From: Dan Carpenter <hidden> Date: 2021-08-16 09:26:37
The bounds check on "index" doesn't catch negative values. Using
ARRAY_SIZE() directly is more readable and more robust because it prevents
negative values for "index". Fortunately we only pass valid values to
ipc_chnl_cfg_get() so this patch does not affect runtime.
Reported-by: Solomon Ucko <redacted>
Signed-off-by: Dan Carpenter <redacted>
---
I suspect this is bug report was based on static analysis. I had a
Smatch check that used to print a warning, but then I modified it to
only complain when the index was user controlled.
drivers/net/wwan/iosm/iosm_ipc_chnl_cfg.c | 7 +++----
1 file changed, 3 insertions(+), 4 deletions(-)
From: Kumar, M Chetan <hidden> Date: 2021-08-16 10:48:24
Hi Dan,
quoted hunk
+++ b/drivers/net/wwan/iosm/iosm_ipc_chnl_cfg.c
@@ -64,10 +64,9 @@ static struct ipc_chnl_cfg modem_cfg[] = {intipc_chnl_cfg_get(structipc_chnl_cfg*chnl_cfg,intindex){-intarray_size=ARRAY_SIZE(modem_cfg);--if(index>=array_size){-pr_err("index: %d and array_size %d",index,array_size);+if(index>=ARRAY_SIZE(modem_cfg)){+pr_err("index: %d and array_size %lu",index,
array_size is removed so please change array_size in pr_err to array size (remove _).
Also change in pr_err array size format "%lu" is throwing warning [1] in 32bit env.
[1]
from ../drivers/net/wwan/iosm/iosm_ipc_chnl_cfg.c:6:
../drivers/net/wwan/iosm/iosm_ipc_chnl_cfg.c: In function 'ipc_chnl_cfg_get':
../include/linux/kern_levels.h:5:18: warning: format '%lu' expects argument of type
'long unsigned int', but argument 3 has type 'unsigned int' [-Wformat=]
Regards,
Chetan
From: Dan Carpenter <hidden> Date: 2021-08-16 11:14:06
The bounds check on "index" doesn't catch negative values. Using
ARRAY_SIZE() directly is more readable and more robust because it prevents
negative values for "index". Fortunately we only pass valid values to
ipc_chnl_cfg_get() so this patch does not affect runtime.
Reported-by: Solomon Ucko <redacted>
Signed-off-by: Dan Carpenter <redacted>
---
v2: Remove underscore between "array" and "size".
Use %zu print format specifier to fix a compile warning on 32 bit.
drivers/net/wwan/iosm/iosm_ipc_chnl_cfg.c | 7 +++----
1 file changed, 3 insertions(+), 4 deletions(-)
From: Kumar, M Chetan <hidden> Date: 2021-08-16 12:17:28
-----Original Message-----
From: Dan Carpenter <redacted>
Sent: Monday, August 16, 2021 4:44 PM
To: Kumar, M Chetan <redacted>; Solomon Ucko
[off-list ref]
Cc: linuxwwan <redacted>; Loic Poulain
[off-list ref]; Sergey Ryazanov [off-list ref];
Johannes Berg [off-list ref]; David S. Miller
[off-list ref]; Jakub Kicinski [off-list ref];
netdev@vger.kernel.org; security@kernel.org
Subject: [PATCH v2 net] net: iosm: Prevent underflow in ipc_chnl_cfg_get()
The bounds check on "index" doesn't catch negative values. Using
ARRAY_SIZE() directly is more readable and more robust because it prevents
negative values for "index". Fortunately we only pass valid values to
ipc_chnl_cfg_get() so this patch does not affect runtime.
Reported-by: Solomon Ucko <redacted>
Signed-off-by: Dan Carpenter <redacted>
---
v2: Remove underscore between "array" and "size".
Use %zu print format specifier to fix a compile warning on 32 bit.
drivers/net/wwan/iosm/iosm_ipc_chnl_cfg.c | 7 +++----
1 file changed, 3 insertions(+), 4 deletions(-)
Hello:
This patch was applied to netdev/net.git (refs/heads/master):
On Mon, 16 Aug 2021 14:13:33 +0300 you wrote:
The bounds check on "index" doesn't catch negative values. Using
ARRAY_SIZE() directly is more readable and more robust because it prevents
negative values for "index". Fortunately we only pass valid values to
ipc_chnl_cfg_get() so this patch does not affect runtime.
Reported-by: Solomon Ucko <redacted>
Signed-off-by: Dan Carpenter <redacted>
[...]