[CRIU] [PATCH] files: char devices -- Make sure only Unix98 pty is being dumped

Cyrill Gorcunov gorcunov at openvz.org
Wed Feb 12 00:03:05 PST 2014


We support only Unix98 terminals for now thus take into
account minor number of the character device.

This is because TTYAUX_MAJOR is used not only for Unix98
but for /dev/console and bsd terminals as well (which we
don't support yet).

Also note that previsouly we printed minor number in
error report as minor(p->stat.st_dev) while it should
be minor(p->stat.st_rdev). And since I need minor anyway
I've fixed it same time.

Signed-off-by: Cyrill Gorcunov <gorcunov at openvz.org>
---
 files.c | 22 +++++++++++++++-------
 1 file changed, 15 insertions(+), 7 deletions(-)

diff --git a/files.c b/files.c
index dc3445ee2f3e..0da96f8daeba 100644
--- a/files.c
+++ b/files.c
@@ -263,31 +263,39 @@ static const struct fdtype_ops *get_misc_dev_ops(int minor)
 static int dump_chrdev(struct fd_parms *p, int lfd, const int fdinfo)
 {
 	int maj = major(p->stat.st_rdev);
+	int minor = minor(p->stat.st_rdev);
 	const struct fdtype_ops *ops;
+	char more[32];
 
 	switch (maj) {
 	case MEM_MAJOR:
 		ops = &regfile_dump_ops;
 		break;
 	case TTYAUX_MAJOR:
+		/*
+		 * We support Unix98 devices only for now.
+		 */
+		if (minor != 2)
+			goto unsupported;
+		/* fallthrough */
 	case UNIX98_PTY_MASTER_MAJOR ... (UNIX98_PTY_MASTER_MAJOR + UNIX98_PTY_MAJOR_COUNT - 1):
 	case UNIX98_PTY_SLAVE_MAJOR:
 		ops = &tty_dump_ops;
 		break;
 	case MISC_MAJOR:
-		ops = get_misc_dev_ops(minor(p->stat.st_rdev));
+		ops = get_misc_dev_ops(minor);
 		if (ops)
 			break;
 		/* fallthrough */
-	default: {
-		char more[32];
-
-		sprintf(more, "%d:%d", maj, minor(p->stat.st_dev));
-		return dump_unsupp_fd(p, lfd, fdinfo, "chr", more);
-	}
+	default:
+		goto unsupported;
 	}
 
 	return do_dump_gen_file(p, lfd, ops, fdinfo);
+
+unsupported:
+	sprintf(more, "%d:%d", maj, minor);
+	return dump_unsupp_fd(p, lfd, fdinfo, "chr", more);
 }
 
 #ifndef PIPEFS_MAGIC
-- 
1.8.3.1



More information about the CRIU mailing list