2022-10-31 00:00:54

by kernel test robot

[permalink] [raw]
Subject: drivers/net/can/usb/kvaser_usb/kvaser_usb_hydra.c:489:65: warning: array subscript 'struct kvaser_cmd_ext[0]' is partly outside array bounds of 'unsigned char[32]'

tree: https://git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git master
head: 30a0b95b1335e12efef89dd78518ed3e4a71a763
commit: 00784da3e6b8c1f0e58d813272503d014de8f64b can: kvaser_usb: kvaser_usb_hydra: Use kzalloc for allocating only one element
date: 8 weeks ago
config: i386-randconfig-r021-20221031
compiler: gcc-11 (Debian 11.3.0-8) 11.3.0
reproduce (this is a W=1 build):
# https://git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git/commit/?id=00784da3e6b8c1f0e58d813272503d014de8f64b
git remote add linus https://git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
git fetch --no-tags linus master
git checkout 00784da3e6b8c1f0e58d813272503d014de8f64b
# save the config file
mkdir build_dir && cp config build_dir/.config
make W=1 O=build_dir ARCH=i386 SHELL=/bin/bash

If you fix the issue, kindly add following tag where applicable
| Reported-by: kernel test robot <[email protected]>

All warnings (new ones prefixed by >>):

In file included from include/linux/byteorder/little_endian.h:5,
from arch/x86/include/uapi/asm/byteorder.h:5,
from include/asm-generic/bitops/le.h:6,
from arch/x86/include/asm/bitops.h:416,
from include/linux/bitops.h:68,
from include/linux/kernel.h:22,
from arch/x86/include/asm/percpu.h:27,
from arch/x86/include/asm/preempt.h:6,
from include/linux/preempt.h:78,
from include/linux/spinlock.h:55,
from include/linux/swait.h:7,
from include/linux/completion.h:12,
from drivers/net/can/usb/kvaser_usb/kvaser_usb_hydra.c:16:
drivers/net/can/usb/kvaser_usb/kvaser_usb_hydra.c: In function 'kvaser_usb_hydra_send_simple_cmd':
>> drivers/net/can/usb/kvaser_usb/kvaser_usb_hydra.c:489:65: warning: array subscript 'struct kvaser_cmd_ext[0]' is partly outside array bounds of 'unsigned char[32]' [-Warray-bounds]
489 | ret = le16_to_cpu(((struct kvaser_cmd_ext *)cmd)->len);
include/uapi/linux/byteorder/little_endian.h:37:51: note: in definition of macro '__le16_to_cpu'
37 | #define __le16_to_cpu(x) ((__force __u16)(__le16)(x))
| ^
drivers/net/can/usb/kvaser_usb/kvaser_usb_hydra.c:489:23: note: in expansion of macro 'le16_to_cpu'
489 | ret = le16_to_cpu(((struct kvaser_cmd_ext *)cmd)->len);
| ^~~~~~~~~~~
drivers/net/can/usb/kvaser_usb/kvaser_usb_hydra.c:537:15: note: referencing an object of size 32 allocated by 'kzalloc'
537 | cmd = kzalloc(sizeof(*cmd), GFP_KERNEL);
| ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
In file included from include/linux/byteorder/little_endian.h:5,
from arch/x86/include/uapi/asm/byteorder.h:5,
from include/asm-generic/bitops/le.h:6,
from arch/x86/include/asm/bitops.h:416,
from include/linux/bitops.h:68,
from include/linux/kernel.h:22,
from arch/x86/include/asm/percpu.h:27,
from arch/x86/include/asm/preempt.h:6,
from include/linux/preempt.h:78,
from include/linux/spinlock.h:55,
from include/linux/swait.h:7,
from include/linux/completion.h:12,
from drivers/net/can/usb/kvaser_usb/kvaser_usb_hydra.c:16:
drivers/net/can/usb/kvaser_usb/kvaser_usb_hydra.c: In function 'kvaser_usb_hydra_set_opt_mode':
>> drivers/net/can/usb/kvaser_usb/kvaser_usb_hydra.c:489:65: warning: array subscript 'struct kvaser_cmd_ext[0]' is partly outside array bounds of 'unsigned char[32]' [-Warray-bounds]
489 | ret = le16_to_cpu(((struct kvaser_cmd_ext *)cmd)->len);
include/uapi/linux/byteorder/little_endian.h:37:51: note: in definition of macro '__le16_to_cpu'
37 | #define __le16_to_cpu(x) ((__force __u16)(__le16)(x))
| ^
drivers/net/can/usb/kvaser_usb/kvaser_usb_hydra.c:489:23: note: in expansion of macro 'le16_to_cpu'
489 | ret = le16_to_cpu(((struct kvaser_cmd_ext *)cmd)->len);
| ^~~~~~~~~~~
drivers/net/can/usb/kvaser_usb/kvaser_usb_hydra.c:1854:15: note: referencing an object of size 32 allocated by 'kzalloc'
1854 | cmd = kzalloc(sizeof(*cmd), GFP_KERNEL);
| ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
In file included from include/linux/byteorder/little_endian.h:5,
from arch/x86/include/uapi/asm/byteorder.h:5,
from include/asm-generic/bitops/le.h:6,
from arch/x86/include/asm/bitops.h:416,
from include/linux/bitops.h:68,
from include/linux/kernel.h:22,
from arch/x86/include/asm/percpu.h:27,
from arch/x86/include/asm/preempt.h:6,
from include/linux/preempt.h:78,
from include/linux/spinlock.h:55,
from include/linux/swait.h:7,
from include/linux/completion.h:12,
from drivers/net/can/usb/kvaser_usb/kvaser_usb_hydra.c:16:
drivers/net/can/usb/kvaser_usb/kvaser_usb_hydra.c: In function 'kvaser_usb_hydra_set_data_bittiming':
>> drivers/net/can/usb/kvaser_usb/kvaser_usb_hydra.c:489:65: warning: array subscript 'struct kvaser_cmd_ext[0]' is partly outside array bounds of 'unsigned char[32]' [-Warray-bounds]
489 | ret = le16_to_cpu(((struct kvaser_cmd_ext *)cmd)->len);
include/uapi/linux/byteorder/little_endian.h:37:51: note: in definition of macro '__le16_to_cpu'
37 | #define __le16_to_cpu(x) ((__force __u16)(__le16)(x))
| ^
drivers/net/can/usb/kvaser_usb/kvaser_usb_hydra.c:489:23: note: in expansion of macro 'le16_to_cpu'
489 | ret = le16_to_cpu(((struct kvaser_cmd_ext *)cmd)->len);
| ^~~~~~~~~~~
drivers/net/can/usb/kvaser_usb/kvaser_usb_hydra.c:1570:15: note: referencing an object of size 32 allocated by 'kzalloc'
1570 | cmd = kzalloc(sizeof(*cmd), GFP_KERNEL);
| ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
In file included from include/linux/byteorder/little_endian.h:5,
from arch/x86/include/uapi/asm/byteorder.h:5,
from include/asm-generic/bitops/le.h:6,
from arch/x86/include/asm/bitops.h:416,
from include/linux/bitops.h:68,
from include/linux/kernel.h:22,
from arch/x86/include/asm/percpu.h:27,
from arch/x86/include/asm/preempt.h:6,
from include/linux/preempt.h:78,
from include/linux/spinlock.h:55,
from include/linux/swait.h:7,
from include/linux/completion.h:12,
from drivers/net/can/usb/kvaser_usb/kvaser_usb_hydra.c:16:
drivers/net/can/usb/kvaser_usb/kvaser_usb_hydra.c: In function 'kvaser_usb_hydra_set_bittiming':
>> drivers/net/can/usb/kvaser_usb/kvaser_usb_hydra.c:489:65: warning: array subscript 'struct kvaser_cmd_ext[0]' is partly outside array bounds of 'unsigned char[32]' [-Warray-bounds]
489 | ret = le16_to_cpu(((struct kvaser_cmd_ext *)cmd)->len);
include/uapi/linux/byteorder/little_endian.h:37:51: note: in definition of macro '__le16_to_cpu'
37 | #define __le16_to_cpu(x) ((__force __u16)(__le16)(x))
| ^
drivers/net/can/usb/kvaser_usb/kvaser_usb_hydra.c:489:23: note: in expansion of macro 'le16_to_cpu'
489 | ret = le16_to_cpu(((struct kvaser_cmd_ext *)cmd)->len);
| ^~~~~~~~~~~
drivers/net/can/usb/kvaser_usb/kvaser_usb_hydra.c:1536:15: note: referencing an object of size 32 allocated by 'kzalloc'
1536 | cmd = kzalloc(sizeof(*cmd), GFP_KERNEL);
| ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
In file included from include/linux/byteorder/little_endian.h:5,
from arch/x86/include/uapi/asm/byteorder.h:5,
from include/asm-generic/bitops/le.h:6,
from arch/x86/include/asm/bitops.h:416,
from include/linux/bitops.h:68,
from include/linux/kernel.h:22,
from arch/x86/include/asm/percpu.h:27,
from arch/x86/include/asm/preempt.h:6,
from include/linux/preempt.h:78,
from include/linux/spinlock.h:55,
from include/linux/swait.h:7,
from include/linux/completion.h:12,
from drivers/net/can/usb/kvaser_usb/kvaser_usb_hydra.c:16:
drivers/net/can/usb/kvaser_usb/kvaser_usb_hydra.c: In function 'kvaser_usb_hydra_get_single_capability':
>> drivers/net/can/usb/kvaser_usb/kvaser_usb_hydra.c:489:65: warning: array subscript 'struct kvaser_cmd_ext[0]' is partly outside array bounds of 'unsigned char[32]' [-Warray-bounds]
489 | ret = le16_to_cpu(((struct kvaser_cmd_ext *)cmd)->len);
include/uapi/linux/byteorder/little_endian.h:37:51: note: in definition of macro '__le16_to_cpu'
37 | #define __le16_to_cpu(x) ((__force __u16)(__le16)(x))
| ^
drivers/net/can/usb/kvaser_usb/kvaser_usb_hydra.c:489:23: note: in expansion of macro 'le16_to_cpu'
489 | ret = le16_to_cpu(((struct kvaser_cmd_ext *)cmd)->len);
| ^~~~~~~~~~~
drivers/net/can/usb/kvaser_usb/kvaser_usb_hydra.c:738:15: note: referencing an object of size 32 allocated by 'kzalloc'
738 | cmd = kzalloc(sizeof(*cmd), GFP_KERNEL);
| ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
In file included from include/linux/byteorder/little_endian.h:5,
from arch/x86/include/uapi/asm/byteorder.h:5,
from include/asm-generic/bitops/le.h:6,
from arch/x86/include/asm/bitops.h:416,
from include/linux/bitops.h:68,
from include/linux/kernel.h:22,
from arch/x86/include/asm/percpu.h:27,
from arch/x86/include/asm/preempt.h:6,
from include/linux/preempt.h:78,
from include/linux/spinlock.h:55,
from include/linux/swait.h:7,
from include/linux/completion.h:12,
from drivers/net/can/usb/kvaser_usb/kvaser_usb_hydra.c:16:
drivers/net/can/usb/kvaser_usb/kvaser_usb_hydra.c: In function 'kvaser_usb_hydra_get_software_details':
>> drivers/net/can/usb/kvaser_usb/kvaser_usb_hydra.c:489:65: warning: array subscript 'struct kvaser_cmd_ext[0]' is partly outside array bounds of 'unsigned char[32]' [-Warray-bounds]
489 | ret = le16_to_cpu(((struct kvaser_cmd_ext *)cmd)->len);
include/uapi/linux/byteorder/little_endian.h:37:51: note: in definition of macro '__le16_to_cpu'
37 | #define __le16_to_cpu(x) ((__force __u16)(__le16)(x))
| ^
drivers/net/can/usb/kvaser_usb/kvaser_usb_hydra.c:489:23: note: in expansion of macro 'le16_to_cpu'
489 | ret = le16_to_cpu(((struct kvaser_cmd_ext *)cmd)->len);
| ^~~~~~~~~~~
drivers/net/can/usb/kvaser_usb/kvaser_usb_hydra.c:1714:15: note: referencing an object of size 32 allocated by 'kzalloc'
1714 | cmd = kzalloc(sizeof(*cmd), GFP_KERNEL);
| ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
In file included from include/linux/byteorder/little_endian.h:5,
from arch/x86/include/uapi/asm/byteorder.h:5,
from include/asm-generic/bitops/le.h:6,
from arch/x86/include/asm/bitops.h:416,
from include/linux/bitops.h:68,
from include/linux/kernel.h:22,
from arch/x86/include/asm/percpu.h:27,
from arch/x86/include/asm/preempt.h:6,
from include/linux/preempt.h:78,
from include/linux/spinlock.h:55,
from include/linux/swait.h:7,
from include/linux/completion.h:12,
from drivers/net/can/usb/kvaser_usb/kvaser_usb_hydra.c:16:
drivers/net/can/usb/kvaser_usb/kvaser_usb_hydra.c: In function 'kvaser_usb_hydra_send_simple_cmd_async.constprop.isra':
>> drivers/net/can/usb/kvaser_usb/kvaser_usb_hydra.c:489:65: warning: array subscript 'struct kvaser_cmd_ext[0]' is partly outside array bounds of 'unsigned char[32]' [-Warray-bounds]
489 | ret = le16_to_cpu(((struct kvaser_cmd_ext *)cmd)->len);
include/uapi/linux/byteorder/little_endian.h:37:51: note: in definition of macro '__le16_to_cpu'
37 | #define __le16_to_cpu(x) ((__force __u16)(__le16)(x))
| ^
drivers/net/can/usb/kvaser_usb/kvaser_usb_hydra.c:489:23: note: in expansion of macro 'le16_to_cpu'
489 | ret = le16_to_cpu(((struct kvaser_cmd_ext *)cmd)->len);
| ^~~~~~~~~~~
drivers/net/can/usb/kvaser_usb/kvaser_usb_hydra.c:576:15: note: referencing an object of size 32 allocated by 'kzalloc'
576 | cmd = kzalloc(sizeof(*cmd), GFP_ATOMIC);
| ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~


