Blame SOURCES/0058-findmnt-add-option-to-list-all-fs-independent-flags.patch

be81ba
From 2f04609de018013a36396e6a10b317607fb0b625 Mon Sep 17 00:00:00 2001
be81ba
From: Roberto Bergantinos Corpas <rbergant@redhat.com>
be81ba
Date: Tue, 12 Jan 2021 11:58:53 +0100
be81ba
Subject: [PATCH 58/63] findmnt: add option to list all fs-independent flags
be81ba
be81ba
It might be useful for security auditing purposes list all possible
be81ba
mount flags/options including default set which are normally not listed.
be81ba
be81ba
This patch adds "--vfs-all" option to list all fs-independent flags
be81ba
on VFS-OPTIONS column, as well as libmount funcionality to accomplish
be81ba
it.
be81ba
be81ba
i.e.:
be81ba
be81ba
$ findmnt -o VFS-OPTIONS
be81ba
VFS-OPTIONS
be81ba
rw,relatime
be81ba
rw,nosuid,nodev,noexec,relatime
be81ba
rw,nosuid,nodev,noexec,relatime
be81ba
ro,nosuid,nodev,noexec
be81ba
...
be81ba
be81ba
$ findmnt --vfs-all -o VFS-OPTIONS
be81ba
VFS-OPTIONS
be81ba
rw,exec,suid,dev,async,loud,nomand,atime,noiversion,diratime,relatime,nostrictatime,nolazytime,symfollow
be81ba
rw,noexec,nosuid,nodev,async,loud,nomand,atime,noiversion,diratime,relatime,nostrictatime,nolazytime,symfollow
be81ba
rw,noexec,nosuid,nodev,async,loud,nomand,atime,noiversion,diratime,relatime,nostrictatime,nolazytime,symfollow
be81ba
ro,noexec,nosuid,nodev,async,loud,nomand,atime,noiversion,diratime,norelatime,nostrictatime,nolazytime,symfollow
be81ba
...
be81ba
be81ba
[kzak@redhat.com: - cleanup coding style and comments]
be81ba
be81ba
Addresses: https://bugzilla.redhat.com/show_bug.cgi?id=1917852
be81ba
Upstream: http://github.com/karelzak/util-linux/commit/ff21f476f85ac9855452f4aac43a231c3c1e2ebc
be81ba
Signed-off-by: Roberto Bergantinos Corpas <rbergant@redhat.com>
be81ba
Signed-off-by: Karel Zak <kzak@redhat.com>
be81ba
---
be81ba
 libmount/docs/libmount-sections.txt |  1 +
be81ba
 libmount/src/fs.c                   | 32 +++++++++++++++++++++++++++++
be81ba
 libmount/src/libmount.h.in          |  1 +
be81ba
 libmount/src/libmount.sym           |  4 ++++
be81ba
 misc-utils/findmnt.8                |  6 ++++++
be81ba
 misc-utils/findmnt.c                | 15 +++++++++++---
be81ba
 misc-utils/findmnt.h                |  2 ++
be81ba
 7 files changed, 58 insertions(+), 3 deletions(-)
be81ba
be81ba
diff --git a/libmount/docs/libmount-sections.txt b/libmount/docs/libmount-sections.txt
be81ba
index dea724b2f..f296c0611 100644
be81ba
--- a/libmount/docs/libmount-sections.txt
be81ba
+++ b/libmount/docs/libmount-sections.txt
be81ba
@@ -224,6 +224,7 @@ mnt_fs_get_usedsize
be81ba
 mnt_fs_get_userdata
be81ba
 mnt_fs_get_user_options
be81ba
 mnt_fs_get_vfs_options
be81ba
+mnt_fs_get_vfs_options_all
be81ba
 mnt_fs_is_kernel
be81ba
 mnt_fs_is_netfs
be81ba
 mnt_fs_is_pseudofs
be81ba
diff --git a/libmount/src/fs.c b/libmount/src/fs.c
be81ba
index aae4961c3..34c09d66b 100644
be81ba
--- a/libmount/src/fs.c
be81ba
+++ b/libmount/src/fs.c
be81ba
@@ -924,6 +924,38 @@ const char *mnt_fs_get_vfs_options(struct libmnt_fs *fs)
be81ba
 	return fs ? fs->vfs_optstr : NULL;
be81ba
 }
be81ba
 
