* [PATCH] a multiplication overflow in drivers/pps/pps.c
@ 2013-12-18 7:36 xqx12
2013-12-20 0:37 ` Andrew Morton
0 siblings, 1 reply; 2+ messages in thread
From: xqx12 @ 2013-12-18 7:36 UTC (permalink / raw)
To: giometti, linux-kernel; +Cc: chyyuu, xuyongjiande, xqx12
there is an overflow in the following code :
ticks = fdata.timeout.sec * HZ;
while ticks is a signed 64-bit, but the result of fdata.timeout.sec *
HZ will be converted be 32-bit first. So ticks will be a wrong value
after multiplication overflow.
Reported-by: Qixue Xiao <xiaoqixue_1@163.com>
Suggested-by: Yongjian Xu <xuyongjiande@gmail.com>
Suggested-by: Yu Chen <chyyuu@gmail.com>
Signed-off-by: Qixue Xiao <xiaoqixue_1@163.com>
---
drivers/pps/pps.c | 2 +-
gentags.sh | 4 +++
memory_leak.txt | 88 +++++++++++++++++++++++++++++++++++++++++++++++++++++
3 files changed, 93 insertions(+), 1 deletion(-)
create mode 100755 gentags.sh
create mode 100644 memory_leak.txt
diff --git a/drivers/pps/pps.c b/drivers/pps/pps.c
index 2f07cd6..44ddd22 100644
--- a/drivers/pps/pps.c
+++ b/drivers/pps/pps.c
@@ -164,7 +164,7 @@ static long pps_cdev_ioctl(struct file *file,
dev_dbg(pps->dev, "timeout %lld.%09d\n",
(long long) fdata.timeout.sec,
fdata.timeout.nsec);
- ticks = fdata.timeout.sec * HZ;
+ ticks = (s64)(fdata.timeout.sec) * HZ;
ticks += fdata.timeout.nsec / (NSEC_PER_SEC / HZ);
if (ticks != 0) {
--
1.7.9.5
^ permalink raw reply [flat|nested] 2+ messages in thread
* Re: [PATCH] a multiplication overflow in drivers/pps/pps.c
2013-12-18 7:36 [PATCH] a multiplication overflow in drivers/pps/pps.c xqx12
@ 2013-12-20 0:37 ` Andrew Morton
0 siblings, 0 replies; 2+ messages in thread
From: Andrew Morton @ 2013-12-20 0:37 UTC (permalink / raw)
To: xqx12; +Cc: giometti, linux-kernel, chyyuu, xuyongjiande, xqx12
On Wed, 18 Dec 2013 15:36:11 +0800 xqx12 <s2exqx@gmail.com> wrote:
> there is an overflow in the following code :
>
> ticks = fdata.timeout.sec * HZ;
>
> while ticks is a signed 64-bit, but the result of fdata.timeout.sec *
> HZ will be converted be 32-bit first. So ticks will be a wrong value
> after multiplication overflow.
When fixing a bug, please always include a full description of the
user-visible effects of that bug. This helps others decide which
kernel version(s) should be fixed.
> ...
>
> --- a/drivers/pps/pps.c
> +++ b/drivers/pps/pps.c
> @@ -164,7 +164,7 @@ static long pps_cdev_ioctl(struct file *file,
> dev_dbg(pps->dev, "timeout %lld.%09d\n",
> (long long) fdata.timeout.sec,
> fdata.timeout.nsec);
> - ticks = fdata.timeout.sec * HZ;
> + ticks = (s64)(fdata.timeout.sec) * HZ;
> ticks += fdata.timeout.nsec / (NSEC_PER_SEC / HZ);
>
> if (ticks != 0) {
pps_fdata.timeout.sec has type __s64, so the patch should be a no-op?
Did you really observe a runtime problem from this? If so, I suspect
your compiler is busted.
^ permalink raw reply [flat|nested] 2+ messages in thread
end of thread, other threads:[~2013-12-20 0:37 UTC | newest]
Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2013-12-18 7:36 [PATCH] a multiplication overflow in drivers/pps/pps.c xqx12
2013-12-20 0:37 ` Andrew Morton
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox
all inboxes | Powered by JetHome®