restorecond: switch terminate to sig_atomic_t for async-signal-safety
Stephen Smalley
maintainerPATCH 1/4 restorecond: switch terminate to sig_atomic_t for async-signal-safety
The terminate flag is written from a signal handler so switch it to volatile sig_atomic_t for async-signal-safety.
--- restorecond/restorecond.c | 2 +- restorecond/restorecond.h | 4 +++- 2 files changed, 4 insertions(+), 2 deletions(-)
restorecond/restorecond.c +1 -1
@@ -73,7 +73,7 @@ struct restore_opts r_opts;#include <selinux/selinux.h> int debug_mode =0 ; -int terminate =0 ; +volatile sig_atomic_t terminate =0 ;int master_wd =-1 ;int run_as_user =0 ;int foreground_mode =0 ;
restorecond/restorecond.h +3 -1
@@ -24,9 +24,11 @@#ifndef RESTORED_CONFIG_H #define RESTORED_CONFIG_H +#include <signal.h> +extern int debug_mode;extern const char *homedir; -extern int terminate; +extern volatile sig_atomic_t terminate;extern int master_wd;extern int run_as_user;
Signature · 1 line
2.55.0
Stephen Smalley
maintainerPATCH 2/4 restorecond: copy homedir to avoid overwrite by later getpw*() calls
homedir was set to pwd->pw_dir returned by getpwuid() and the referenced string could be overwritten by subsequent getpw*() calls, e.g. from utmpwatcher.c:watch_file(). Create a copy to be safe. NB Intentionally not bothering with free'ing the copy on all the potential exit paths; it's small and will be taken care of at exit regardless.
--- restorecond/restorecond.c | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-)
restorecond/restorecond.c +4 -1
@@ -206,7 +206,10 @@ int main(int argc, char **argv)if (!pwd)exitApp ("getpwuid" ); - homedir = pwd->pw_dir; + homedir =strdup (pwd->pw_dir); +if (!homedir) +exitApp ("strdup" ); +if (uid !=0 ) {if (run_as_user)return server (master_fd, user_watch_file);
Signature · 1 line
2.55.0
Stephen Smalley
maintainerPATCH 3/4 restorecond: fix type of utmpwatcher_handle()
In reply to Stephen Smalleyutmpwatcher_handle() returns -1 in some cases and the caller has a switch statement on it that compares with -1. Switch the return type to just int rather than unsigned int to more accurately reflect the interface.
--- restorecond/utmpwatcher.c | 2 +- restorecond/utmpwatcher.h | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-)
restorecond/utmpwatcher.c +1 -1
@@ -45,7 +45,7 @@static struct stringsList *utmp_ptr =NULL ;static int utmp_wd =-1 ; -unsigned int utmpwatcher_handle (int inotify_fd,int wd) +int utmpwatcher_handle (int inotify_fd,int wd) {int changed =0 ;struct utmp u;
restorecond/utmpwatcher.h +1 -1
@@ -23,7 +23,7 @@#ifndef UTMPWATCHER_H #define UTMPWATCHER_H -unsigned int utmpwatcher_handle (int inotify_fd,int wd); +int utmpwatcher_handle (int inotify_fd,int wd);void utmpwatcher_add (int inotify_fd,const char *path);void utmpwatcher_free (void );
Signature · 1 line
2.55.0
Stephen Smalley
maintainerPATCH 4/4 restorecond: fix isspace() call to cast to unsigned
In reply to Stephen Smalleyisspace() on a plain char argument is defined for negative values; cast to unsigned char in the caller.
--- restorecond/watch.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
restorecond/watch.c +1 -1
@@ -424,7 +424,7 @@ static void process_config(int fd, FILE *cfg)while (getline (&line_buf, &len, cfg) >0 ) {char *buffer = line_buf; -while (isspace (*buffer)) +while (isspace ((unsigned char )*buffer)) buffer++;if (buffer[0 ] =='#' )continue ;
Signature · 1 line
2.55.0
Stephen Smalley
maintainerQuoted 5 lines · Stephen Smalley
The terminate flag is written from a signal handler so switch it to volatile
sig_atomic_tfor async-signal-safety.Signed-off-by Stephen Smalley <[email protected]>
This series has been merged.
Quoted 38 lines
--- restorecond/restorecond.c | 2 +- restorecond/restorecond.h | 4 +++- 2 files changed, 4 insertions(+), 2 deletions(-)restorecond/restorecond.c +1
-1@@ -73,7 +73,7 @@ struct restore_opts r_opts;#include <selinux/selinux.h> int debug_mode =0 ; -int terminate =0 ; +volatile sig_atomic_t terminate =0 ;int master_wd =-1 ;int run_as_user =0 ;int foreground_mode =0 ;restorecond/restorecond.h +3
-2@@ -24,9 +24,11 @@#ifndef RESTORED_CONFIG_H #define RESTORED_CONFIG_H +#include <signal.h> +extern int debug_mode;extern const char *homedir; -extern int terminate; +extern volatile sig_atomic_t terminate;extern int master_wd;extern int run_as_user; --2.55.0