mkfs.ubifs: Implement selinux labelling support
Subsystems (2)
cover mkfs.ubifs: Implement selinux labelling support
Hi All,
This patchset implements the selinux context labelling support in mkfs.ubifs utility which was discussed here [1]. Patchset is based upon previous work done by John [2]. Commit texts should explain about the change description.
I have tested this on my 4.9 kernel NAND based internal device with UBIFS and selinux enabled. With this we are able to set the respective selinux labels based on the input file_context provided in mkfs.ubifs command.
[1]:- http://lists.infradead.org/pipermail/linux-mtd/2018-May/081138.html
[2]:- http://lists.infradead.org/pipermail/linux-mtd/2014-February/052136.html
Ritesh Harjani (2):
mkfs.ubifs: add_xattr is not depending on host XATTR support mkfs.ubifs: Implement selinux labelling support in mkfs.ubifs.
Makefile.am | 4 + configure.ac | 27 +++++ ubifs-utils/Makemodule.am | 4 +- ubifs-utils/mkfs.ubifs/mkfs.ubifs.c | 197 ++++++++++++++++++++++++++++-------- 4 files changed, 189 insertions(+), 43 deletions(-)
Signature · 2 lines
The Qualcomm Innovation Center, Inc. is a member of Code Aurora Forum, a Linux Foundation Collaborative Project.
RFC PATCH 1/2 mkfs.ubifs: add_xattr is not depending on host XATTR support
add_xattr adds the xattr to the ubifs image and has nothing to do with host XATTR support.
Now that we are adding support where selinux interfaces may use this API even when host OS(where ubi/ubifs image is being created) does not support XATTR -so remove it from WITHOUT_XATTR #ifdef.
--- ubifs-utils/mkfs.ubifs/mkfs.ubifs.c | 80 ++++++++++++++++++------------------- 1 file changed, 40 insertions(+), 40 deletions(-)
ubifs-utils/mkfs.ubifs/mkfs.ubifs.c +40 -40
@@ -1007,46 +1007,6 @@ static int add_node(union ubifs_key *key, char *name, void *node, int len)return 0 ; } -#ifdef WITHOUT_XATTR -static inline int create_inum_attr (ino_t inum,const char *name) -{ - (void )inum; - (void )name; - -return 0 ; -} - -static inline int inode_add_xattr (struct ubifs_ino_node *host_ino, -const char *path_name,struct stat *st,ino_t inum) -{ - (void )host_ino; - (void )path_name; - (void )st; - (void )inum; - -return 0 ; -} -#else -static int create_inum_attr (ino_t inum,const char *name) -{ -char *str; -int ret; - -if (!do_create_inum_attr) -return 0 ; - - ret =asprintf (&str,"%llu" , (unsigned long long )inum); -if (ret <0 ) -return -1 ; - - ret =lsetxattr (name,"user.image-inode-number" , str, ret,0 ); - -free (str); - -return ret; -} - -static int add_xattr (struct stat *st,ino_t inum,const void *data,unsigned int data_len,struct qstr *nm) {
@@ -1117,6 +1077,46 @@ out:return ret; } +#ifdef WITHOUT_XATTR +static inline int create_inum_attr (ino_t inum,const char *name) +{ + (void )inum; + (void )name; + +return 0 ; +} + +static inline int inode_add_xattr (struct ubifs_ino_node *host_ino, +const char *path_name, +struct stat *st,ino_t inum) +{ + (void )host_ino; + (void )path_name; + (void )st; + (void )inum; + +return 0 ; +} +#else +static int create_inum_attr (ino_t inum,const char *name) +{ +char *str; +int ret; + +if (!do_create_inum_attr) +return 0 ; + + ret =asprintf (&str,"%llu" , (unsigned long long )inum); +if (ret <0 ) +return ret; + + ret =lsetxattr (name,"user.image-inode-number" , str, ret,0 ); + +free (str); + +return ret; +} +static int inode_add_xattr (struct ubifs_ino_node *host_ino,const char *path_name,struct stat *st,ino_t inum) {
Signature · 2 lines
The Qualcomm Innovation Center, Inc. is a member of Code Aurora Forum, a Linux Foundation Collaborative Project.
RFC PATCH 2/2 mkfs.ubifs: Implement selinux labelling support in mkfs.ubifs.
In reply to Ritesh HarjaniThis implements/adds selinux labelling support to mkfs.ubifs utility. It adds an extra option in configure to enable selinux labelling support and then finally in mkfs.ubifs adds an extra option to pass the file_contexts which is looked up for filesystem file labels.
- Default behavior is kept without selinux so as to not break existing support where selinux library/headers may not be present.
- If this is configured with --with-selinux then XATTR from the file_contexts(passed with --selinux option while mkfs.ubifs) will be taken and not from the host file's xattr.
This is done to avoid the problem where the host OS may have selinux enabled and hence same xattr names will be present in both host filesystem files and from the --selinux=file passed. So the existing behavior is kept mutually exclusive and preference is given to selinux xattrs (if configured with --with-selinux).
--- Makefile.am | 4 ++ configure.ac | 27 +++++++++ ubifs-utils/Makemodule.am | 4 +- ubifs-utils/mkfs.ubifs/mkfs.ubifs.c | 117 +++++++++++++++++++++++++++++++++++- 4 files changed, 149 insertions(+), 3 deletions(-)
Makefile.am +4 -0
@@ -10,6 +10,10 @@ if WITHOUT_LZO AM_CPPFLAGS += -DWITHOUT_LZO endif +if WITH_SELINUX +AM_CPPFLAGS += -DWITH_SELINUX +endif + sbin_PROGRAMS = sbin_SCRIPTS = check_PROGRAMS =
configure.ac +27 -0
@@ -59,6 +59,7 @@ need_zlib="no" need_lzo="no" need_xattr="no" need_cmocka="no" +need_selinux="no" AM_COND_IF([UNIT_TESTS], [
@@ -144,6 +145,15 @@ AC_ARG_WITH([lzo], *) AC_MSG_ERROR([bad value ${withval} for --without-lzo]) ;; esac]) +AC_ARG_WITH([selinux], + [AS_HELP_STRING([--with-selinux], + [Enable support for selinux extended attributes])], + [case "${withval}" in + yes) need_selinux="yes";; + no) ;; + *) AC_MSG_ERROR([bad value ${withval} for --with-selinux]) ;; + esac]) + ##### search for dependencies ##### clock_gettime_missing="no"
@@ -153,11 +163,16 @@ zlib_missing="no" lzo_missing="no" xattr_missing="no" cmocka_missing="no" +selinux_missing="no" if test "x$need_zlib" = "xyes"; then PKG_CHECK_MODULES(ZLIB, [zlib], [], [zlib_missing="yes"]) fi +if test "x$need_selinux" = "xyes"; then + PKG_CHECK_MODULES(LIBSELINUX, [libselinux], [], [selinux_missing="yes"]) +fi + if test "x$need_uuid" = "xyes"; then PKG_CHECK_MODULES(UUID, [uuid], [], [uuid_missing="yes"]) fi
@@ -186,6 +201,11 @@ if test "x$need_xattr" = "xyes"; then AC_CHECK_HEADERS([sys/acl.h], [], [xattr_missing="yes"]) fi +if test "x$need_selinux" = "xyes"; then + AC_CHECK_HEADERS([selinux/selinux.h], [], [selinux_missing="yes"]) + AC_CHECK_HEADERS([selinux/label.h], [], [selinux_missing="yes"]) +fi + if test "x$need_cmocka" = "xyes"; then PKG_CHECK_MODULES(CMOCKA, [cmocka], [], [cmocka_missing="yes"]) fi
@@ -235,6 +255,12 @@ if test "x$xattr_missing" = "xyes"; then need_xattr="no" fi +if test "x$selinux_missing" = "xyes"; then + AC_MSG_WARN([cannot find headers for selinux library]) + AC_MSG_WARN([disabling SELINUX support]) + need_selinux="no" +fi + if test "x$cmocka_missing" = "xyes"; then AC_MSG_WARN([cannot find CMocka library required for unit tests]) AC_MSG_NOTICE([unit tests can optionally be disabled])
@@ -249,6 +275,7 @@ fi AM_CONDITIONAL([WITHOUT_LZO], [test "x$need_lzo" != "xyes"]) AM_CONDITIONAL([WITHOUT_XATTR], [test "x$need_xattr" != "xyes"]) +AM_CONDITIONAL([WITH_SELINUX], [test "x$need_selinux" == "xyes"]) AC_CHECK_SIZEOF([off_t]) AC_CHECK_SIZEOF([loff_t])
ubifs-utils/Makemodule.am +2 -2
@@ -16,8 +16,8 @@ mkfs_ubifs_SOURCES = \ ubifs-utils/mkfs.ubifs/hashtable/hashtable.c \ ubifs-utils/mkfs.ubifs/hashtable/hashtable_itr.c \ ubifs-utils/mkfs.ubifs/devtable.c -mkfs_ubifs_LDADD = libmtd.a libubi.a $(ZLIB_LIBS) $(LZO_LIBS) $(UUID_LIBS) -lm -mkfs_ubifs_CPPFLAGS = $(AM_CPPFLAGS) $(ZLIB_CFLAGS) $(LZO_CFLAGS) $(UUID_CFLAGS) \ +mkfs_ubifs_LDADD = libmtd.a libubi.a $(ZLIB_LIBS) $(LZO_LIBS) $(UUID_LIBS) $(LIBSELINUX_LIBS) -lm +mkfs_ubifs_CPPFLAGS = $(AM_CPPFLAGS) $(ZLIB_CFLAGS) $(LZO_CFLAGS) $(UUID_CFLAGS) $(LIBSELINUX_CFLAGS)\ -I$(top_srcdir)/ubi-utils/include -I$(top_srcdir)/ubifs-utils/mkfs.ubifs/ UBIFS_BINS = \
ubifs-utils/mkfs.ubifs/mkfs.ubifs.c +116 -1
184 lines not on this page · raw message
Signature · 2 lines
The Qualcomm Innovation Center, Inc. is a member of Code Aurora Forum, a Linux Foundation Collaborative Project.
Gentle reminder!!
Regards
Ritesh
Quoted 25 lines · Ritesh Harjani
Hi All,
This patchset implements the selinux context labelling support in mkfs.ubifs utility which was discussed here [1]. Patchset is based upon previous work done by John [2]. Commit texts should explain about the change description.
I have tested this on my 4.9 kernel NAND based internal device with UBIFS and selinux enabled. With this we are able to set the respective selinux labels based on the input
file_contextprovided in mkfs.ubifs command.[1]:- http://lists.infradead.org/pipermail/linux-mtd/2018-May/081138.html
[2]:- http://lists.infradead.org/pipermail/linux-mtd/2014-February/052136.htmlRitesh Harjani (2):
mkfs.ubifs:add_xattris not depending on host XATTR support mkfs.ubifs: Implement selinux labelling support in mkfs.ubifs.Makefile.am | 4 + configure.ac | 27 +++++ ubifs-utils/Makemodule.am | 4 +- ubifs-utils/mkfs.ubifs/mkfs.ubifs.c | 197 ++++++++++++++++++++++++++++-------- 4 files changed, 189 insertions(+), 43 deletions(-)
Richard Weinberger
maintainerAm Montag, 11. Juni 2018, 06:27:20 CEST schrieb Ritesh Harjani:
Quoted 1 line
Gentle reminder!!
"gentle" with two exclamation marks? ...
Please give David at least a full week before pushing.
Thanks,
//richard
Quoted 3 lines · Richard Weinberger
Am Montag, 11. Juni 2018, 06:27:20 CEST schrieb Ritesh Harjani:
Quoted 1 line
Gentle reminder!!
"gentle" with two exclamation marks? ...
This was just out of habit.
Quoted 2 lines
Please give David at least a full week before pushing.
Sorry about that. No intention of pushing :)
Thanks
Ritesh
Hi,
sorry for the delay. I was quite busy during the last week and got a little less done than I expected. Also, it took me a little more time for closer inspection, since the patch set conflicted with another big mkfs.ubifs patch set that I have lying around on my end.
The changes look good to me so far. I pushed it to mtd-utils.git master.
Thanks,
David
Quoted 7 lines · David Oberhollenzer
Hi,
sorry for the delay. I was quite busy during the last week and got a little less done than I expected. Also, it took me a little more time for closer inspection, since the patch set conflicted with another big mkfs.ubifs patch set that I have lying around on my end.
Np. Thanks for the review.
Quoted 2 lines
The changes look good to me so far. I pushed it to mtd-utils.git master.
Sure thanks.
Quoted 10 lines
Thanks,
David
______________________________________________________
Linux MTD discussion mailing list
http://lists.infradead.org/mailman/listinfo/linux-mtd/