All of lore.kernel.org
 help / color / mirror / Atom feed
* [lustre-devel] [PATCH] staging/lustre: Use proper number of bytes in copy_from_user
@ 2016-11-21  5:46 ` Oleg Drokin
  0 siblings, 0 replies; 4+ messages in thread
From: Oleg Drokin @ 2016-11-21  5:46 UTC (permalink / raw)
  To: Greg Kroah-Hartman, devel, Andreas Dilger, James Simmons
  Cc: Linux Kernel Mailing List, Lustre Development List, Jian Yu,
	Oleg Drokin

From: Jian Yu <jian.yu@intel.com>

This patch removes the usage of MAX_STRING_SIZE from
copy_from_user() and just copies enough bytes to cover
count passed in.

Signed-off-by: Jian Yu <jian.yu@intel.com>
Reviewed-on: http://review.whamcloud.com/23462
Intel-bug-id: https://jira.hpdd.intel.com/browse/LU-8774
Reviewed-by: John L. Hammond <john.hammond@intel.com>
Signed-off-by: Oleg Drokin <green@linuxhacker.ru>
---
 drivers/staging/lustre/lustre/obdclass/lprocfs_status.c | 11 +++++++++--
 1 file changed, 9 insertions(+), 2 deletions(-)

diff --git a/drivers/staging/lustre/lustre/obdclass/lprocfs_status.c b/drivers/staging/lustre/lustre/obdclass/lprocfs_status.c
index 8a2f02f3..db49992 100644
--- a/drivers/staging/lustre/lustre/obdclass/lprocfs_status.c
+++ b/drivers/staging/lustre/lustre/obdclass/lprocfs_status.c
@@ -400,10 +400,17 @@ int lprocfs_wr_uint(struct file *file, const char __user *buffer,
 	char dummy[MAX_STRING_SIZE + 1], *end;
 	unsigned long tmp;
 
-	dummy[MAX_STRING_SIZE] = '\0';
-	if (copy_from_user(dummy, buffer, MAX_STRING_SIZE))
+	if (count >= sizeof(dummy))
+		return -EINVAL;
+
+	if (count == 0)
+		return 0;
+
+	if (copy_from_user(dummy, buffer, count))
 		return -EFAULT;
 
+	dummy[count] = '\0';
+
 	tmp = simple_strtoul(dummy, &end, 0);
 	if (dummy == end)
 		return -EINVAL;
-- 
2.7.4

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

end of thread, other threads:[~2016-11-21 10:14 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2016-11-21  5:46 [lustre-devel] [PATCH] staging/lustre: Use proper number of bytes in copy_from_user Oleg Drokin
2016-11-21  5:46 ` Oleg Drokin
2016-11-21 10:14 ` [lustre-devel] " Greg Kroah-Hartman
2016-11-21 10:14   ` Greg Kroah-Hartman

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.