Blame SOURCES/0126-libmount-use-eacess-rather-than-open-to-check-mtab-u.patch

05ad79
From 04cad06bed055a5dd373b2f5babc8000a76597a6 Mon Sep 17 00:00:00 2001
05ad79
From: Karel Zak <kzak@redhat.com>
05ad79
Date: Mon, 9 Oct 2017 12:44:48 +0200
05ad79
Subject: [PATCH] libmount: use eacess() rather than open() to check mtab/utab
05ad79
05ad79
The open() syscall is probably the most strong way how to check write
05ad79
accessibility in all situations, but it's overkill and on some
05ad79
paranoid systems with enabled audit/selinux. It fills logs with
05ad79
"Permission denied" entries. Let's use eaccess() if available.
05ad79
05ad79
Addresses: https://bugzilla.redhat.com/show_bug.cgi?id=1499760
05ad79
Signed-off-by: Karel Zak <kzak@redhat.com>
05ad79
---
05ad79
 configure.ac         |  1 +
05ad79
 libmount/src/utils.c | 19 +++++++++++++------
05ad79
 2 files changed, 14 insertions(+), 6 deletions(-)
05ad79
05ad79
diff --git a/configure.ac b/configure.ac
05ad79
index 78258d677..96c5838cf 100644
05ad79
--- a/configure.ac
05ad79
+++ b/configure.ac
05ad79
@@ -315,6 +315,7 @@ AC_CHECK_FUNCS([ \
05ad79
 	__fpending \
05ad79
 	secure_getenv \
05ad79
 	__secure_getenv \
05ad79
+	eaccess \
05ad79
 	err \
05ad79
 	errx \
05ad79
 	fsync \
05ad79
diff --git a/libmount/src/utils.c b/libmount/src/utils.c
05ad79
index 5c374b432..a275d0a0e 100644
05ad79
--- a/libmount/src/utils.c
05ad79
+++ b/libmount/src/utils.c
05ad79
@@ -653,18 +653,25 @@ done:
05ad79
 
05ad79
 static int try_write(const char *filename)
05ad79
 {
05ad79
-	int fd;
05ad79
+	int rc = 0;
05ad79
 
05ad79
 	if (!filename)
05ad79
 		return -EINVAL;
05ad79
 
05ad79
-	fd = open(filename, O_RDWR|O_CREAT|O_CLOEXEC,
05ad79
+#ifdef HAVE_EACCESS
05ad79
+	if (eaccess(filename, R_OK|W_OK) != 0)
05ad79
+		rc = -errno;
05ad79
+#else
05ad79
+	{
05ad79
+		int fd = open(filename, O_RDWR|O_CREAT|O_CLOEXEC,
05ad79
 			    S_IWUSR|S_IRUSR|S_IRGRP|S_IROTH);
05ad79
-	if (fd >= 0) {
05ad79
-		close(fd);
05ad79
-		return 0;
05ad79
+		if (fd < 0)
05ad79
+			rc = -errno;
05ad79
+		else
05ad79
+			close(fd);
05ad79
 	}
05ad79
-	return -errno;
05ad79
+#endif
05ad79
+	return rc;
05ad79
 }
05ad79
 
05ad79
 /**
05ad79
-- 
05ad79
2.13.6
05ad79