All of lore.kernel.org
 help / color / mirror / Atom feed
* [PATCH] HID: hid-lg4ff: Add check for empty lbuf
@ 2022-11-11 12:55 Anastasia Belova
  2022-11-14 22:57 ` Jiri Kosina
  0 siblings, 1 reply; 2+ messages in thread
From: Anastasia Belova @ 2022-11-11 12:55 UTC (permalink / raw)
  To: Jiri Kosina
  Cc: Anastasia Belova, Benjamin Tissoires, Michal Malý,
	linux-input, linux-kernel, lvc-project

If an empty buf is received, lbuf is also empty. So lbuf is 
accessed by index -1.

Found by Linux Verification Center (linuxtesting.org) with SVACE.

Fixes: f31a2de3fe36 ("HID: hid-lg4ff: Allow switching of Logitech gaming wheels between compatibility modes")

Signed-off-by: Anastasia Belova <abelova@astralinux.ru>
---
 drivers/hid/hid-lg4ff.c | 6 ++++++
 1 file changed, 6 insertions(+)

diff --git a/drivers/hid/hid-lg4ff.c b/drivers/hid/hid-lg4ff.c
index 5e6a0cef2a06..e3fcf1353fb3 100644
--- a/drivers/hid/hid-lg4ff.c
+++ b/drivers/hid/hid-lg4ff.c
@@ -872,6 +872,12 @@ static ssize_t lg4ff_alternate_modes_store(struct device *dev, struct device_att
 		return -ENOMEM;
 
 	i = strlen(lbuf);
+
+	if (i == 0) {
+		kfree(lbuf);
+		return -EINVAL;
+	}
+
 	if (lbuf[i-1] == '\n') {
 		if (i == 1) {
 			kfree(lbuf);
-- 
2.30.2


^ permalink raw reply related	[flat|nested] 2+ messages in thread

* Re: [PATCH] HID: hid-lg4ff: Add check for empty lbuf
  2022-11-11 12:55 [PATCH] HID: hid-lg4ff: Add check for empty lbuf Anastasia Belova
@ 2022-11-14 22:57 ` Jiri Kosina
  0 siblings, 0 replies; 2+ messages in thread
From: Jiri Kosina @ 2022-11-14 22:57 UTC (permalink / raw)
  To: Anastasia Belova
  Cc: Benjamin Tissoires, Michal Malý,
	linux-input, linux-kernel, lvc-project

On Fri, 11 Nov 2022, Anastasia Belova wrote:

> If an empty buf is received, lbuf is also empty. So lbuf is 
> accessed by index -1.

Good catch, thanks!

> Found by Linux Verification Center (linuxtesting.org) with SVACE.
> 
> Fixes: f31a2de3fe36 ("HID: hid-lg4ff: Allow switching of Logitech gaming wheels between compatibility modes")
> 
> Signed-off-by: Anastasia Belova <abelova@astralinux.ru>

I've put the Fixes: line into the SOB/metadata space, and applied. Thank 
you,

-- 
Jiri Kosina
SUSE Labs


^ permalink raw reply	[flat|nested] 2+ messages in thread

end of thread, other threads:[~2022-11-14 22:58 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2022-11-11 12:55 [PATCH] HID: hid-lg4ff: Add check for empty lbuf Anastasia Belova
2022-11-14 22:57 ` Jiri Kosina

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.