[CRIU] Re: [PATCH 4/6] tty: Rework tty entry verification

Cyrill Gorcunov gorcunov at openvz.org
Fri Sep 14 08:50:43 EDT 2012


On Fri, Sep 14, 2012 at 04:08:04PM +0400, Pavel Emelyanov wrote:
> On 09/14/2012 02:38 PM, Cyrill Gorcunov wrote:
> > 
> > tty entries might have no parameters assigned if they
> > are hanging on closed master, we should take into
> > account when we do verify them.
> > 
> > Signed-off-by: Cyrill Gorcunov <gorcunov at openvz.org>
> > ---
> >  tty.c |   55 +++++++++++++++++++++++++++++++++++++++++++------------
> >  1 files changed, 43 insertions(+), 12 deletions(-)
> > 
> 
> > +	if (!pty_is_master(info)) {
> > +		if (info->tie->sid || info->tie->pgrp)
> > +			pr_err("Found sid %d pgrp %d on slave peer %x\n",
> > +			       info->tie->sid, info->tie->pgrp, info->tfe->id);
> 
> return -1 lost?

Update
-------------- next part --------------
>From 46b3d705195f58709edaf05a4418626185c5e18c Mon Sep 17 00:00:00 2001
From: Cyrill Gorcunov <gorcunov at openvz.org>
Date: Fri, 14 Sep 2012 11:22:33 +0400
Subject: [PATCH] tty: Rework tty entry verification

tty entries might have no parameters assigned if they
are hanging on closed master, we should take into
account when we do verify them.

Signed-off-by: Cyrill Gorcunov <gorcunov at openvz.org>
---
 tty.c |   57 +++++++++++++++++++++++++++++++++++++++++++++------------
 1 files changed, 45 insertions(+), 12 deletions(-)

diff --git a/tty.c b/tty.c
index b0f9737..2acb1a7 100644
--- a/tty.c
+++ b/tty.c
@@ -638,7 +638,7 @@ static int tty_setup_slavery(void)
 	return 0;
 }
 
-static int veirfy_termios(u32 id, TermiosEntry *e)
+static int verify_termios(u32 id, TermiosEntry *e)
 {
 	if (e && e->n_c_cc < TERMIOS_NCC) {
 		pr_err("pty ID %#x n_c_cc (%d) has wrong value\n",
@@ -648,6 +648,49 @@ static int veirfy_termios(u32 id, TermiosEntry *e)
 	return 0;
 }
 
+#define term_opts_missing_cmp(p, op)		\
+	(!(p)->tie->termios		op	\
+	 !(p)->tie->termios_locked	op	\
+	 !(p)->tie->winsize)
+
+#define term_opts_missing_any(p)		\
+	term_opts_missing_cmp(p, ||)
+
+#define term_opts_missing_all(p)		\
+	term_opts_missing_cmp(p, &&)
+
+static int verify_info(struct tty_info *info)
+{
+	/*
+	 * Master peer must have all parameters present,
+	 * while slave peer must have either all parameters present
+	 * or don't have them at all.
+	 */
+	if (term_opts_missing_any(info)) {
+		if (pty_is_master(info)) {
+			pr_err("Corrupted master peer %x\n", info->tfe->id);
+			return -1;
+		} else if (!term_opts_missing_all(info)) {
+			pr_err("Corrupted slave peer %x\n", info->tfe->id);
+			return -1;
+		}
+	}
+
+	if (verify_termios(info->tfe->id, info->tie->termios_locked) ||
+	    verify_termios(info->tfe->id, info->tie->termios))
+		return -1;
+
+	if (!pty_is_master(info)) {
+		if (info->tie->sid || info->tie->pgrp) {
+			pr_err("Found sid %d pgrp %d on slave peer %x\n",
+			       info->tie->sid, info->tie->pgrp, info->tfe->id);
+			return -1;
+		}
+	}
+
+	return 0;
+}
+
 static TtyInfoEntry *lookup_tty_info_entry(u32 id)
 {
 	struct tty_info_entry *e;
@@ -700,18 +743,8 @@ static int collect_one_tty(void *obj, ProtobufCMessage *msg)
 	INIT_LIST_HEAD(&info->sibling);
 	info->major = major(info->tie->rdev);
 
-	/*
-	 * Verify data obtained from the image.
-	 */
-	if (veirfy_termios(info->tfe->id, info->tie->termios))
+	if (verify_info(info))
 		return -1;
-	else if (veirfy_termios(info->tfe->id, info->tie->termios_locked))
-		return -1;
-	else if (!pty_is_master(info) && (info->tie->sid || info->tie->pgrp)) {
-		pr_err("Found sid %d pgrp %d on slave peer %x\n",
-			info->tie->sid, info->tie->pgrp, info->tfe->id);
-		return -1;
-	}
 
 	pr_info("Collected tty ID %#x\n", info->tfe->id);
 
-- 
1.7.7.6



More information about the CRIU mailing list