Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux

scm: lower SCM_MAX_FD

Lower SCM_MAX_FD from 255 to 253 so that allocations for scm_fp_list are
halved. (commit f8d570a4 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 <eric.dumazet@gmail.com>
Signed-off-by: David S. Miller <davem@davemloft.net>

authored by

Eric Dumazet and committed by
David S. Miller
bba14de9 456b61bc

+9 -6
+3 -2
include/net/scm.h
··· 10 10 /* Well, we should have at least one descriptor open 11 11 * to accept passed FDs 8) 12 12 */ 13 - #define SCM_MAX_FD 255 13 + #define SCM_MAX_FD 253 14 14 15 15 struct scm_fp_list { 16 16 struct list_head list; 17 - int count; 17 + short count; 18 + short max; 18 19 struct file *fp[SCM_MAX_FD]; 19 20 }; 20 21
+6 -4
net/core/scm.c
··· 79 79 return -ENOMEM; 80 80 *fplp = fpl; 81 81 fpl->count = 0; 82 + fpl->max = SCM_MAX_FD; 82 83 } 83 84 fpp = &fpl->fp[fpl->count]; 84 85 85 - if (fpl->count + num > SCM_MAX_FD) 86 + if (fpl->count + num > fpl->max) 86 87 return -EINVAL; 87 88 88 89 /* ··· 332 331 if (!fpl) 333 332 return NULL; 334 333 335 - new_fpl = kmalloc(sizeof(*fpl), GFP_KERNEL); 334 + new_fpl = kmemdup(fpl, offsetof(struct scm_fp_list, fp[fpl->count]), 335 + GFP_KERNEL); 336 336 if (new_fpl) { 337 - for (i=fpl->count-1; i>=0; i--) 337 + for (i = 0; i < fpl->count; i++) 338 338 get_file(fpl->fp[i]); 339 - memcpy(new_fpl, fpl, sizeof(*fpl)); 339 + new_fpl->max = new_fpl->count; 340 340 } 341 341 return new_fpl; 342 342 }