setfiles converted to fts
PATCH 1/1 setfiles converted to fts
This patch converted setfiles/restorecon to using fts instead of nftw. It also removed forking, pipes and pre_stat because Dan Walsh and I could not figure out what it was for.
-Thomas Liu
setfiles/Makefile renamed from setfiles/Makefile.old +1 -2
@@ -3,11 +3,10 @@ PREFIX ?= ${DESTDIR}/usr SBINDIR ?= $(DESTDIR)/sbin MANDIR = $(PREFIX)/share/man LIBDIR ?= $(PREFIX)/lib - AUDITH = $(shell ls /usr/include/libaudit.h 2>/dev/null) CFLAGS = -Werror -Wall -W -override CFLAGS += -D_FILE_OFFSET_BITS=64 -I$(PREFIX)/include +override CFLAGS += -I$(PREFIX)/include LDLIBS = -lselinux -lsepol -L$(LIBDIR) ifeq (${AUDITH}, /usr/include/libaudit.h)
setfiles/setfiles.c renamed from setfiles/setfiles.c.old +47 -89
230 lines not on this page · raw message
Quoted 3 lines · Thomas Liu
This patch converted setfiles/restorecon to using fts instead of nftw. It also removed forking, pipes and
pre_statbecause Dan Walsh and I could not figure out what it was for.
See:
http://marc.info/?l=selinux&m=113627973615236&w=2
for the rationale for that logic.
Did you run any measurements to assess the impact of your changes on setfiles?
Did you compare with the implementation of setfsmac.c in FreeBSD, which likewise started life as setfiles and was then rewritten to use fts()?
What improvements do we get from the changes?
Should we be using fts_path or fts_accpath when performing operations on the files, like lsetfilecon()? I suspect the latter would be more efficient and less prone to simultaneous changes to the file tree if fts switches the cwd as it walks the tree.
IIRC, we called lstat() within apply_spec() even though a struct stat was supplied as an argument because in the case of symlinks, we were getting the stat of the referenced file rather than of the symlink file. Is this true of fts?
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 8 lines · Stephen Smalley
Quoted 3 lines · Thomas Liu
This patch converted setfiles/restorecon to using fts instead of nftw. It also removed forking, pipes and
pre_statbecause Dan Walsh and I could not figure out what it was for.See:
http://marc.info/?l=selinux&m=113627973615236&w=2
for the rationale for that logic.
But this does not seem to be much benefit since fts files come with the stat already filled out. Thomas removed all stat/lstat calls since you are not allowed to use the -D_FILE_OFFSET_BITS=64 with fts.
Quoted 3 lines
Did you run any measurements to assess the impact of your changes on setfiles?
I think the biggest impact on speed comes from not trying to read past a failed directory.
One thing that would be helpful to add would be to check if a directory is on a files system that supports labeling, if not then the directory should be skipped. I think with this patch the tool would walk a nfs_t file system unless it is called as setfiles.
Quoted 10 lines
Did you compare with the implementation of
setfsmac.cin FreeBSD, which likewise started life as setfiles and was then rewritten to usefts()?What improvements do we get from the changes?
Should we be using
fts_pathorfts_accpathwhen performing operations on the files, likelsetfilecon()? I suspect the latter would be more efficient and less prone to simultaneous changes to the file tree if fts switches the cwd as it walks the tree.
Quoted 5 lines
IIRC, we called
lstat()withinapply_spec()even though a struct stat was supplied as an argument because in the case of symlinks, we were getting the stat of the referenced file rather than of the symlink file. Is this true of fts?
--
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 6 lines · Daniel J Walsh
Quoted 5 lines · Stephen Smalley
Quoted 3 lines · Thomas Liu
This patch converted setfiles/restorecon to using fts instead of nftw. It also removed forking, pipes and
pre_statbecause Dan Walsh and I could not figure out what it was for.
Quoted 6 lines
Quoted 3 lines
See:
http://marc.info/?l=selinux&m=113627973615236&w=2
for the rationale for that logic.But this does not seem to be much benefit since fts files come with the stat already filled out. Thomas removed all stat/lstat calls since you are not allowed to use the -D_FILE_OFFSET_BITS=64 with fts.
I'm open to considering the change, but I'd like to see actual measurements before and after the changes.
I'd also like answers to the questions I posed regarding use of fts_path vs. fts_accpath (I think we should be using the latter for calls to getfilecon and setfilecon at least), whether the removal of the extra lstat call changes behavior for symlinks (nftw would pass the stat struct of the referenced file rather than the symlink, and the man page for fts suggests that it may do likewise, which may change how we end up labeling symlinks due to the different modes), and whether you looked at the FreeBSD setfsmac.c implementation to see if we can learn anything useful from it.
Quoted 30 lines
Quoted 2 lines
Did you run any measurements to assess the impact of your changes on setfiles?
I think the biggest impact on speed comes from not trying to read past a failed directory.
One thing that would be helpful to add would be to check if a directory is on a files system that supports labeling, if not then the directory should be skipped. I think with this patch the tool would walk a
nfs_tfile system unless it is called as setfiles.Quoted 10 lines
Did you compare with the implementation of
setfsmac.cin FreeBSD, which likewise started life as setfiles and was then rewritten to usefts()?What improvements do we get from the changes?
Should we be using
fts_pathorfts_accpathwhen performing operations on the files, likelsetfilecon()? I suspect the latter would be more efficient and less prone to simultaneous changes to the file tree if fts switches the cwd as it walks the tree.Quoted 5 lines
IIRC, we called
lstat()withinapply_spec()even though a struct stat was supplied as an argument because in the case of symlinks, we were getting the stat of the referenced file rather than of the symlink file. Is this true of fts?--
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.
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 10 lines · Stephen Smalley
Quoted 9 lines · Daniel J Walsh
Quoted 8 lines · Stephen Smalley
Quoted 3 lines · Thomas Liu
This patch converted setfiles/restorecon to using fts instead of nftw. It also removed forking, pipes and
pre_statbecause Dan Walsh and I could not figure out what it was for.See:
http://marc.info/?l=selinux&m=113627973615236&w=2
for the rationale for that logic.
Quoted 6 lines
Quoted 3 lines
But this does not seem to be much benefit since fts files come with the stat already filled out. Thomas removed all stat/lstat calls since you are not allowed to use the -D_FILE_OFFSET_BITS=64 with fts.
I'm open to considering the change, but I'd like to see actual measurements before and after the changes.
Also, I'd like to see the output of a setfiles -v for an entire system before and after the patch to verify that there is no change in behavior on existing systems, i.e. that no label gets changed as a result of the patch.
Quoted 41 lines
I'd also like answers to the questions I posed regarding use of
fts_pathvs.fts_accpath(I think we should be using the latter for calls to getfilecon and setfilecon at least), whether the removal of the extra lstat call changes behavior for symlinks (nftw would pass the stat struct of the referenced file rather than the symlink, and the man page for fts suggests that it may do likewise, which may change how we end up labeling symlinks due to the different modes), and whether you looked at the FreeBSDsetfsmac.cimplementation to see if we can learn anything useful from it.Quoted 30 lines
Quoted 2 lines
Did you run any measurements to assess the impact of your changes on setfiles?
I think the biggest impact on speed comes from not trying to read past a failed directory.
One thing that would be helpful to add would be to check if a directory is on a files system that supports labeling, if not then the directory should be skipped. I think with this patch the tool would walk a
nfs_tfile system unless it is called as setfiles.Quoted 10 lines
Did you compare with the implementation of
setfsmac.cin FreeBSD, which likewise started life as setfiles and was then rewritten to usefts()?What improvements do we get from the changes?
Should we be using
fts_pathorfts_accpathwhen performing operations on the files, likelsetfilecon()? I suspect the latter would be more efficient and less prone to simultaneous changes to the file tree if fts switches the cwd as it walks the tree.Quoted 5 lines
IIRC, we called
lstat()withinapply_spec()even though a struct stat was supplied as an argument because in the case of symlinks, we were getting the stat of the referenced file rather than of the symlink file. Is this true of fts?--
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.
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 3 lines · Thomas Liu
This patch converted setfiles/restorecon to using fts instead of nftw. It also removed forking, pipes and
pre_statbecause Dan Walsh and I could not figure out what it was for.
Also, please inline your patch as per:
http://lxr.linux.no/linux/Documentation/SubmittingPatches
so that it will be included in the reply for commenting on it.
A couple of comments below.
-static int restore(const char *file)
+static int restore(const char *file, struct stat *sb)
{
char *my_file = strdupa(file);
- struct stat my_sb;
+ struct stat my_sb = *sb;
int ret;
char *context, *newcon;
int user_only_changed = 0;If we truly don't need a private stat struct anymore (i.e. fts will pass us the true stat structure even for symlinks), then just replace all occurrences of my_sb with sb and remove my_sb altogether.
@@ -549,42 +542,38 @@ static int restore(const char *file)
if (ret) {
fprintf(stderr, "%s set context %s->%s failed:'%s'\n",
progname, my_file, newcon, strerror(errno));
- goto out;
+ goto skip;
}+ skip:
+ freecon(newcon);
+ return SKIP;
This looks wrong - it means that you return SKIP in the success path as well. I think you wanted skip: to follow the return 0 of the out: path?
out:
freecon(newcon);
return 0;
err:
freecon(newcon);- return -1;
+ return ERR;
}
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.
Thanks for the feedback! I will look into all of the suggestions and then send another patch with more information.
-Thomas Liu
Quoted 44 lines · Stephen Smalley
Quoted 3 lines · Thomas Liu
This patch converted setfiles/restorecon to using fts instead of nftw. It also removed forking, pipes and
pre_statbecause Dan Walsh and I could not figure out what it was for.Also, please inline your patch as per:
http://lxr.linux.no/linux/Documentation/SubmittingPatches
so that it will be included in the reply for commenting on it.A couple of comments below.
setfiles/setfiles.c renamed from setfiles/setfiles.c.old +2
-2-static int restore (const char *file) +static int restore (const char *file,struct stat *sb) {char *my_file =strdupa (file); -struct stat my_sb; +struct stat my_sb = *sb;int ret;char *context, *newcon;int user_only_changed =0 ;If we truly don't need a private stat struct anymore (i.e. fts will pass us the true stat structure even for symlinks), then just replace all occurrences of
my_sbwith sb and removemy_sbaltogether.setfiles/setfiles.c renamed from setfiles/setfiles.c.old +4
-1@@ -549,42 +542,38 @@ static int restore(const char *file)if (ret) {fprintf (stderr,"%s set context %s->%s failed:'%s'\n" , progname, my_file, newcon,strerror (errno)); - goto out; + goto skip; } + skip: +freecon (newcon); +return SKIP ;This looks wrong - it means that you return SKIP in the success path as well. I think you wanted skip: to follow the return 0 of the out: path?
out: freecon(newcon); return 0; err: freecon(newcon);
setfiles/setfiles.c static int restore(const char *file) · line 556
Quoted 3 lines
setfiles/setfiles.c renamed from setfiles/setfiles.c.old +1
-1-return -1 ; +return ERR ; }
--
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.