Chuck Ebbert 7a0a7db
From: Eric Dumazet <eric.dumazet@gmail.com>
Chuck Ebbert 7a0a7db
Date: Tue, 23 Nov 2010 14:09:15 +0000 (+0000)
Chuck Ebbert 7a0a7db
Subject: scm: lower SCM_MAX_FD
Chuck Ebbert 7a0a7db
X-Git-Url: http://git.kernel.org/?p=linux%2Fkernel%2Fgit%2Fdavem%2Fnet-next-2.6.git;a=commitdiff_plain;h=bba14de98753cb6599a2dae0e520714b2153522d
Chuck Ebbert 7a0a7db
Chuck Ebbert 7a0a7db
scm: lower SCM_MAX_FD
Chuck Ebbert 7a0a7db
Chuck Ebbert 7a0a7db
Lower SCM_MAX_FD from 255 to 253 so that allocations for scm_fp_list are
Chuck Ebbert 7a0a7db
halved. (commit f8d570a4 added two pointers in this structure)
Chuck Ebbert 7a0a7db
Chuck Ebbert 7a0a7db
scm_fp_dup() should not copy whole structure (and trigger kmemcheck
Chuck Ebbert 7a0a7db
warnings), but only the used part. While we are at it, only allocate
Chuck Ebbert 7a0a7db
needed size.
Chuck Ebbert 7a0a7db
Chuck Ebbert 7a0a7db
Signed-off-by: Eric Dumazet <eric.dumazet@gmail.com>
Chuck Ebbert 7a0a7db
Signed-off-by: David S. Miller <davem@davemloft.net>
Chuck Ebbert 7a0a7db
---
Chuck Ebbert 7a0a7db
Chuck Ebbert 7a0a7db
diff --git a/include/net/scm.h b/include/net/scm.h
Chuck Ebbert 7a0a7db
index 3165650..745460f 100644
Chuck Ebbert 7a0a7db
--- a/include/net/scm.h
Chuck Ebbert 7a0a7db
+++ b/include/net/scm.h
Chuck Ebbert 7a0a7db
@@ -10,11 +10,12 @@
Chuck Ebbert 7a0a7db
 /* Well, we should have at least one descriptor open
Chuck Ebbert 7a0a7db
  * to accept passed FDs 8)
Chuck Ebbert 7a0a7db
  */
Chuck Ebbert 7a0a7db
-#define SCM_MAX_FD	255
Chuck Ebbert 7a0a7db
+#define SCM_MAX_FD	253
Chuck Ebbert 7a0a7db
 
Chuck Ebbert 7a0a7db
 struct scm_fp_list {
Chuck Ebbert 7a0a7db
 	struct list_head	list;
Chuck Ebbert 7a0a7db
-	int			count;
Chuck Ebbert 7a0a7db
+	short			count;
Chuck Ebbert 7a0a7db
+	short			max;
Chuck Ebbert 7a0a7db
 	struct file		*fp[SCM_MAX_FD];
Chuck Ebbert 7a0a7db
 };
Chuck Ebbert 7a0a7db
 
Chuck Ebbert 7a0a7db
diff --git a/net/core/scm.c b/net/core/scm.c
Chuck Ebbert 7a0a7db
index 413cab8..bbe4544 100644
Chuck Ebbert 7a0a7db
--- a/net/core/scm.c
Chuck Ebbert 7a0a7db
+++ b/net/core/scm.c
Chuck Ebbert 7a0a7db
@@ -79,10 +79,11 @@ static int scm_fp_copy(struct cmsghdr *cmsg, struct scm_fp_list **fplp)
Chuck Ebbert 7a0a7db
 			return -ENOMEM;
Chuck Ebbert 7a0a7db
 		*fplp = fpl;
Chuck Ebbert 7a0a7db
 		fpl->count = 0;
Chuck Ebbert 7a0a7db
+		fpl->max = SCM_MAX_FD;
Chuck Ebbert 7a0a7db
 	}
Chuck Ebbert 7a0a7db
 	fpp = &fpl->fp[fpl->count];
Chuck Ebbert 7a0a7db
 
Chuck Ebbert 7a0a7db
-	if (fpl->count + num > SCM_MAX_FD)
Chuck Ebbert 7a0a7db
+	if (fpl->count + num > fpl->max)
Chuck Ebbert 7a0a7db
 		return -EINVAL;
Chuck Ebbert 7a0a7db
 
Chuck Ebbert 7a0a7db
 	/*
Chuck Ebbert 7a0a7db
@@ -331,11 +332,12 @@ struct scm_fp_list *scm_fp_dup(struct scm_fp_list *fpl)
Chuck Ebbert 7a0a7db
 	if (!fpl)
Chuck Ebbert 7a0a7db
 		return NULL;
Chuck Ebbert 7a0a7db
 
Chuck Ebbert 7a0a7db
-	new_fpl = kmalloc(sizeof(*fpl), GFP_KERNEL);
Chuck Ebbert 7a0a7db
+	new_fpl = kmemdup(fpl, offsetof(struct scm_fp_list, fp[fpl->count]),
Chuck Ebbert 7a0a7db
+			  GFP_KERNEL);
Chuck Ebbert 7a0a7db
 	if (new_fpl) {
Chuck Ebbert 7a0a7db
-		for (i=fpl->count-1; i>=0; i--)
Chuck Ebbert 7a0a7db
+		for (i = 0; i < fpl->count; i++)
Chuck Ebbert 7a0a7db
 			get_file(fpl->fp[i]);
Chuck Ebbert 7a0a7db
-		memcpy(new_fpl, fpl, sizeof(*fpl));
Chuck Ebbert 7a0a7db
+		new_fpl->max = new_fpl->count;
Chuck Ebbert 7a0a7db
 	}
Chuck Ebbert 7a0a7db
 	return new_fpl;
Chuck Ebbert 7a0a7db
 }