Skip to contentSkip to conversation

x86/mtrr: Convert to use strncpy_from_user() helper

PATCH New Andy Shevchenko 2 participants 2 messages May 15, 2018 – May 16, 2018 x86

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 x86/mtrr: Convert to use strncpy_from_user() helper

Replace the open coded string fetch from the user.

---
 arch/x86/kernel/cpu/mtrr/if.c | 12 ++----------
 1 file changed, 2 insertions(+), 10 deletions(-)
arch/x86/kernel/cpu/mtrr/if.c +2 -10
index e4adad68b5e5..3cbae60663fa 100644
@@ -105,17 +105,9 @@ mtrr_write(struct file *file, const char __user *buf, size_t len, loff_t * ppos)
 
 	memset(line, 0, LINE_SIZE);
 
-	length = len;
-	length--;
-
-	if (length > LINE_SIZE - 1)
-		length = LINE_SIZE - 1;
-
+	length = strncpy_from_user(line, buf, LINE_SIZE - 1);
 	if (length < 0)
-		return -EINVAL;
-
-	if (copy_from_user(line, buf, length))
-		return -EFAULT;
+		return length;
 
 	strim(line);
 
Signature · 1 line
2.17.0
#1 lore raw
x86/mtrr: Convert to use strncpy_from_user() helper
Commit-ID:  7f8ec5a4f01aa7d03e94a3d99d7b5f9c02d7fe5a
Gitweb:     https://git.kernel.org/tip/7f8ec5a4f01aa7d03e94a3d99d7b5f9c02d7fe5a
Author:     Andy Shevchenko <[email protected]>
AuthorDate: Tue, 15 May 2018 21:05:35 +0300
Committer:  Ingo Molnar <[email protected]>
CommitDate: Wed, 16 May 2018 09:47:23 +0200

x86/mtrr: Convert to use strncpy_from_user() helper

Replace the open coded string fetch from user-space with strncpy_from_user().

Cc Andrew Morton <[email protected]>
Cc Andy Lutomirski <[email protected]>
Cc Borislav Petkov <[email protected]>
Cc Brian Gerst <[email protected]>
Cc Denys Vlasenko <[email protected]>
Cc H. Peter Anvin <[email protected]>
Cc Josh Poimboeuf <[email protected]>
Cc Linus Torvalds <[email protected]>
Cc Luis R. Rodriguez <[email protected]>
Cc Peter Zijlstra <[email protected]>
Cc Thomas Gleixner <[email protected]>
Cc Toshi Kani <[email protected]>
---
 arch/x86/kernel/cpu/mtrr/if.c | 12 ++----------
 1 file changed, 2 insertions(+), 10 deletions(-)
arch/x86/kernel/cpu/mtrr/if.c +2 -10
index 42b4f2f3b557..c610f47373e4 100644
@@ -106,17 +106,9 @@ mtrr_write(struct file *file, const char __user *buf, size_t len, loff_t * ppos)
 
 	memset(line, 0, LINE_SIZE);
 
-	length = len;
-	length--;
-
-	if (length > LINE_SIZE - 1)
-		length = LINE_SIZE - 1;
-
+	length = strncpy_from_user(line, buf, LINE_SIZE - 1);
 	if (length < 0)
-		return -EINVAL;
-
-	if (copy_from_user(line, buf, length))
-		return -EFAULT;
+		return length;
 
 	linelen = strlen(line);
 	ptr = line + linelen - 1;