public inbox for linux-kernel@vger.kernel.org
 help / color / mirror / Atom feed
* [PATCH v1] drivers:testing:Handle possible memory leaks
@ 2024-08-22  3:21 Yang Ruibin
  2024-08-24 19:28 ` kernel test robot
  2024-08-24 22:01 ` kernel test robot
  0 siblings, 2 replies; 5+ messages in thread
From: Yang Ruibin @ 2024-08-22  3:21 UTC (permalink / raw)
  To: Rafael J. Wysocki, Daniel Lezcano, Zhang Rui, Lukasz Luba,
	Stephen Rothwell, Yang Ruibin, linux-pm, linux-kernel
  Cc: opensource.kernel

When copy_from_user() fails, -EFAULT is returned without
releasing the memory previously allocated by kmalloc().

Signed-off-by: Yang Ruibin <11162571@vivo.com>
---
 drivers/thermal/testing/command.c | 1 +
 1 file changed, 1 insertion(+)

diff --git a/drivers/thermal/testing/command.c b/drivers/thermal/testing/command.c
index 6771eb7b1..7868caee3 100644
--- a/drivers/thermal/testing/command.c
+++ b/drivers/thermal/testing/command.c
@@ -151,6 +151,7 @@ static ssize_t tt_command_process(struct dentry *dentry, const char __user *user
 		return -ENOMEM;
 
 	if (copy_from_user(buf, user_buf, count))
+		kfree(buf);
 		return -EFAULT;
 
 	buf[count] = '\0';
-- 
2.34.1


^ permalink raw reply related	[flat|nested] 5+ messages in thread
* [PATCH v1] drivers:testing:Handle possible memory leaks
@ 2024-08-22  3:39 Yang Ruibin
  2024-08-22 18:52 ` Rafael J. Wysocki
  0 siblings, 1 reply; 5+ messages in thread
From: Yang Ruibin @ 2024-08-22  3:39 UTC (permalink / raw)
  To: Rafael J. Wysocki, Daniel Lezcano, Zhang Rui, Lukasz Luba,
	Yang Ruibin, Stephen Rothwell, linux-pm, linux-kernel
  Cc: opensource.kernel

When copy_from_user() fails, -EFAULT is returned without
releasing the memory previously allocated by kmalloc().

Signed-off-by: Yang Ruibin <11162571@vivo.com>
---
 drivers/thermal/testing/command.c | 3 ++-
 1 file changed, 2 insertions(+), 1 deletion(-)

diff --git a/drivers/thermal/testing/command.c b/drivers/thermal/testing/command.c
index 7868caee3..b95bcb94e 100644
--- a/drivers/thermal/testing/command.c
+++ b/drivers/thermal/testing/command.c
@@ -150,9 +150,10 @@ static ssize_t tt_command_process(struct dentry *dentry, const char __user *user
 	if (!buf)
 		return -ENOMEM;
 
-	if (copy_from_user(buf, user_buf, count))
+	if (copy_from_user(buf, user_buf, count)) {
+		kfree(buf);
 		return -EFAULT;
+	}
 
 	buf[count] = '\0';
 	strim(buf);
-- 
2.34.1


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

end of thread, other threads:[~2024-08-24 22:02 UTC | newest]

Thread overview: 5+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2024-08-22  3:21 [PATCH v1] drivers:testing:Handle possible memory leaks Yang Ruibin
2024-08-24 19:28 ` kernel test robot
2024-08-24 22:01 ` kernel test robot
  -- strict thread matches above, loose matches on Subject: below --
2024-08-22  3:39 Yang Ruibin
2024-08-22 18:52 ` Rafael J. Wysocki

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox