浏览代码

Merge branch 'for-linus' of git://git.kernel.org/pub/scm/linux/kernel/git/jmorris/selinux-2.6

* 'for-linus' of git://git.kernel.org/pub/scm/linux/kernel/git/jmorris/selinux-2.6:
  SELinux: null-terminate context string in selinux_xfrm_sec_ctx_alloc
Linus Torvalds 18 年之前
父节点
当前提交
80492cc797
共有 1 个文件被更改,包括 2 次插入1 次删除
  1. 2 1
      security/selinux/xfrm.c

+ 2 - 1
security/selinux/xfrm.c

@@ -216,7 +216,7 @@ static int selinux_xfrm_sec_ctx_alloc(struct xfrm_sec_ctx **ctxp,
 		return -ENOMEM;
 		return -ENOMEM;
 
 
 	*ctxp = ctx = kmalloc(sizeof(*ctx) +
 	*ctxp = ctx = kmalloc(sizeof(*ctx) +
-			      uctx->ctx_len,
+			      uctx->ctx_len + 1,
 			      GFP_KERNEL);
 			      GFP_KERNEL);
 
 
 	if (!ctx)
 	if (!ctx)
@@ -229,6 +229,7 @@ static int selinux_xfrm_sec_ctx_alloc(struct xfrm_sec_ctx **ctxp,
 	memcpy(ctx->ctx_str,
 	memcpy(ctx->ctx_str,
 	       uctx+1,
 	       uctx+1,
 	       ctx->ctx_len);
 	       ctx->ctx_len);
+	ctx->ctx_str[ctx->ctx_len] = 0;
 	rc = security_context_to_sid(ctx->ctx_str,
 	rc = security_context_to_sid(ctx->ctx_str,
 				     ctx->ctx_len,
 				     ctx->ctx_len,
 				     &ctx->ctx_sid);
 				     &ctx->ctx_sid);