vim +489 drivers/net/can/usb/kvaser_usb/kvaser_usb_hydra.c

aec5fb2268b700 Jimmy Assarsson 2018-07-18 483
aec5fb2268b700 Jimmy Assarsson 2018-07-18 484 static size_t kvaser_usb_hydra_cmd_size(struct kvaser_cmd *cmd)
aec5fb2268b700 Jimmy Assarsson 2018-07-18 485 {
aec5fb2268b700 Jimmy Assarsson 2018-07-18 486 size_t ret;
aec5fb2268b700 Jimmy Assarsson 2018-07-18 487
aec5fb2268b700 Jimmy Assarsson 2018-07-18 488 if (cmd->header.cmd_no == CMD_EXTENDED)
aec5fb2268b700 Jimmy Assarsson 2018-07-18 @489 ret = le16_to_cpu(((struct kvaser_cmd_ext *)cmd)->len);
aec5fb2268b700 Jimmy Assarsson 2018-07-18 490 else
aec5fb2268b700 Jimmy Assarsson 2018-07-18 491 ret = sizeof(struct kvaser_cmd);
aec5fb2268b700 Jimmy Assarsson 2018-07-18 492
aec5fb2268b700 Jimmy Assarsson 2018-07-18 493 return ret;
aec5fb2268b700 Jimmy Assarsson 2018-07-18 494 }
aec5fb2268b700 Jimmy Assarsson 2018-07-18 495

