]> git.ipfire.org Git - thirdparty/systemd.git/commitdiff
udev: always open with O_NOCTTY
authorYu Watanabe <watanabe.yu+github@gmail.com>
Fri, 9 Sep 2022 16:56:19 +0000 (01:56 +0900)
committerYu Watanabe <watanabe.yu+github@gmail.com>
Fri, 9 Sep 2022 22:16:43 +0000 (07:16 +0900)
All files or device nodes opened here should not be console tty.
Let's open it the flags for safety.

src/udev/ata_id/ata_id.c
src/udev/cdrom_id/cdrom_id.c
src/udev/fido_id/fido_id.c
src/udev/mtd_probe/mtd_probe.c
src/udev/scsi_id/scsi_serial.c
src/udev/udev-builtin-blkid.c
src/udev/udev-builtin-btrfs.c
src/udev/udev-builtin-input_id.c
src/udev/udev-builtin-usb_id.c
src/udev/udevadm-lock.c
src/udev/udevd.c

index 1fc27f4b642794ee78e911ade716ea9692520a07..f451c0d0e15a8b49d5833de9ac7a8ccb1873bac5 100644 (file)
@@ -439,7 +439,7 @@ int main(int argc, char *argv[]) {
                 return 1;
         }
 
-        fd = open(node, O_RDONLY|O_NONBLOCK|O_CLOEXEC);
+        fd = open(node, O_RDONLY|O_NONBLOCK|O_CLOEXEC|O_NOCTTY);
         if (fd < 0) {
                 log_error("unable to open '%s'", node);
                 return 1;
index 2d758c4082f105b4ad9ade30e8d83a9d5ebad844..5945dcbbaec304405b7bd4e6e234e7fac7636e72 100644 (file)
@@ -743,7 +743,7 @@ static int open_drive(Context *c) {
         assert(c->fd < 0);
 
         for (int cnt = 0;; cnt++) {
-                fd = open(arg_node, O_RDONLY|O_NONBLOCK|O_CLOEXEC);
+                fd = open(arg_node, O_RDONLY|O_NONBLOCK|O_CLOEXEC|O_NOCTTY);
                 if (fd >= 0)
                         break;
                 if (++cnt >= 20 || errno != EBUSY)
index a9f5f8f8a64a0a6c934216a13deac260506b7aac..58a282781809ca44442d2d894cbad6cd3c62ee8b 100644 (file)
@@ -67,7 +67,7 @@ static int run(int argc, char **argv) {
         if (!desc_path)
                 return log_oom();
 
-        fd = open(desc_path, O_RDONLY | O_NOFOLLOW | O_CLOEXEC);
+        fd = open(desc_path, O_RDONLY | O_NOFOLLOW | O_CLOEXEC | O_NOCTTY);
         if (fd < 0)
                 return log_device_error_errno(hid_device, errno,
                                               "Failed to open report descriptor at '%s': %m", desc_path);
index df1f1c173a31f67d0c5669b9ce4a446b12bf0394..d5fb64f1948a31f16718c61b1227b3a3fbb474b6 100644 (file)
@@ -41,7 +41,7 @@ int main(int argc, char** argv) {
                 return EXIT_FAILURE;
         }
 
-        mtd_fd = open(argv[1], O_RDONLY|O_CLOEXEC);
+        mtd_fd = open(argv[1], O_RDONLY|O_CLOEXEC|O_NOCTTY);
         if (mtd_fd < 0) {
                 log_error_errno(errno, "Failed to open: %m");
                 return EXIT_FAILURE;
index 60e2b40c27b7400f3fe7ab5eaff158c74b6020ca..f1ce8601bd8257dabe32ba8600268425ddb663e4 100644 (file)
@@ -751,7 +751,7 @@ int scsi_std_inquiry(struct scsi_id_device *dev_scsi, const char *devname) {
         struct stat statbuf;
         int err = 0;
 
-        fd = open(devname, O_RDONLY | O_NONBLOCK | O_CLOEXEC);
+        fd = open(devname, O_RDONLY | O_NONBLOCK | O_CLOEXEC | O_NOCTTY);
         if (fd < 0) {
                 log_debug_errno(errno, "scsi_id: cannot open %s: %m", devname);
                 return 1;
@@ -795,7 +795,7 @@ int scsi_get_serial(struct scsi_id_device *dev_scsi, const char *devname,
         for (cnt = 20; cnt > 0; cnt--) {
                 struct timespec duration;
 
-                fd = open(devname, O_RDONLY | O_NONBLOCK | O_CLOEXEC);
+                fd = open(devname, O_RDONLY | O_NONBLOCK | O_CLOEXEC | O_NOCTTY);
                 if (fd >= 0 || errno != EBUSY)
                         break;
                 duration.tv_sec = 0;
index f992c8f4c5d216c035a24d979cccdf5d56756678..6de470c71dda1ebd00cba1494affbf19fa7748b0 100644 (file)
@@ -310,7 +310,7 @@ static int builtin_blkid(sd_device *dev, sd_netlink **rtnl, int argc, char *argv
         if (r < 0)
                 return log_device_debug_errno(dev, r, "Failed to get device name: %m");
 
-        fd = sd_device_open(dev, O_RDONLY|O_CLOEXEC|O_NONBLOCK);
+        fd = sd_device_open(dev, O_RDONLY|O_CLOEXEC|O_NONBLOCK|O_NOCTTY);
         if (fd < 0) {
                 bool ignore = ERRNO_IS_DEVICE_ABSENT(fd);
                 log_device_debug_errno(dev, fd, "Failed to open block device %s%s: %m",
index f9d4f1dd4ef4b56481780fa9580beb2a784e0513..8cd627807f9667e5d7aaea07652a0a9a6b72d0b0 100644 (file)
@@ -21,7 +21,7 @@ static int builtin_btrfs(sd_device *dev, sd_netlink **rtnl, int argc, char *argv
         if (argc != 3 || !streq(argv[1], "ready"))
                 return log_device_error_errno(dev, SYNTHETIC_ERRNO(EINVAL), "Invalid arguments");
 
-        fd = open("/dev/btrfs-control", O_RDWR|O_CLOEXEC);
+        fd = open("/dev/btrfs-control", O_RDWR|O_CLOEXEC|O_NOCTTY);
         if (fd < 0) {
                 if (ERRNO_IS_DEVICE_ABSENT(errno)) {
                         /* Driver not installed? Then we aren't ready. This is useful in initrds that lack
index 6da8ad85bb0308b0b0e3a2be26baac7c9567eaa1..07421202483e4aeb50b84aeafb8ee38f22c6f8ae 100644 (file)
@@ -50,7 +50,7 @@ static void extract_info(sd_device *dev, bool test) {
         struct input_absinfo xabsinfo = {}, yabsinfo = {};
         _cleanup_close_ int fd = -1;
 
-        fd = sd_device_open(dev, O_RDONLY|O_CLOEXEC|O_NONBLOCK);
+        fd = sd_device_open(dev, O_RDONLY|O_CLOEXEC|O_NONBLOCK|O_NOCTTY);
         if (fd < 0)
                 return;
 
index eb326612555abb8035821bfbd2389f8a2c4b078e..d94718f468022e706262dddf26d956d9401c0b37 100644 (file)
@@ -158,7 +158,7 @@ static int dev_if_packed_info(sd_device *dev, char *ifs_str, size_t len) {
                 return r;
 
         filename = strjoina(syspath, "/descriptors");
-        fd = open(filename, O_RDONLY|O_CLOEXEC);
+        fd = open(filename, O_RDONLY|O_CLOEXEC|O_NOCTTY);
         if (fd < 0)
                 return log_device_debug_errno(dev, errno, "Failed to open \"%s\": %m", filename);
 
index a3be2336afeea6a270e64e55cf6196c5cafde822..35e9999c015e9577b2955c3e3348e709f3e432ca 100644 (file)
@@ -180,7 +180,7 @@ static int lock_device(
         struct stat st;
         int r;
 
-        fd = open(path, O_RDONLY|O_CLOEXEC|O_NONBLOCK);
+        fd = open(path, O_RDONLY|O_CLOEXEC|O_NONBLOCK|O_NOCTTY);
         if (fd < 0)
                 return log_error_errno(errno, "Failed to open '%s': %m", path);
 
index c2a4a8a7bd6415fa60dfd345465c1008fbcde9c9..5316adf6ec4e83436dd9ce3c6ac631afeb1208cb 100644 (file)
@@ -544,7 +544,7 @@ static int worker_lock_whole_disk(sd_device *dev, int *ret_fd) {
         if (r == 0)
                 goto nolock;
 
-        fd = sd_device_open(dev_whole_disk, O_RDONLY|O_CLOEXEC|O_NONBLOCK);
+        fd = sd_device_open(dev_whole_disk, O_RDONLY|O_CLOEXEC|O_NONBLOCK|O_NOCTTY);
         if (fd < 0) {
                 bool ignore = ERRNO_IS_DEVICE_ABSENT(fd);
 
@@ -599,7 +599,7 @@ static int worker_mark_block_device_read_only(sd_device *dev) {
         if (STARTSWITH_SET(val, "dm-", "md", "drbd", "loop", "nbd", "zram"))
                 return 0;
 
-        fd = sd_device_open(dev, O_RDONLY|O_CLOEXEC|O_NONBLOCK);
+        fd = sd_device_open(dev, O_RDONLY|O_CLOEXEC|O_NONBLOCK|O_NOCTTY);
         if (fd < 0)
                 return log_device_debug_errno(dev, fd, "Failed to open '%s', ignoring: %m", val);