Patch setfiles to only warn if add_remove fails to lstat on user initiated excludes.
Currently in F12 if you have file systems that root can not read
# restorecon -R -v /var/lib/libvirt/ Can't stat directory "/home/dwalsh/.gvfs", Permission denied. Can't stat directory "/home/dwalsh/redhat", Permission denied.
After patch
# ./restorecon -R -v /var/lib/libvirt/
setfiles/setfiles.c renamed from setfiles/setfiles.c~ +5 -5
@@ -234,7 +234,7 @@ void filespec_destroy(void) fl_head =NULL ; } -static int add_exclude (const char *directory) +static int add_exclude (const char *directory,int warn) {struct stat sb;size_t len =0 ;
@@ -244,8 +244,8 @@ static int add_exclude(const char *direcreturn 1 ; }if (lstat (directory, &sb)) { -fprintf (stderr,"Can't stat directory \"%s\", %s.\n" , - directory,strerror (errno)); +if (warn)fprintf (stderr,"Can't stat directory \"%s\", %s.\n" , + directory,strerror (errno));return 0 ; }if ((sb.st_mode &S_IFDIR ) ==0 ) {
@@ -727,7 +727,7 @@ static void exclude_non_seclabel_mounts(/* exclude mount points without the seclabel option */ if (!found) -add_exclude (mount_info[1 ]); +add_exclude (mount_info[1 ],0 ); }free (buf);
@@ -840,7 +840,7 @@ int main(int argc, char **argv) }case 'e' :remove_exclude (optarg); -if (add_exclude (optarg)) +if (add_exclude (optarg,1 ))exit (1 );break ;case 'f' :
Quoted 9 lines · Daniel J Walsh
Currently in F12 if you have file systems that root can not read
# restorecon -R -v /var/lib/libvirt/ Can't stat directory "/home/dwalsh/.gvfs", Permission denied. Can't stat directory "/home/dwalsh/redhat", Permission denied.After patch
# ./restorecon -R -v /var/lib/libvirt/
But if you were to run
./restorecon -R /home/dwalsh
that would try to descend into .gvfs and redhat, right?
I think you want instead to ignore the lstat error if the error was permission denied and add the entry to the exclude list so that restorecon will not try to descend into it. It is ok to exclude a directory to which you lack permission. Try this:
policycoreutils/setfiles/setfiles.c +8 -7
@@ -243,17 +243,18 @@ static int add_exclude(const char *directory) directory);return 1 ; } -if (lstat (directory, &sb)) { +if (lstat (directory, &sb) ==0 ) { +if ((sb.st_mode &S_IFDIR ) ==0 ) { +fprintf (stderr, +"\"%s\" is not a Directory: mode %o, ignoring\n" , + directory, sb.st_mode); +return 0 ; + } + }else if (errno !=EACCES ) {fprintf (stderr,"Can't stat directory \"%s\", %s.\n" , directory,strerror (errno));return 0 ; } -if ((sb.st_mode &S_IFDIR ) ==0 ) { -fprintf (stderr, -"\"%s\" is not a Directory: mode %o, ignoring\n" , - directory, sb.st_mode); -return 0 ; - }if (excludeCtr ==MAX_EXCLUDES ) { fprintf(stderr, "Maximum excludes %d exceeded.\n",
Signature · 8 lines
Stephen Smalley National Security Agency -- This message was distributed to subscribers of the selinux mailing list. If you no longer wish to subscribe, send mail to [email protected] with the words "unsubscribe selinux" without quotes as the message.
Quoted 11 lines · Stephen Smalley
Quoted 9 lines · Daniel J Walsh
Currently in F12 if you have file systems that root can not read
# restorecon -R -v /var/lib/libvirt/ Can't stat directory "/home/dwalsh/.gvfs", Permission denied. Can't stat directory "/home/dwalsh/redhat", Permission denied.After patch
# ./restorecon -R -v /var/lib/libvirt/
Quoted 8 lines
But if you were to run
./restorecon -R/home/dwalsh
that would try to descend into .gvfs and redhat, right?I think you want instead to ignore the lstat error if the error was permission denied and add the entry to the exclude list so that restorecon will not try to descend into it. It is ok to exclude a directory to which you lack permission. Try this:
Also, why limit -e to only directories? Why not let the user exclude individual files if they choose to do so? In which case we could drop the mode test altogether, and possibly drop the lstat() call altogether? Or if you truly want to warn the user about non-existent paths, then take the lstat() and warning to the 'e' option processing in main() instead of doing it inside of add_exclude().
Signature · 8 lines
Stephen Smalley National Security Agency -- This message was distributed to subscribers of the selinux mailing list. If you no longer wish to subscribe, send mail to [email protected] with the words "unsubscribe selinux" without quotes as the message.
Quoted 21 lines · Stephen Smalley
Quoted 11 lines · Stephen Smalley
Quoted 9 lines · Daniel J Walsh
Currently in F12 if you have file systems that root can not read
# restorecon -R -v /var/lib/libvirt/ Can't stat directory "/home/dwalsh/.gvfs", Permission denied. Can't stat directory "/home/dwalsh/redhat", Permission denied.After patch
# ./restorecon -R -v /var/lib/libvirt/Quoted 8 lines
But if you were to run
./restorecon -R/home/dwalsh
that would try to descend into .gvfs and redhat, right?I think you want instead to ignore the lstat error if the error was permission denied and add the entry to the exclude list so that restorecon will not try to descend into it. It is ok to exclude a directory to which you lack permission. Try this:
Quoted 7 lines
Also, why limit -e to only directories? Why not let the user exclude individual files if they choose to do so? In which case we could drop the mode test altogether, and possibly drop the
lstat()call altogether? Or if you truly want to warn the user about non-existent paths, then take thelstat()and warning to the 'e' option processing inmain()instead of doing it inside ofadd_exclude().
I agree lets remove the directory check and warn on non existing files.
--
This message was distributed to subscribers of the selinux mailing list. If you no longer wish to subscribe, send mail to [email protected] with the words "unsubscribe selinux" without quotes as the message.
Quoted 22 lines · Daniel J Walsh
Quoted 21 lines · Stephen Smalley
Quoted 19 lines · Stephen Smalley
Quoted 9 lines · Daniel J Walsh
Currently in F12 if you have file systems that root can not read
# restorecon -R -v /var/lib/libvirt/ Can't stat directory "/home/dwalsh/.gvfs", Permission denied. Can't stat directory "/home/dwalsh/redhat", Permission denied.After patch
# ./restorecon -R -v /var/lib/libvirt/But if you were to run
./restorecon -R/home/dwalsh
that would try to descend into .gvfs and redhat, right?I think you want instead to ignore the lstat error if the error was permission denied and add the entry to the exclude list so that restorecon will not try to descend into it. It is ok to exclude a directory to which you lack permission. Try this:
Quoted 8 lines
Quoted 7 lines
Also, why limit -e to only directories? Why not let the user exclude individual files if they choose to do so? In which case we could drop the mode test altogether, and possibly drop the
lstat()call altogether? Or if you truly want to warn the user about non-existent paths, then take thelstat()and warning to the 'e' option processing inmain()instead of doing it inside ofadd_exclude().I agree lets remove the directory check and warn on non existing files.
Does this handle it correctly for you?
Remove the directory check for the -e option and only apply the existence test to user-specified entries. Also ignore permission denied errors as it is ok to exclude a directory or file to which the caller lacks permission.
policycoreutils/setfiles/setfiles.c +6 -13
@@ -236,25 +236,13 @@ void filespec_destroy(void)static int add_exclude (const char *directory) { -struct stat sb;size_t len =0 ; +if (directory ==NULL || directory[0 ] !='/' ) {fprintf (stderr,"Full path required for exclude: %s.\n" , directory);return 1 ; } -if (lstat (directory, &sb)) { -fprintf (stderr,"Can't stat directory \"%s\", %s.\n" , - directory,strerror (errno)); -return 0 ; - } -if ((sb.st_mode &S_IFDIR ) ==0 ) { -fprintf (stderr, -"\"%s\" is not a Directory: mode %o, ignoring\n" , - directory, sb.st_mode); -return 0 ; - } -if (excludeCtr ==MAX_EXCLUDES ) {fprintf (stderr,"Maximum excludes %d exceeded.\n" ,MAX_EXCLUDES );
@@ -840,6 +828,11 @@ int main(int argc, char **argv) }case 'e' :remove_exclude (optarg); +if (lstat (optarg, &sb) <0 && errno !=EACCES ) { +fprintf (stderr,"Can't stat exclude path \"%s\", %s - ignoring.\n" , + optarg,strerror (errno)); +break ; + }if (add_exclude (optarg))exit (1 );break ;
Signature · 8 lines
Stephen Smalley National Security Agency -- This message was distributed to subscribers of the selinux mailing list. If you no longer wish to subscribe, send mail to [email protected] with the words "unsubscribe selinux" without quotes as the message.
Quoted 73 lines · Stephen Smalley
Quoted 22 lines · Daniel J Walsh
Quoted 21 lines · Stephen Smalley
Quoted 19 lines · Stephen Smalley
Quoted 9 lines · Daniel J Walsh
Currently in F12 if you have file systems that root can not read
# restorecon -R -v /var/lib/libvirt/ Can't stat directory "/home/dwalsh/.gvfs", Permission denied. Can't stat directory "/home/dwalsh/redhat", Permission denied.After patch
# ./restorecon -R -v /var/lib/libvirt/But if you were to run
./restorecon -R/home/dwalsh
that would try to descend into .gvfs and redhat, right?I think you want instead to ignore the lstat error if the error was permission denied and add the entry to the exclude list so that restorecon will not try to descend into it. It is ok to exclude a directory to which you lack permission. Try this:
Quoted 8 lines
Quoted 7 lines
Also, why limit -e to only directories? Why not let the user exclude individual files if they choose to do so? In which case we could drop the mode test altogether, and possibly drop the
lstat()call altogether? Or if you truly want to warn the user about non-existent paths, then take thelstat()and warning to the 'e' option processing inmain()instead of doing it inside ofadd_exclude().I agree lets remove the directory check and warn on non existing files.
Does this handle it correctly for you?
Remove the directory check for the -e option and only apply the existence test to user-specified entries. Also ignore permission denied errors as it is ok to exclude a directory or file to which the caller lacks permission.
policycoreutils/setfiles/setfiles.c +1
-13@@ -236,25 +236,13 @@ void filespec_destroy(void)static int add_exclude (const char *directory) { -struct stat sb;size_t len =0 ; +if (directory ==NULL || directory[0 ] !='/' ) {fprintf (stderr,"Full path required for exclude: %s.\n" , directory);return 1 ; } -if (lstat (directory, &sb)) { -fprintf (stderr,"Can't stat directory \"%s\", %s.\n" , - directory,strerror (errno)); -return 0 ; - } -if ((sb.st_mode &S_IFDIR ) ==0 ) { -fprintf (stderr, -"\"%s\" is not a Directory: mode %o, ignoring\n" , - directory, sb.st_mode); -return 0 ; - } -if (excludeCtr ==MAX_EXCLUDES ) {fprintf (stderr,"Maximum excludes %d exceeded.\n" ,MAX_EXCLUDES );@@ -840,6 +828,11 @@ int main(int argc, char **argv) }
policycoreutils/setfiles/setfiles.c int main(int argc, char **argv) · line 838
Quoted 10 lines
policycoreutils/setfiles/setfiles.c +5
-0case 'e' :remove_exclude (optarg); +if (lstat (optarg, &sb) <0 && errno !=EACCES ) { +fprintf (stderr,"Can't stat exclude path \"%s\", %s - ignoring.\n" , + optarg,strerror (errno)); +break ; + }if (add_exclude (optarg))exit (1 );break ;
I like it ack.
--
This message was distributed to subscribers of the selinux mailing list. If you no longer wish to subscribe, send mail to [email protected] with the words "unsubscribe selinux" without quotes as the message.