Skip to content

Commit bba14de

Browse files
Eric Dumazetdavem330
authored andcommitted
scm: lower SCM_MAX_FD
Lower SCM_MAX_FD from 255 to 253 so that allocations for scm_fp_list are halved. (commit f8d570a added two pointers in this structure) scm_fp_dup() should not copy whole structure (and trigger kmemcheck warnings), but only the used part. While we are at it, only allocate needed size. Signed-off-by: Eric Dumazet <[email protected]> Signed-off-by: David S. Miller <[email protected]>
1 parent 456b61b commit bba14de

File tree

2 files changed

+9
-6
lines changed

2 files changed

+9
-6
lines changed

include/net/scm.h

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,11 +10,12 @@
1010
/* Well, we should have at least one descriptor open
1111
* to accept passed FDs 8)
1212
*/
13-
#define SCM_MAX_FD 255
13+
#define SCM_MAX_FD 253
1414

1515
struct scm_fp_list {
1616
struct list_head list;
17-
int count;
17+
short count;
18+
short max;
1819
struct file *fp[SCM_MAX_FD];
1920
};
2021

net/core/scm.c

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -79,10 +79,11 @@ static int scm_fp_copy(struct cmsghdr *cmsg, struct scm_fp_list **fplp)
7979
return -ENOMEM;
8080
*fplp = fpl;
8181
fpl->count = 0;
82+
fpl->max = SCM_MAX_FD;
8283
}
8384
fpp = &fpl->fp[fpl->count];
8485

85-
if (fpl->count + num > SCM_MAX_FD)
86+
if (fpl->count + num > fpl->max)
8687
return -EINVAL;
8788

8889
/*
@@ -331,11 +332,12 @@ struct scm_fp_list *scm_fp_dup(struct scm_fp_list *fpl)
331332
if (!fpl)
332333
return NULL;
333334

334-
new_fpl = kmalloc(sizeof(*fpl), GFP_KERNEL);
335+
new_fpl = kmemdup(fpl, offsetof(struct scm_fp_list, fp[fpl->count]),
336+
GFP_KERNEL);
335337
if (new_fpl) {
336-
for (i=fpl->count-1; i>=0; i--)
338+
for (i = 0; i < fpl->count; i++)
337339
get_file(fpl->fp[i]);
338-
memcpy(new_fpl, fpl, sizeof(*fpl));
340+
new_fpl->max = new_fpl->count;
339341
}
340342
return new_fpl;
341343
}

0 commit comments

Comments
 (0)