[Devel] [PATCH] c/r: Take uts_sem during checkpoint and restart

Dan Smith danms at us.ibm.com
Thu Apr 16 08:59:45 PDT 2009


Fix the potential for breakage if our UTS changes during checkpoint or
restart by grabbing uts_sem during these operations.

Cc: orenl at cs.columbia.edu
Signed-off-by: Dan Smith <danms at us.ibm.com>
---
 checkpoint/ckpt_task.c |   12 ++++++++----
 checkpoint/rstr_task.c |   17 +++++++++++------
 2 files changed, 19 insertions(+), 10 deletions(-)

diff --git a/checkpoint/ckpt_task.c b/checkpoint/ckpt_task.c
index 4d19e31..589f304 100644
--- a/checkpoint/ckpt_task.c
+++ b/checkpoint/ckpt_task.c
@@ -173,14 +173,16 @@ static int cr_write_utsns(struct cr_ctx *ctx, struct uts_namespace *uts_ns)
 	struct cr_hdr_utsns *hh;
 	int domainname_len;
 	int nodename_len;
-	int ret;
+	int ret = -ENOMEM;
+
+ 	down_read(&uts_sem);
 
 	h.type = CR_HDR_UTSNS;
 	h.len = sizeof(*hh);
 
 	hh = cr_hbuf_get(ctx, sizeof(*hh));
 	if (!hh)
-		return -ENOMEM;
+		goto out;
 
 	nodename_len = strlen(uts_ns->name.nodename) + 1;
 	domainname_len = strlen(uts_ns->name.domainname) + 1;
@@ -191,13 +193,15 @@ static int cr_write_utsns(struct cr_ctx *ctx, struct uts_namespace *uts_ns)
 	ret = cr_write_obj(ctx, &h, hh);
 	cr_hbuf_put(ctx, sizeof(*hh));
 	if (ret < 0)
-		return ret;
+		goto out;
 
 	ret = cr_write_string(ctx, uts_ns->name.nodename, nodename_len);
 	if (ret < 0)
-		return ret;
+		goto out;
 
 	ret = cr_write_string(ctx, uts_ns->name.domainname, domainname_len);
+ out:
+	up_read(&uts_sem);
 	return ret;
 }
 
diff --git a/checkpoint/rstr_task.c b/checkpoint/rstr_task.c
index fe5c059..ccf60f8 100644
--- a/checkpoint/rstr_task.c
+++ b/checkpoint/rstr_task.c
@@ -171,32 +171,37 @@ static int cr_read_utsns(struct cr_ctx *ctx)
 {
 	struct cr_hdr_utsns *hh;
 	struct uts_namespace *ns;
-	int ret;
+	int ret = -ENOMEM;
+
+	down_write(&uts_sem);
 
 	hh = cr_hbuf_get(ctx, sizeof(*hh));
 	if (!hh)
-		return -ENOMEM;
+		goto out;
 
 	ret = cr_read_obj_type(ctx, hh, sizeof(*hh), CR_HDR_UTSNS);
 	if (ret < 0)
-		goto out;
+		goto out_hbuf;
 
 	ret = -EINVAL;
 	if (hh->nodename_len > sizeof(ns->name.nodename) ||
 	    hh->domainname_len > sizeof(ns->name.domainname))
-		goto out;
+		goto out_hbuf;
 
 	ns = current->nsproxy->uts_ns;
 
 	memset(ns->name.nodename, 0, sizeof(ns->name.nodename));
 	ret = cr_read_string(ctx, ns->name.nodename, hh->nodename_len);
 	if (ret < 0)
-		goto out;
+		goto out_hbuf;
 
 	memset(ns->name.domainname, 0, sizeof(ns->name.domainname));
 	ret = cr_read_string(ctx, ns->name.domainname, hh->domainname_len);
+
+ out_hbuf:
+ 	cr_hbuf_put(ctx, sizeof(*hh));
  out:
-	cr_hbuf_put(ctx, sizeof(*hh));
+	up_write(&uts_sem);
 	return ret;
 }
 
-- 
1.5.6.3

_______________________________________________
Containers mailing list
Containers at lists.linux-foundation.org
https://lists.linux-foundation.org/mailman/listinfo/containers




More information about the Devel mailing list