:::::: The code at line 489 was first introduced by commit
:::::: aec5fb2268b700f3c4e8481ab431eefcd33893f6 can: kvaser_usb: Add support for Kvaser USB hydra family

:::::: TO: Jimmy Assarsson <[email protected]>
:::::: CC: Marc Kleine-Budde <[email protected]>

--
0-DAY CI Kernel Test Service
https://01.org/lkp


Attachments:
(No filename) (15.02 kB)
config (181.51 kB)
Download all attachments

2022-10-31 08:53:05

by Marc Kleine-Budde

[permalink] [raw]
Subject: Re: drivers/net/can/usb/kvaser_usb/kvaser_usb_hydra.c:489:65: warning: array subscript 'struct kvaser_cmd_ext[0]' is partly outside array bounds of 'unsigned char[32]'

On 31.10.2022 07:35:36, kernel test robot wrote:
> tree: https://git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git master
> head: 30a0b95b1335e12efef89dd78518ed3e4a71a763
> commit: 00784da3e6b8c1f0e58d813272503d014de8f64b can: kvaser_usb: kvaser_usb_hydra: Use kzalloc for allocating only one element
> date: 8 weeks ago
> config: i386-randconfig-r021-20221031
> compiler: gcc-11 (Debian 11.3.0-8) 11.3.0
> reproduce (this is a W=1 build):
> # https://git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git/commit/?id=00784da3e6b8c1f0e58d813272503d014de8f64b
> git remote add linus https://git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
> git fetch --no-tags linus master
> git checkout 00784da3e6b8c1f0e58d813272503d014de8f64b
> # save the config file
> mkdir build_dir && cp config build_dir/.config
> make W=1 O=build_dir ARCH=i386 SHELL=/bin/bash
>
> If you fix the issue, kindly add following tag where applicable
> | Reported-by: kernel test robot <[email protected]>
>
> All warnings (new ones prefixed by >>):
>
> In file included from include/linux/byteorder/little_endian.h:5,
> from arch/x86/include/uapi/asm/byteorder.h:5,
> from include/asm-generic/bitops/le.h:6,
> from arch/x86/include/asm/bitops.h:416,
> from include/linux/bitops.h:68,
> from include/linux/kernel.h:22,
> from arch/x86/include/asm/percpu.h:27,
> from arch/x86/include/asm/preempt.h:6,
> from include/linux/preempt.h:78,
> from include/linux/spinlock.h:55,
> from include/linux/swait.h:7,
> from include/linux/completion.h:12,
> from drivers/net/can/usb/kvaser_usb/kvaser_usb_hydra.c:16:
> drivers/net/can/usb/kvaser_usb/kvaser_usb_hydra.c: In function 'kvaser_usb_hydra_send_simple_cmd':
> >> drivers/net/can/usb/kvaser_usb/kvaser_usb_hydra.c:489:65: warning: array subscript 'struct kvaser_cmd_ext[0]' is partly outside array bounds of 'unsigned char[32]' [-Warray-bounds]
> 489 | ret = le16_to_cpu(((struct kvaser_cmd_ext *)cmd)->len);
> include/uapi/linux/byteorder/little_endian.h:37:51: note: in definition of macro '__le16_to_cpu'
> 37 | #define __le16_to_cpu(x) ((__force __u16)(__le16)(x))
> | ^
> drivers/net/can/usb/kvaser_usb/kvaser_usb_hydra.c:489:23: note: in expansion of macro 'le16_to_cpu'
> 489 | ret = le16_to_cpu(((struct kvaser_cmd_ext *)cmd)->len);
> | ^~~~~~~~~~~
> drivers/net/can/usb/kvaser_usb/kvaser_usb_hydra.c:537:15: note: referencing an object of size 32 allocated by 'kzalloc'
> 537 | cmd = kzalloc(sizeof(*cmd), GFP_KERNEL);
> | ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

I think this is a false positive.

The commit you're building 00784da3e6b8 ("can: kvaser_usb:
kvaser_usb_hydra: Use kzalloc for allocating only one element") contains
3e88445a3a5a ("can: kvaser_usb: silence a GCC 12 -Warray-bounds
warning").

In the latter commit, the -Warray-bounds warning was disabled, as gcc-12
has some problem with it. However you're using gcc-11 (Debian 11.3.0-8)
11.3.0 here. Don't know the status of gcc-11 with regards to that
warning.

In the mean time in 26117d92d001 ("can: kvaser_usb: Remove
-Warray-bounds exception") that was removed, as gcc-13 should be fixed.

regards,
Marc

--
Pengutronix e.K. | Marc Kleine-Budde |
Embedded Linux | https://www.pengutronix.de |
Vertretung West/Dortmund | Phone: +49-231-2826-924 |
Amtsgericht Hildesheim, HRA 2686 | Fax: +49-5121-206917-5555 |


Attachments:
(No filename) (3.85 kB)
signature.asc (499.00 B)
Download all attachments