diff options
-rw-r--r-- | udev_add.c | 10 | ||||
-rw-r--r-- | udev_selinux.c | 32 | ||||
-rw-r--r-- | udev_selinux.h | 6 |
3 files changed, 28 insertions, 20 deletions
diff --git a/udev_add.c b/udev_add.c index 58f4ee1150..42b8d2104c 100644 --- a/udev_add.c +++ b/udev_add.c @@ -83,6 +83,7 @@ create: selinux_setfscreatecon(file, udev->kernel_name, mode); retval = mknod(file, mode, devt); + selinux_resetfscreatecon(); if (retval != 0) { dbg("mknod(%s, %#o, %u, %u) failed with error '%s'", file, mode, major(devt), minor(devt), strerror(errno)); @@ -189,6 +190,7 @@ static int create_node(struct udevice *udev, struct sysfs_class_device *class_de /* create symlink(s) if requested */ list_for_each_entry(name_loop, &udev->symlink_list, node) { + int retval; char linktarget[PATH_SIZE]; snprintf(filename, sizeof(filename), "%s/%s", udev_root, name_loop->name); @@ -218,9 +220,11 @@ static int create_node(struct udevice *udev, struct sysfs_class_device *class_de dbg("symlink(%s, %s)", linktarget, filename); if (!udev->test_run) { - selinux_setfscreatecon(filename, udev->kernel_name, S_IFLNK); unlink(filename); - if (symlink(linktarget, filename) != 0) + selinux_setfscreatecon(filename, udev->kernel_name, S_IFLNK); + retval = symlink(linktarget, filename); + selinux_resetfscreatecon(); + if (retval != 0) dbg("symlink(%s, %s) failed with error '%s'", linktarget, filename, strerror(errno)); } @@ -317,7 +321,7 @@ int udev_add_device(struct udevice *udev, struct sysfs_class_device *class_dev) } exit: - selinux_restore(); + selinux_exit(); return retval; } diff --git a/udev_selinux.c b/udev_selinux.c index 72381f0d0d..cc6f4d7d3f 100644 --- a/udev_selinux.c +++ b/udev_selinux.c @@ -105,7 +105,7 @@ void selinux_setfilecon(const char *file, const char *devname, unsigned int mode } if (setfilecon(file, scontext) < 0) - dbg("setfiles %s failed with error '%s'", file, strerror(errno)); + dbg("setfilecon %s failed with error '%s'", file, strerror(errno)); freecon(scontext); } @@ -131,12 +131,20 @@ void selinux_setfscreatecon(const char *file, const char *devname, unsigned int } if (setfscreatecon(scontext) < 0) - dbg("setfiles %s failed with error '%s'", file, strerror(errno)); + dbg("setfscreatecon %s failed with error '%s'", file, strerror(errno)); freecon(scontext); } } +void selinux_resetfscreatecon(void) +{ + if (is_selinux_running()) { + if (setfscreatecon(prev_scontext) < 0) + dbg("setfscreatecon %s failed with error '%s'", file, strerror(errno)); + } +} + void selinux_init(void) { /* @@ -144,23 +152,17 @@ void selinux_init(void) * restoration creation purposes. */ if (is_selinux_running()) { - if (getfscreatecon(&prev_scontext) < 0) + if (getfscreatecon(&prev_scontext) < 0) { dbg("getfscreatecon failed\n"); - - prev_scontext = NULL; + prev_scontext = NULL; + } } } -void selinux_restore(void) +void selinux_exit(void) { - if (is_selinux_running()) { - /* reset the file create context to its former glory */ - if (setfscreatecon(prev_scontext) < 0) - dbg("setfscreatecon failed\n"); - - if (prev_scontext) { - freecon(prev_scontext); - prev_scontext = NULL; - } + if (is_selinux_running() && prev_scontext) { + freecon(prev_scontext); + prev_scontext = NULL; } } diff --git a/udev_selinux.h b/udev_selinux.h index 132a9a6550..d9dfeffad0 100644 --- a/udev_selinux.h +++ b/udev_selinux.h @@ -24,15 +24,17 @@ extern void selinux_setfilecon(const char *file, const char *devname, unsigned int mode); extern void selinux_setfscreatecon(const char *file, const char *devname, unsigned int mode); +extern void selinux_resetfscreatecon(void); extern void selinux_init(void); -extern void selinux_restore(void); +extern void selinux_exit(void); #else static inline void selinux_setfilecon(const char *file, const char *devname, unsigned int mode) {} static inline void selinux_setfscreatecon(const char *file, const char *devname, unsigned int mode) {} +static inline void selinux_resetfscreatecon(void) {} static inline void selinux_init(void) {} -static inline void selinux_restore(void) {} +static inline void selinux_exit(void) {} #endif /* USE_SELINUX */ #endif /* _UDEV_USE_SELINUX */ |