ldt.h: Add workaround for x86_64
PATCH v3 1/1 ldt.h: Add workaround for x86_64
From: Ricardo B. Marlière <[email protected]>
The commit be0aaca2f742 ("syscalls/modify_ldt: Add lapi/ldt.h") left behind an important factor of modify_ldt(): the kernel intentionally casts the return value to unsigned int. This was handled in testcases/cve/cve-2015-3290.c but was removed. Add it back to the relevant file.
---
Changes in v3:
- EDITME: describe what is new in this series revision.
- EDITME: use bulletpoints and terse descriptions.
- Link to v2: https://lore.kernel.org/r/[email protected]
Changes in v2:
- Added TBROK for any ret != 0 in modify_ldt call in cve-2015-3290.c
- Link to v1: https://lore.kernel.org/r/[email protected]
--- include/lapi/ldt.h | 30 +++++++++++++++++++++++++++++- 1 file changed, 29 insertions(+), 1 deletion(-)
include/lapi/ldt.h +29 -1
@@ -31,7 +31,27 @@ struct user_desc {static inline int modify_ldt (int func,const struct user_desc *ptr,unsigned long bytecount) { -return tst_syscall (__NR_modify_ldt, func, ptr, bytecount); +long rval; + + errno =0 ; + rval =tst_syscall (__NR_modify_ldt, func, ptr, bytecount); + +#ifdef __x86_64__ +/* +* The kernel intentionally casts modify_ldt() return value +* to unsigned int to prevent sign extension to 64 bits. This may +* result in syscall() returning the value as is instead of setting +* errno and returning -1. +*/ +if (rval >0 && (int )rval <0 ) { +tst_res (TINFO , +"WARNING: Libc mishandled modify_ldt() return value" ); + errno = -(int )errno; + rval =-1 ; + } +#endif /* __x86_64__ */ + +return rval; } static inline int safe_modify_ldt(const char *file, const int lineno, int func,
@@ -40,7 +60,15 @@ static inline int safe_modify_ldt(const char *file, const int lineno, int func, {int rval; + errno =0 ; rval =modify_ldt (func, ptr, bytecount); +#ifdef __x86_64__ +if (rval ==-1 && errno ==EINVAL ) { +tst_brk_ (file, lineno,TCONF |TTERRNO , +"modify_ldt(%d, %p, %lu): 16-bit data segments are probably disabled" , + func, ptr, bytecount); + } +#endif if (rval ==-1 ) {tst_brk_ (file, lineno,TBROK |TERRNO ,"modify_ldt(%d, %p, %lu)" , func, ptr, bytecount);
---
base-commit: b070a5692e035ec12c3d3c7a7e9e97c270fd4d7d
change-id: 20250507-fixes-modify_ldt-ebcfdd2a7d30
Best regards,
Signature · 5 lines
Ricardo B. Marlière <[email protected]> -- Mailing list info: https://lists.linux.it/listinfo/ltp
Quoted 8 lines · Ricardo B. Marlière
From: Ricardo B. Marlière <[email protected]>
The commit
be0aaca2f742("syscalls/modify_ldt: Addlapi/ldt.h") left behind an important factor ofmodify_ldt(): the kernel intentionally casts the return value to unsigned int. This was handled intestcases/cve/cve-2015-3290.cbut was removed. Add it back to the relevant file.
Quoted 8 lines
Reported-by Martin Doucha <[email protected]>Reviewed-by Martin Doucha <[email protected]>Signed-off-by Ricardo B. Marlière <[email protected]>---
Changes in v3:
- EDITME: describe what is new in this series revision.
- EDITME: use bulletpoints and terse descriptions.
- Link to v2: https://lore.kernel.org/r/[email protected]
Changes in v3:
- Moved the (rval == -1 && errno == EINVAL) check into safe_modify_ldt.
Signature · 1 line
Mailing list info: https://lists.linux.it/listinfo/ltp
Hi,safe_modify_ldt() should not allow any errors. Let's merge v2.
Quoted 79 lines · Ricardo B. Marlière
From: Ricardo B. Marlière <[email protected]>
The commit
be0aaca2f742("syscalls/modify_ldt: Addlapi/ldt.h") left behind an important factor ofmodify_ldt(): the kernel intentionally casts the return value to unsigned int. This was handled intestcases/cve/cve-2015-3290.cbut was removed. Add it back to the relevant file.Reported-by Martin Doucha <[email protected]>Reviewed-by Martin Doucha <[email protected]>Signed-off-by Ricardo B. Marlière <[email protected]>---
Changes in v3:
- EDITME: describe what is new in this series revision.
- EDITME: use bulletpoints and terse descriptions.
- Link to v2: https://lore.kernel.org/r/[email protected]Changes in v2:
- Added TBROK for any ret != 0 inmodify_ldtcall incve-2015-3290.c
- Link to v1: https://lore.kernel.org/r/[email protected]--- include/lapi/ldt.h | 30 +++++++++++++++++++++++++++++- 1 file changed, 29 insertions(+), 1 deletion(-)include/lapi/ldt.h +29
-2@@ -31,7 +31,27 @@ struct user_desc {static inline int modify_ldt (int func,const struct user_desc *ptr,unsigned long bytecount) { -return tst_syscall (__NR_modify_ldt, func, ptr, bytecount); +long rval; + + errno =0 ; + rval =tst_syscall (__NR_modify_ldt, func, ptr, bytecount); + +#ifdef __x86_64__ +/* +* The kernel intentionally casts modify_ldt() return value +* to unsigned int to prevent sign extension to 64 bits. This may +* result in syscall() returning the value as is instead of setting +* errno and returning -1. +*/ +if (rval >0 && (int )rval <0 ) { +tst_res (TINFO , +"WARNING: Libc mishandled modify_ldt() return value" ); + errno = -(int )errno; + rval =-1 ; + } +#endif /* __x86_64__ */ + +return rval; } static inline int safe_modify_ldt(const char *file, const int lineno, int func,@@ -40,7 +60,15 @@ static inline int safe_modify_ldt(const char *file, const int lineno, int func, {int rval; + errno =0 ; rval =modify_ldt (func, ptr, bytecount); +#ifdef __x86_64__ +if (rval ==-1 && errno ==EINVAL ) { +tst_brk_ (file, lineno,TCONF |TTERRNO , +"modify_ldt(%d, %p, %lu): 16-bit data segments are probably disabled" , + func, ptr, bytecount); + } +#endif if (rval ==-1 ) {tst_brk_ (file, lineno,TBROK |TERRNO ,"modify_ldt(%d, %p, %lu)" , func, ptr, bytecount); ---base-commit:
b070a5692e035ec12c3d3c7a7e9e97c270fd4d7d
change-id: 20250507-fixes-modify_ldt-ebcfdd2a7d30Best regards,
Signature · 10 lines
Martin Doucha [email protected] SW Quality Engineer SUSE LINUX, s.r.o. CORSO IIa Krizikova 148/34 186 00 Prague 8 Czech Republic -- Mailing list info: https://lists.linux.it/listinfo/ltp
Hi,
Quoted 2 lines · Martin Doucha
Hi,
safe_modify_ldt()should not allow any errors. Let's merge v2.
What about the other tests? This check should be applied to them as well eventually.
- Andrea
Signature · 1 line
Mailing list info: https://lists.linux.it/listinfo/ltp
Quoted 7 lines · Andrea Cervesato
Hi,
Quoted 2 lines · Martin Doucha
Hi,
safe_modify_ldt()should not allow any errors. Let's merge v2.What about the other tests? This check should be applied to them as well eventually.
That varies by testcase. If the test expects any errors from the call, it should call modify_ldt() directly and handle the return value either directly or using one of the TST_EXP helper macros.
Signature · 10 lines
Martin Doucha [email protected] SW Quality Engineer SUSE LINUX, s.r.o. CORSO IIa Krizikova 148/34 186 00 Prague 8 Czech Republic -- Mailing list info: https://lists.linux.it/listinfo/ltp
Andrea Cervesato via ltp
Acked-by Andrea CervesatoOk, merged.
Quoted 11 lines · Martin Doucha
Quoted 7 lines · Andrea Cervesato
Hi,
Quoted 2 lines · Martin Doucha
Hi,
safe_modify_ldt()should not allow any errors. Let's merge v2.What about the other tests? This check should be applied to them as well eventually.
That varies by testcase. If the test expects any errors from the call, it should call
modify_ldt()directly and handle the return value either directly or using one of theTST_EXPhelper macros.
Signature · 1 line
Mailing list info: https://lists.linux.it/listinfo/ltp
Quoted 3 lines · Andrea Cervesato
Ok, merged.
Acked-by Andrea Cervesato <[email protected]>
Thank you Andrea for the review and suggestion! :)
Quoted 16 lines · Martin Doucha
Quoted 14 lines · Andrea Cervesato
Quoted 8 lines
Hi,
Quoted 2 lines · Martin Doucha
Hi,
safe_modify_ldt()should not allow any errors. Let's merge v2.What about the other tests? This check should be applied to them as well eventually.
That varies by testcase. If the test expects any errors from the call, it should call
modify_ldt()directly and handle the return value either directly or using one of theTST_EXPhelper macros.
Signature · 1 line
Mailing list info: https://lists.linux.it/listinfo/ltp