device-drivers/uaccess: add a workaround for Intel's SMAP feature
PATCH 1/1 device-drivers/uaccess: add a workaround for Intel's SMAP feature
When Intel's new "Supervisor Mode Access Prevention" (SMAP) feature is enabled, kernel will be forbidden to visit user space memory, please see url: https://lwn.net/Articles/517475/ for detailed infomation.
Here, we explicitly call stac()/clac() to enable/disable SMAP feature.
--- testcases/kernel/device-drivers/uaccess/ltp_uaccess.c | 8 ++++++++ 1 file changed, 8 insertions(+)
testcases/kernel/device-drivers/uaccess/ltp_uaccess.c +8 -0
@@ -68,6 +68,9 @@ static ssize_t sys_tcase(struct device *dev, str = (char *) ptr; test_result =0 ; +#ifdef CONFIG_X86_SMAP +stac (); +#endif switch (tc) {case TC_READ_USER :if (copy_from_user (buffer, str, str_size))
@@ -90,6 +93,11 @@ static ssize_t sys_tcase(struct device *dev,break ; } +#ifdef CONFIG_X86_SMAP +clac (); +#endif + +return count; } static DEVICE_ATTR(tcase, S_IWUSR, NULL, sys_tcase);
Signature · 1 line
1.8.3.1
PATCH 1/1 device-drivers/uaccess: add a workaround for Intel's SMAP feature
hello,
Sorry, I do not have a machine with this SMAP feature, anybody can help to test this patch, thanks very much.
Regards,
Xiaoguang Wang
Quoted 38 lines · Xiaoguang Wang
When Intel's new "Supervisor Mode Access Prevention" (SMAP) feature is enabled, kernel will be forbidden to visit user space memory, please see url: https://lwn.net/Articles/517475/ for detailed infomation.
Here, we explicitly call stac()/clac() to enable/disable SMAP feature.
Signed-off-by Xiaoguang Wang <[email protected]>--- testcases/kernel/device-drivers/uaccess/ltp_uaccess.c | 8 ++++++++ 1 file changed, 8 insertions(+)testcases/kernel/device-drivers/uaccess/ltp_uaccess.c +8
-0@@ -68,6 +68,9 @@ static ssize_t sys_tcase(struct device *dev, str = (char *) ptr; test_result =0 ; +#ifdef CONFIG_X86_SMAP +stac (); +#endif switch (tc) {case TC_READ_USER :if (copy_from_user (buffer, str, str_size))@@ -90,6 +93,11 @@ static ssize_t sys_tcase(struct device *dev,break ; } +#ifdef CONFIG_X86_SMAP +clac (); +#endif + +return count; } static DEVICE_ATTR(tcase, S_IWUSR, NULL, sys_tcase);
PATCH 1/1 device-drivers/uaccess: add a workaround for Intel's SMAP feature
Hi,
Quoted 38 lines · Xiaoguang Wang
hello,
Sorry, I do not have a machine with this SMAP feature, anybody can help to test this patch, thanks very much.
Regards,
Xiaoguang WangQuoted 29 lines · Xiaoguang Wang
When Intel's new "Supervisor Mode Access Prevention" (SMAP) feature is enabled, kernel will be forbidden to visit user space memory, please see url: https://lwn.net/Articles/517475/ for detailed infomation.
Here, we explicitly call stac()/clac() to enable/disable SMAP feature.
Signed-off-by Xiaoguang Wang <[email protected]>--- testcases/kernel/device-drivers/uaccess/ltp_uaccess.c | 8 ++++++++ 1 file changed, 8 insertions(+)testcases/kernel/device-drivers/uaccess/ltp_uaccess.c +3
-0@@ -68,6 +68,9 @@ static ssize_t sys_tcase(struct device *dev, str = (char *) ptr; test_result =0 ; +#ifdef CONFIG_X86_SMAP +stac (); +#endif switch (tc) {case TC_READ_USER :if (copy_from_user (buffer, str, str_size))@@ -90,6 +93,11 @@ static ssize_t sys_tcase(struct device *dev,break ; }
Quoted 3 lines
testcases/kernel/device-drivers/uaccess/ltp_uaccess.c static ssize_t sys_tcase(struct device *dev, · line 98
Quoted 3 lines
testcases/kernel/device-drivers/uaccess/ltp_uaccess.c +3
-0+#ifdef CONFIG_X86_SMAP +clac (); +#endif
copy_from_user() and others have stac() / clac() already. Are you sure we need to invoke them there again?
Thanks,
Alexey
PATCH 1/1 device-drivers/uaccess: add a workaround for Intel's SMAP feature
Quoted 22 lines · Alexey Kodanev
Hi,
Quoted 20 lines · Xiaoguang Wang
hello,
Sorry, I do not have a machine with this SMAP feature, anybody can help to test this patch, thanks very much.
Regards,
Xiaoguang WangQuoted 11 lines · Xiaoguang Wang
When Intel's new "Supervisor Mode Access Prevention" (SMAP) feature is enabled, kernel will be forbidden to visit user space memory, please see url: https://lwn.net/Articles/517475/ for detailed infomation.
Here, we explicitly call stac()/clac() to enable/disable SMAP feature.
Signed-off-by Xiaoguang Wang <[email protected]>---
testcases/kernel/device-drivers/uaccess/ltp_uaccess.c| 8 ++++++++1 file changed, 8 insertions(+)
Quoted 11 lines
Quoted 11 lines
testcases/kernel/device-drivers/uaccess/ltp_uaccess.c static ssize_t sys_tcase(struct device *dev, · line 72
Quoted 11 lines
testcases/kernel/device-drivers/uaccess/ltp_uaccess.c +2
-0@@ -68,6 +68,9 @@ static ssize_t sys_tcase(struct device *dev, str = (char *) ptr; test_result =0 ; +#ifdef CONFIG_X86_SMAP +stac (); +#endif
Also you don't need ifdefs as smap.h has a check:
...
#else /* CONFIG_X86_SMAP */
static inline void clac(void) { }
static inline void stac(void) { }
...
Quoted 19 lines
Quoted 10 lines
testcases/kernel/device-drivers/uaccess/ltp_uaccess.c static ssize_t sys_tcase(struct device *dev, · line 97
Quoted 10 lines
testcases/kernel/device-drivers/uaccess/ltp_uaccess.c +2
-0switch (tc) {case TC_READ_USER :if (copy_from_user (buffer, str, str_size))@@ -90,6 +93,11 @@ static ssize_t sys_tcase(struct device *dev,break ; } +#ifdef CONFIG_X86_SMAP +clac (); +#endif
copy_from_user()and others havestac()/clac()already. Are you sure we need to invoke them there again?Thanks,
Alexey