be81ba
+/**
be81ba
+ * mnt_fs_get_vfs_options_all:
be81ba
+ * @fs: fstab/mtab entry pointer
be81ba
+ *
be81ba
+ * Returns: pointer to newlly allocated string (can be freed by free(3)) or
be81ba
+ * NULL in case of error.  The string contains all (including defaults) mount
be81ba
+ * options.
be81ba
+ */
be81ba
+char *mnt_fs_get_vfs_options_all(struct libmnt_fs *fs)
be81ba
+{
be81ba
+	const struct libmnt_optmap *map = mnt_get_builtin_optmap(MNT_LINUX_MAP);
be81ba
+	const struct libmnt_optmap *ent;
be81ba
+	const char *opts = mnt_fs_get_options(fs);
be81ba
+	char *result = NULL;
be81ba
+	unsigned long flags = 0;
be81ba
+
be81ba
+	if (!opts || mnt_optstr_get_flags(opts, &flags, map))
be81ba
+		return NULL;
be81ba
+
be81ba
+	for (ent = map ; ent && ent->name ; ent++){
be81ba
+		if (ent->id & flags) { /* non-default value */
be81ba
+			if (!(ent->mask & MNT_INVERT))
be81ba
+				mnt_optstr_append_option(&result, ent->name, NULL);
be81ba
+			else
be81ba
+				continue;
be81ba
+		} else if (ent->mask & MNT_INVERT)
be81ba
+			mnt_optstr_append_option(&result, ent->name, NULL);
be81ba
+	}
be81ba
+
be81ba
+	return result;
be81ba
+}
be81ba
+
be81ba
 /**
be81ba
  * mnt_fs_get_user_options:
be81ba
  * @fs: fstab/mtab entry pointer
be81ba
diff --git a/libmount/src/libmount.h.in b/libmount/src/libmount.h.in
be81ba
index c61514b59..1d9a053e0 100644
be81ba
--- a/libmount/src/libmount.h.in
be81ba
+++ b/libmount/src/libmount.h.in
be81ba
@@ -452,6 +452,7 @@ extern int mnt_fs_get_option(struct libmnt_fs *fs, const char *name,
be81ba
 extern const char *mnt_fs_get_fs_options(struct libmnt_fs *fs);
be81ba
 extern const char *mnt_fs_get_vfs_options(struct libmnt_fs *fs);
be81ba
 extern const char *mnt_fs_get_user_options(struct libmnt_fs *fs);
be81ba
+extern char *mnt_fs_get_vfs_options_all(struct libmnt_fs *fs);
be81ba
 
be81ba
 extern const char *mnt_fs_get_attributes(struct libmnt_fs *fs);
be81ba
 extern int mnt_fs_set_attributes(struct libmnt_fs *fs, const char *optstr);
be81ba
diff --git a/libmount/src/libmount.sym b/libmount/src/libmount.sym
be81ba
index ca16cafa1..636c564eb 100644
be81ba
--- a/libmount/src/libmount.sym
be81ba
+++ b/libmount/src/libmount.sym
be81ba
@@ -322,3 +322,7 @@ MOUNT_2.30 {
be81ba
 	mnt_context_enable_rwonly_mount;
be81ba
 	mnt_context_get_excode;
be81ba
 } MOUNT_2.28;
be81ba
+
be81ba
+MOUNT_2_37 {
be81ba
+	mnt_fs_get_vfs_options_all;
be81ba
+} MOUNT_2.30;
be81ba
diff --git a/misc-utils/findmnt.8 b/misc-utils/findmnt.8
be81ba
index 58dd38625..41a37cb5f 100644
be81ba
--- a/misc-utils/findmnt.8
be81ba
+++ b/misc-utils/findmnt.8
be81ba
@@ -249,6 +249,12 @@ It's possible to specify source (device) or target (mountpoint) to filter mount
be81ba
 .TP
be81ba
 .BR "\-\-verbose"
be81ba
 Force findmnt to print more information (\fB\-\-verify\fP only for now).
be81ba
+.TP
be81ba
+.B \-\-vfs-all
be81ba
+When used with
be81ba
+.BR VFS-OPTIONS
be81ba
+column, print all VFS (fs-independent) flags.  This option is designed for auditing purposes to
be81ba
+list also default VFS kernel mount options which are normally not listed.
be81ba
 .SH EXAMPLES
be81ba
 .IP "\fBfindmnt \-\-fstab \-t nfs\fP"
be81ba
 Prints all NFS filesystems defined in
be81ba
diff --git a/misc-utils/findmnt.c b/misc-utils/findmnt.c
be81ba
index 184b6f7d7..a7b3af4f4 100644
be81ba
--- a/misc-utils/findmnt.c
be81ba
+++ b/misc-utils/findmnt.c
be81ba
@@ -542,7 +542,10 @@ static char *get_data(struct libmnt_fs *fs, int num)
be81ba
 		str = xstrdup(mnt_fs_get_options(fs));
be81ba
 		break;
be81ba
 	case COL_VFS_OPTIONS:
be81ba
-		str = xstrdup(mnt_fs_get_vfs_options(fs));
be81ba
+		if (flags & FL_VFS_ALL)
be81ba
+			str = mnt_fs_get_vfs_options_all(fs);
be81ba
+		else if (mnt_fs_get_vfs_options(fs))
be81ba
+			str = xstrdup(mnt_fs_get_vfs_options(fs));
be81ba
 		break;
be81ba
 	case COL_FS_OPTIONS:
be81ba
 		str = xstrdup(mnt_fs_get_fs_options(fs));
be81ba
@@ -1243,6 +1246,7 @@ static void __attribute__((__noreturn__)) usage(void)
be81ba
 	fputc('\n', out);
be81ba
 	fputs(_(" -x, --verify           verify mount table content (default is fstab)\n"), out);
be81ba
 	fputs(_("     --verbose          print more details\n"), out);
be81ba
+	fputs(_("     --vfs-all          print all VFS options\n"), out);
be81ba
 
be81ba
 	fputs(USAGE_SEPARATOR, out);
be81ba
 	printf(USAGE_HELP_OPTIONS(24));
be81ba
@@ -1271,8 +1275,9 @@ int main(int argc, char *argv[])
be81ba
 	struct libscols_table *table = NULL;
be81ba
 
be81ba
 	enum {
be81ba
-                FINDMNT_OPT_VERBOSE = CHAR_MAX + 1,
be81ba
-		FINDMNT_OPT_TREE
be81ba
+		FINDMNT_OPT_VERBOSE = CHAR_MAX + 1,
be81ba
+		FINDMNT_OPT_TREE,
be81ba
+		FINDMNT_OPT_VFS_ALL
be81ba
 	};
be81ba
 
be81ba
 	static const struct option longopts[] = {
be81ba
@@ -1313,6 +1318,7 @@ int main(int argc, char *argv[])
be81ba
 		{ "version",	    no_argument,       NULL, 'V'		 },
be81ba
 		{ "verbose",	    no_argument,       NULL, FINDMNT_OPT_VERBOSE },
be81ba
 		{ "tree",	    no_argument,       NULL, FINDMNT_OPT_TREE	 },
be81ba
+		{ "vfs-all",	    no_argument,       NULL, FINDMNT_OPT_VFS_ALL },
be81ba
 		{ NULL, 0, NULL, 0 }
be81ba
 	};
be81ba
 
be81ba
@@ -1479,6 +1485,9 @@ int main(int argc, char *argv[])
be81ba
 		case FINDMNT_OPT_TREE:
be81ba
 			force_tree = 1;
be81ba
 			break;
be81ba
+		case FINDMNT_OPT_VFS_ALL:
be81ba
+			flags |= FL_VFS_ALL;
be81ba
+			break;
be81ba
 		default:
be81ba
 			errtryhelp(EXIT_FAILURE);
be81ba
 		}
be81ba
diff --git a/misc-utils/findmnt.h b/misc-utils/findmnt.h
be81ba
index fbaa38e82..9a277b68a 100644
be81ba
--- a/misc-utils/findmnt.h
be81ba
+++ b/misc-utils/findmnt.h
be81ba
@@ -19,6 +19,8 @@ enum {
be81ba
 	FL_STRICTTARGET = (1 << 15),
be81ba
 	FL_VERBOSE	= (1 << 16),
be81ba
 
be81ba
+	FL_VFS_ALL	= (1 << 19),
be81ba
+
be81ba
 	/* basic table settings */
be81ba
 	FL_ASCII	= (1 << 20),
be81ba
 	FL_RAW		= (1 << 21),
be81ba
-- 
be81ba
2.31.1
be81ba