From: Richard Cochran <richardcochran@gmail.com> Date: 2012-11-02 08:59:24
On Fri, Nov 02, 2012 at 10:06:31AM +0800, Yuanhan Liu wrote:
Hi Richard,
_just_ FYI and let you aware of it, there are new smatch warnings show up in
tree: git://git.kernel.org/pub/scm/linux/kernel/git/davem/net-next.git master
head: b77bc2069d1e437d5a1a71bb5cfcf4556ee40015
commit: 215b13dd288c2e1e4461c1530a801f5f83e8cd90 [122/152] ptp: add an ioctl to compare PHC time with system time
+ drivers/ptp/ptp_chardev.c:36 ptp_ioctl() warn: 'sysoff' puts 832 bytes on stack
drivers/ptp/ptp_chardev.c:144 ptp_read() warn: 'event' puts 960 bytes on stack
I am aware that these methods use large stack buffers, but I thought
it was okay seeing as they are both under the 1k limit.
Thanks,
Richard
From: David Miller <davem@davemloft.net> Date: 2012-11-03 01:39:30
From: Richard Cochran <richardcochran@gmail.com>
Date: Fri, 2 Nov 2012 09:59:15 +0100
On Fri, Nov 02, 2012 at 10:06:31AM +0800, Yuanhan Liu wrote:
quoted
Hi Richard,
_just_ FYI and let you aware of it, there are new smatch warnings show up in
tree: git://git.kernel.org/pub/scm/linux/kernel/git/davem/net-next.git master
head: b77bc2069d1e437d5a1a71bb5cfcf4556ee40015
commit: 215b13dd288c2e1e4461c1530a801f5f83e8cd90 [122/152] ptp: add an ioctl to compare PHC time with system time
+ drivers/ptp/ptp_chardev.c:36 ptp_ioctl() warn: 'sysoff' puts 832 bytes on stack
drivers/ptp/ptp_chardev.c:144 ptp_read() warn: 'event' puts 960 bytes on stack
I am aware that these methods use large stack buffers, but I thought
it was okay seeing as they are both under the 1k limit.
I think you should avoid such a local stack variable here.
It's not that big of a deal to use kmalloc or whatever so just
do that and add the necessary kfree cleanups et al.
From: Richard Cochran <richardcochran@gmail.com> Date: 2012-11-03 04:53:49
On Fri, Nov 02, 2012 at 09:39:28PM -0400, David Miller wrote:
quoted
I am aware that these methods use large stack buffers, but I thought
it was okay seeing as they are both under the 1k limit.
I think you should avoid such a local stack variable here.
It's not that big of a deal to use kmalloc or whatever so just
do that and add the necessary kfree cleanups et al.
The usage pattern will be that the user calls these again and
again. For the sysoff it will be at least once every second, and for
the events it could be ASAP in a tight loop.
Isn't it being nicer to the memory allocation code not to repeatedly
request small chunks?
Thanks,
Richard
From: Richard Cochran <richardcochran@gmail.com> Date: 2012-11-26 11:44:46
This patch removes the large buffer from the stack of the read file
operation and replaces it with a kmalloced buffer.
Signed-off-by: Richard Cochran <richardcochran@gmail.com>
---
drivers/ptp/ptp_chardev.c | 22 +++++++++++++++++-----
1 files changed, 17 insertions(+), 5 deletions(-)
From: Richard Cochran <richardcochran@gmail.com> Date: 2012-11-26 11:44:48
This patch removes the large buffer from the stack of the system
offset ioctl and replaces it with a kmalloced buffer.
Signed-off-by: Richard Cochran <richardcochran@gmail.com>
---
drivers/ptp/ptp_chardev.c | 21 ++++++++++++++-------
1 files changed, 14 insertions(+), 7 deletions(-)
@@ -34,7 +34,7 @@ long ptp_ioctl(struct posix_clock *pc, unsigned int cmd, unsigned long arg){structptp_clock_capscaps;structptp_clock_requestreq;-structptp_sys_offsetsysoff;+structptp_sys_offset*sysoff=NULL;structptp_clock*ptp=container_of(pc,structptp_clock,clock);structptp_clock_info*ops=ptp->info;structptp_clock_time*pct;
@@ -94,17 +94,22 @@ long ptp_ioctl(struct posix_clock *pc, unsigned int cmd, unsigned long arg)break;casePTP_SYS_OFFSET:-if(copy_from_user(&sysoff,(void__user*)arg,-sizeof(sysoff))){+sysoff=kmalloc(sizeof(*sysoff),GFP_KERNEL);+if(!sysoff){+err=-ENOMEM;+break;+}+if(copy_from_user(sysoff,(void__user*)arg,+sizeof(*sysoff))){err=-EFAULT;break;}-if(sysoff.n_samples>PTP_MAX_SAMPLES){+if(sysoff->n_samples>PTP_MAX_SAMPLES){err=-EINVAL;break;}-pct=&sysoff.ts[0];-for(i=0;i<sysoff.n_samples;i++){+pct=&sysoff->ts[0];+for(i=0;i<sysoff->n_samples;i++){getnstimeofday(&ts);pct->sec=ts.tv_sec;pct->nsec=ts.tv_nsec;
@@ -117,7 +122,7 @@ long ptp_ioctl(struct posix_clock *pc, unsigned int cmd, unsigned long arg)getnstimeofday(&ts);pct->sec=ts.tv_sec;pct->nsec=ts.tv_nsec;-if(copy_to_user((void__user*)arg,&sysoff,sizeof(sysoff)))+if(copy_to_user((void__user*)arg,sysoff,sizeof(*sysoff)))err=-EFAULT;break;
@@ -125,6 +130,8 @@ long ptp_ioctl(struct posix_clock *pc, unsigned int cmd, unsigned long arg)err=-ENOTTY;break;}++kfree(sysoff);returnerr;}
From: David Miller <davem@davemloft.net> Date: 2012-11-26 22:23:33
From: Richard Cochran <richardcochran@gmail.com>
Date: Mon, 26 Nov 2012 12:44:34 +0100
This patch removes the large buffer from the stack of the read file
operation and replaces it with a kmalloced buffer.
Signed-off-by: Richard Cochran <richardcochran@gmail.com>
From: David Miller <davem@davemloft.net> Date: 2012-11-26 22:23:40
From: Richard Cochran <richardcochran@gmail.com>
Date: Mon, 26 Nov 2012 12:44:35 +0100
This patch removes the large buffer from the stack of the system
offset ioctl and replaces it with a kmalloced buffer.
Signed-off-by: Richard Cochran <richardcochran@gmail.com>