[CRIU] [PATCH] kerndat: do not report error on loginuid feature test

Dmitry Safonov dsafonov at virtuozzo.com
Mon Feb 8 04:32:00 PST 2016


Fix for commit 0ce8e4299506 ("kerndat: do not report errors on feature
test").
That commit hid error messages for feature testing when you cannot
write to /proc/*/loginuid files because of missing kernel patch that
allows unsetting loginuid value on older kernels, but it didn't hide
error messages in case of disabled CONFIG_AUDITSYSCALL - then you
don't have loginuid files.
Also fixed comment for kerndat feature test: procfs file might fail
to open if it's missing and that's fine - !CONFIG_AUDITSYSCALL case,
but it can't fail due permission fault on _read_ (then something is
wrong, lets report a problem).

Reported-by: Cyrill Gorcunov <gorcunov at gmail.com>
Signed-off-by: Dmitry Safonov <dsafonov at virtuozzo.com>
---
 cr-dump.c            | 2 +-
 cr-restore.c         | 2 +-
 include/proc_parse.h | 2 +-
 kerndat.c            | 4 ++--
 proc_parse.c         | 5 +++--
 5 files changed, 8 insertions(+), 7 deletions(-)

diff --git a/cr-dump.c b/cr-dump.c
index 41ef9f2..385b7bb 100644
--- a/cr-dump.c
+++ b/cr-dump.c
@@ -329,7 +329,7 @@ static int dump_pid_misc(pid_t pid, TaskCoreEntry *tc)
 		pr_info("dumping /proc/%d/loginuid\n", pid);
 
 		tc->has_loginuid = true;
-		tc->loginuid = parse_pid_loginuid(pid, &ret);
+		tc->loginuid = parse_pid_loginuid(pid, &ret, false);
 		tc->loginuid = userns_uid(tc->loginuid);
 		/*
 		 * loginuid dumping is critical, as if not correctly
diff --git a/cr-restore.c b/cr-restore.c
index d07b141..25d206a 100644
--- a/cr-restore.c
+++ b/cr-restore.c
@@ -1866,7 +1866,7 @@ static int prepare_userns_hook(void)
 	 * inside container due to permissions.
 	 * But you still can set this value if it was unset.
 	 */
-	saved_loginuid = parse_pid_loginuid(getpid(), &ret);
+	saved_loginuid = parse_pid_loginuid(getpid(), &ret, false);
 	if (ret < 0)
 		return -1;
 
diff --git a/include/proc_parse.h b/include/proc_parse.h
index bd5317b..33cd077 100644
--- a/include/proc_parse.h
+++ b/include/proc_parse.h
@@ -125,7 +125,7 @@ struct vm_area_list;
 extern bool add_skip_mount(const char *mountpoint);
 extern struct mount_info *parse_mountinfo(pid_t pid, struct ns_id *nsid, bool for_dump);
 extern int parse_pid_stat(pid_t pid, struct proc_pid_stat *s);
-extern unsigned int parse_pid_loginuid(pid_t pid, int *err);
+extern unsigned int parse_pid_loginuid(pid_t pid, int *err, bool ignore_noent);
 extern int parse_pid_oom_score_adj(pid_t pid, int *err);
 extern int prepare_loginuid(unsigned int value, unsigned int loglevel);
 extern int parse_smaps(pid_t pid, struct vm_area_list *vma_area_list);
diff --git a/kerndat.c b/kerndat.c
index d03fdb3..8764e53 100644
--- a/kerndat.c
+++ b/kerndat.c
@@ -465,8 +465,8 @@ int kerndat_loginuid(bool only_dump)
 
 	kdat.has_loginuid = false;
 
-	/* No such file, or perm fault: CONFIG_AUDITSYSCALL disabled */
-	saved_loginuid = parse_pid_loginuid(getpid(), &ret);
+	/* No such file: CONFIG_AUDITSYSCALL disabled */
+	saved_loginuid = parse_pid_loginuid(getpid(), &ret, true);
 	if (ret < 0)
 		return 0;
 
diff --git a/proc_parse.c b/proc_parse.c
index ddb20de..c7c5775 100644
--- a/proc_parse.c
+++ b/proc_parse.c
@@ -830,13 +830,14 @@ int prepare_loginuid(unsigned int value, unsigned int loglevel)
 	return ret;
 }
 
-unsigned int parse_pid_loginuid(pid_t pid, int *err)
+unsigned int parse_pid_loginuid(pid_t pid, int *err, bool ignore_noent)
 {
 	int fd;
 	ssize_t num;
 
 	*err = 0;
-	fd = open_proc(pid, "loginuid");
+	fd = __open_proc(pid, (ignore_noent) ? ENOENT : 0,
+			O_RDONLY, "loginuid");
 	if (fd < 0)
 		goto out;
 
-- 
2.7.1



More information about the CRIU mailing list