[kbuild] Re: [PATCH] ntp: use memset and offsetof init

From: Dan Carpenter
Date: Wed Jan 20 2021 - 05:25:51 EST


Hi Yejune,

url: https://github.com/0day-ci/linux/commits/Yejune-Deng/ntp-use-memset-and-offsetof-init/20210120-110830
base: https://git.kernel.org/pub/scm/linux/kernel/git/tip/tip.git 3cabca87b329cbcbdf295be0094adbd72c7b1f67
config: i386-randconfig-m021-20210120 (attached as .config)
compiler: gcc-9 (Debian 9.3.0-15) 9.3.0

If you fix the issue, kindly add following tag as appropriate
Reported-by: kernel test robot <lkp@xxxxxxxxx>
Reported-by: Dan Carpenter <dan.carpenter@xxxxxxxxxx>

smatch warnings:
kernel/time/ntp.c:232 pps_fill_timex() warn: potential pointer math issue ('txc' is a 1664 bit pointer)

vim +232 kernel/time/ntp.c

ead25417f82ed7f8 Deepa Dinamani 2018-07-02 225 static inline void pps_fill_timex(struct __kernel_timex *txc)
025b40abe715d638 Alexander Gordeev 2011-01-12 226 {
025b40abe715d638 Alexander Gordeev 2011-01-12 227 /* PPS is not implemented, so these are zero */
a29bace5d3c06a35 Yejune Deng 2021-01-20 228 int offset, len;
a29bace5d3c06a35 Yejune Deng 2021-01-20 229
a29bace5d3c06a35 Yejune Deng 2021-01-20 230 offset = offsetof(struct __kernel_timex, ppsfreq);
a29bace5d3c06a35 Yejune Deng 2021-01-20 231 len = offsetof(struct __kernel_timex, tai) - offset;
a29bace5d3c06a35 Yejune Deng 2021-01-20 @232 memset(txc + offset, 0, len);
^^^^^^^^^^^^
The warning message is badly phrased. This needs to be:

memset((u8 *)txc + offset, 0, len);

The current code will corrupt memory if offset is non-zero.

025b40abe715d638 Alexander Gordeev 2011-01-12 233 }

---
0-DAY CI Kernel Test Service, Intel Corporation
https://lists.01.org/hyperkitty/list/kbuild-all@xxxxxxxxxxxx

Attachment: .config.gz
Description: application/gzip

_______________________________________________
kbuild mailing list -- kbuild@xxxxxxxxxxxx
To unsubscribe send an email to kbuild-leave@xxxxxxxxxxxx