seunshare: guard fallible function calls by checking retval
PATCH 1/1 seunshare: guard fallible function calls by checking retval
seunshare currently segfaults is passed --kill and an invalid context via -Z.
Signed-off-by Rahul Sandhu <[email protected]>
--- sandbox/seunshare.c | 26 +++++++++++++++++++------- 1 file changed, 19 insertions(+), 7 deletions(-)
sandbox/seunshare.c +19 -7
@@ -679,9 +679,19 @@ killall (const char *execcon)return -1 ; } pids =0 ; -context_t con; - con =context_new (execcon); -const char *mcs =context_range_get (con); +context_t con =context_new (execcon); +if (!con) { +free (pid_table); + (void )closedir (dir); +return -1 ; + } +const char *const mcs =context_range_get (con); +if (!mcs) { +context_free (con); +free (pid_table); + (void )closedir (dir); +return -1 ; + }printf ("mcs=%s\n" , mcs);while ((de =readdir (dir)) !=NULL ) {if (!(pid = (pid_t )atoi (de->d_name)) || pid == self)
@@ -708,11 +718,13 @@ killall (const char *execcon)if (getpidcon (id, &scon) ==0 ) {context_t pidcon =context_new (scon); -/* Attempt to kill remaining processes */ -if (strcmp (context_range_get (pidcon), mcs) ==0 ) -kill (id,SIGKILL ); +if (pidcon) { +/* Attempt to kill remaining processes */ +if (strcmp (context_range_get (pidcon), mcs) ==0 ) +kill (id,SIGKILL ); -context_free (pidcon); +context_free (pidcon); + }freecon (scon); } running++;
Signature · 1 line
2.53.0
Quoted 5 lines · Rahul Sandhu
seunshare currently segfaults is passed --kill and an invalid context via -Z.
Signed-off-by Rahul Sandhu <[email protected]>
Acked-by Stephen Smalley <[email protected]>
Quoted 53 lines
--- sandbox/seunshare.c | 26 +++++++++++++++++++------- 1 file changed, 19 insertions(+), 7 deletions(-)sandbox/seunshare.c +19
-8@@ -679,9 +679,19 @@ killall (const char *execcon)return -1 ; } pids =0 ; -context_t con; - con =context_new (execcon); -const char *mcs =context_range_get (con); +context_t con =context_new (execcon); +if (!con) { +free (pid_table); + (void )closedir (dir); +return -1 ; + } +const char *const mcs =context_range_get (con); +if (!mcs) { +context_free (con); +free (pid_table); + (void )closedir (dir); +return -1 ; + }printf ("mcs=%s\n" , mcs);while ((de =readdir (dir)) !=NULL ) {if (!(pid = (pid_t )atoi (de->d_name)) || pid == self)@@ -708,11 +718,13 @@ killall (const char *execcon)if (getpidcon (id, &scon) ==0 ) {context_t pidcon =context_new (scon); -/* Attempt to kill remaining processes */ -if (strcmp (context_range_get (pidcon), mcs) ==0 ) -kill (id,SIGKILL ); +if (pidcon) { +/* Attempt to kill remaining processes */ +if (strcmp (context_range_get (pidcon), mcs) ==0 ) +kill (id,SIGKILL ); -context_free (pidcon); +context_free (pidcon); + }freecon (scon); } running++; --2.53.0
Quoted 10 lines · Stephen Smalley
Quoted 5 lines · Rahul Sandhu
seunshare currently segfaults is passed --kill and an invalid context via -Z.
Signed-off-by Rahul Sandhu <[email protected]>Acked-by Stephen Smalley <[email protected]>
Merged.
Thanks,
Jim
Quoted 54 lines
Quoted 53 lines
--- sandbox/seunshare.c | 26 +++++++++++++++++++------- 1 file changed, 19 insertions(+), 7 deletions(-)sandbox/seunshare.c +19
-8@@ -679,9 +679,19 @@ killall (const char *execcon)return -1 ; } pids =0 ; -context_t con; - con =context_new (execcon); -const char *mcs =context_range_get (con); +context_t con =context_new (execcon); +if (!con) { +free (pid_table); + (void )closedir (dir); +return -1 ; + } +const char *const mcs =context_range_get (con); +if (!mcs) { +context_free (con); +free (pid_table); + (void )closedir (dir); +return -1 ; + }printf ("mcs=%s\n" , mcs);while ((de =readdir (dir)) !=NULL ) {if (!(pid = (pid_t )atoi (de->d_name)) || pid == self)@@ -708,11 +718,13 @@ killall (const char *execcon)if (getpidcon (id, &scon) ==0 ) {context_t pidcon =context_new (scon); -/* Attempt to kill remaining processes */ -if (strcmp (context_range_get (pidcon), mcs) ==0 ) -kill (id,SIGKILL ); +if (pidcon) { +/* Attempt to kill remaining processes */ +if (strcmp (context_range_get (pidcon), mcs) ==0 ) +kill (id,SIGKILL ); -context_free (pidcon); +context_free (pidcon); + }freecon (scon); } running++; --2.53.0