[<prev] [next>] [<thread-prev] [thread-next>] [day] [month] [year] [list]
Message-Id: <20171219191412.14880-2-andriy.shevchenko@linux.intel.com>
Date: Tue, 19 Dec 2017 21:14:10 +0200
From: Andy Shevchenko <andriy.shevchenko@...ux.intel.com>
To: "David S. Miller" <davem@...emloft.net>, netdev@...r.kernel.org,
Larry Finger <Larry.Finger@...inger.net>,
Florian Schilhabel <florian.c.schilhabel@...glemail.com>,
devel@...verdev.osuosl.org,
Greg Kroah-Hartman <gregkh@...uxfoundation.org>
Cc: Andy Shevchenko <andriy.shevchenko@...ux.intel.com>
Subject: [PATCH v1 2/4] lib/net_utils: Introduce mac_pton_from_user()
Some drivers are getting MAC from user space. Make a helper for them.
Signed-off-by: Andy Shevchenko <andriy.shevchenko@...ux.intel.com>
---
include/linux/kernel.h | 1 +
lib/net_utils.c | 12 ++++++++++++
2 files changed, 13 insertions(+)
diff --git a/include/linux/kernel.h b/include/linux/kernel.h
index ce51455e2adf..e203b313608d 100644
--- a/include/linux/kernel.h
+++ b/include/linux/kernel.h
@@ -587,6 +587,7 @@ extern int __must_check hex2bin(u8 *dst, const char *src, size_t count);
extern char *bin2hex(char *dst, const void *src, size_t count);
bool mac_pton(const char *s, u8 *mac);
+int __must_check mac_pton_from_user(const char __user *s, size_t count, u8 *mac);
/*
* General tracing related utility functions - trace_printk(),
diff --git a/lib/net_utils.c b/lib/net_utils.c
index d32c6961fe0f..7be3483aece6 100644
--- a/lib/net_utils.c
+++ b/lib/net_utils.c
@@ -3,6 +3,7 @@
#include <linux/if_ether.h>
#include <linux/ctype.h>
#include <linux/kernel.h>
+#include <linux/uaccess.h>
#define MAC_PTON_MINLEN (3 * ETH_ALEN - 1)
@@ -27,3 +28,14 @@ bool mac_pton(const char *s, u8 *mac)
return true;
}
EXPORT_SYMBOL(mac_pton);
+
+int mac_pton_from_user(const char __user *s, size_t count, u8 *mac)
+{
+ char buf[MAC_PTON_MINLEN];
+
+ count = min(count, sizeof(buf));
+ if (copy_from_user(buf, s, count))
+ return -EFAULT;
+ return mac_pton(buf, mac) ? 0 : -EINVAL;
+}
+EXPORT_SYMBOL(mac_pton_from_user);
--
2.15.1
Powered by blists - more mailing lists