* wli1271: buffer overflow static checker warning
@ 2014-11-07 10:05 Dan Carpenter
2014-11-07 10:11 ` Luca Coelho
2014-11-10 7:25 ` [PATCH] wlcore: check minimum buffer size in some cmd_send functions Luca Coelho
0 siblings, 2 replies; 3+ messages in thread
From: Dan Carpenter @ 2014-11-07 10:05 UTC (permalink / raw)
To: Luciano Coelho; +Cc: linux-wireless
Hello Luciano Coelho,
The patch f5fc0f86b02a: "wl1271: add wl1271 driver files" from Aug 6,
2009, leads to the following static checker warning:
drivers/net/wireless/ti/wlcore/cmd.c:894 wlcore_cmd_configure_failsafe()
warn: is 'buf' large enough for 'struct acx_header'?
drivers/net/wireless/ti/wlcore/cmd.c
886 int wlcore_cmd_configure_failsafe(struct wl1271 *wl, u16 id, void *buf,
887 size_t len, unsigned long valid_rets)
888 {
889 struct acx_header *acx = buf;
890 int ret;
891
892 wl1271_debug(DEBUG_CMD, "cmd configure (%d)", id);
893
894 acx->id = cpu_to_le16(id);
"len" is the size of the "buf" buffer.
The warning is because wl1271_tm_cmd_test() and friends check if
len is too large but they don't check if it's too small.
895
896 /* payload length, does not include any headers */
897 acx->len = cpu_to_le16(len - sizeof(*acx));
898
899 ret = wlcore_cmd_send_failsafe(wl, CMD_CONFIGURE, acx, len, 0,
900 valid_rets);
901 if (ret < 0) {
902 wl1271_warning("CONFIGURE command NOK");
903 return ret;
904 }
905
906 return ret;
907 }
See also:
drivers/net/wireless/ti/wl1251/cmd.c:29 wl1251_cmd_send()
warn: is 'buf' large enough for 'struct wl1251_cmd_header'?
regards,
dan carpenter
^ permalink raw reply [flat|nested] 3+ messages in thread* Re: wli1271: buffer overflow static checker warning
2014-11-07 10:05 wli1271: buffer overflow static checker warning Dan Carpenter
@ 2014-11-07 10:11 ` Luca Coelho
2014-11-10 7:25 ` [PATCH] wlcore: check minimum buffer size in some cmd_send functions Luca Coelho
1 sibling, 0 replies; 3+ messages in thread
From: Luca Coelho @ 2014-11-07 10:11 UTC (permalink / raw)
To: Dan Carpenter, Luciano Coelho; +Cc: linux-wireless
On November 7, 2014 12:05:43 PM EET, Dan Carpenter <dan.carpenter@oracle.com> wrote:
>Hello Luciano Coelho,
>
>The patch f5fc0f86b02a: "wl1271: add wl1271 driver files" from Aug 6,
>2009, leads to the following static checker warning:
2009?! :)
Does this code even still exist? :P
^ permalink raw reply [flat|nested] 3+ messages in thread
* [PATCH] wlcore: check minimum buffer size in some cmd_send functions
2014-11-07 10:05 wli1271: buffer overflow static checker warning Dan Carpenter
2014-11-07 10:11 ` Luca Coelho
@ 2014-11-10 7:25 ` Luca Coelho
1 sibling, 0 replies; 3+ messages in thread
From: Luca Coelho @ 2014-11-10 7:25 UTC (permalink / raw)
To: linux-wireless; +Cc: dan.carpenter
From: Luciano Coelho <luciano.coelho@intel.com>
Check for the minimum required buffer length in wlcore_cmd_send() and
wlcore_cmd_configure_failsafe. This ensures that we will never try to
use a buffer that is smaller than the required header.
Reported-by: Dan Carpenter <dan.carpenter@oracle.com>
Signed-off-by: Luciano Coelho <luciano.coelho@intel.com>
---
NOTE: this is only compile-tested.
drivers/net/wireless/ti/wlcore/cmd.c | 6 ++++++
1 file changed, 6 insertions(+)
diff --git a/drivers/net/wireless/ti/wlcore/cmd.c b/drivers/net/wireless/ti/wlcore/cmd.c
index 05604ee..5c6f3c8 100644
--- a/drivers/net/wireless/ti/wlcore/cmd.c
+++ b/drivers/net/wireless/ti/wlcore/cmd.c
@@ -64,6 +64,9 @@ static int __wlcore_cmd_send(struct wl1271 *wl, u16 id, void *buf,
id != CMD_STOP_FWLOGGER))
return -EIO;
+ if (WARN_ON_ONCE(len < sizeof(*cmd)))
+ return -EIO;
+
cmd = buf;
cmd->id = cpu_to_le16(id);
cmd->status = 0;
@@ -891,6 +894,9 @@ int wlcore_cmd_configure_failsafe(struct wl1271 *wl, u16 id, void *buf,
wl1271_debug(DEBUG_CMD, "cmd configure (%d)", id);
+ if (WARN_ON_ONCE(len < sizeof(*acx)))
+ return -EIO;
+
acx->id = cpu_to_le16(id);
/* payload length, does not include any headers */
--
2.1.1
^ permalink raw reply related [flat|nested] 3+ messages in thread
end of thread, other threads:[~2014-11-10 7:25 UTC | newest]
Thread overview: 3+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2014-11-07 10:05 wli1271: buffer overflow static checker warning Dan Carpenter
2014-11-07 10:11 ` Luca Coelho
2014-11-10 7:25 ` [PATCH] wlcore: check minimum buffer size in some cmd_send functions Luca Coelho
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).