syscalls/modify_ldt: Refactor into new API
v5 cover syscalls/modify_ldt: Refactor into new API
---
Changes in v5:
- Removed unnecessary #error
- Removed const specifier in cve-2015-3290.c
- Improved modify_ldt02 test description
- Added run_child() in modify_ldt02
- Removed unnecessary #include "lapi/ldt.h" in files that include common.h
- Extended coverage in modify_ldt01
- Link to v4: https://lore.kernel.org/r/[email protected]
Changes in v4:
- Re-added the asm/ldt.h include directive
- Link to v3: https://lore.kernel.org/r/[email protected]
Changes in v3:
- Dropped the set_thread_area01 patch for a later series
- Squashed modify_ldt03 commit into modify_ldt01
- Renamed struct tst_case to tcase
- Removed fallback definition of struct user_desc
- Link to v2: https://lore.kernel.org/r/[email protected]
Changes in v2:
- Also refactored set_thread_area01
- Merged simple tests (including the existing modify_ldt03) intomodify_ldt01 instead of splitting it
- Added SAFE_MODIFY_LDT() macro
- Removed check to asm/ldt.h in configure.ac
- Used tst_syscall() instead of syscall() in modify_ldt() @ lapi/ldt.h
- Link to v1: https://lore.kernel.org/r/[email protected]
---
Ricardo B. Marlière (3):
syscalls/modify_ldt: Add lapi/ldt.h syscalls/modify_ldt02: Refactor into new API syscalls/modify_ldt01: Refactor into new API
configure.ac | 1 - include/lapi/ldt.h | 34 +++ testcases/cve/cve-2015-3290.c | 37 +-- testcases/cve/cve-2017-17053.c | 10 +- testcases/kernel/syscalls/fork/fork05.c | 5 +- testcases/kernel/syscalls/modify_ldt/.gitignore | 5 +- testcases/kernel/syscalls/modify_ldt/common.h | 30 +++ .../kernel/syscalls/modify_ldt/modify_ldt01.c | 261 +++++---------------- .../kernel/syscalls/modify_ldt/modify_ldt02.c | 223 ++++-------------- .../kernel/syscalls/modify_ldt/modify_ldt03.c | 105 --------- 10 files changed, 183 insertions(+), 528 deletions(-)
---
base-commit: 0a0a77c444b56483bdde5046feeb518c96f5e4a2
change-id: 20250324-conversions-modify_ldt-816329223f6e
Best regards,
Signature · 5 lines
Ricardo B. Marlière <[email protected]> -- Mailing list info: https://lists.linux.it/listinfo/ltp
PATCH v5 1/3 syscalls/modify_ldt: Add lapi/ldt.h
From: Ricardo B. Marlière <[email protected]>
Add a wrapper to modify_ldt which is used in a few tests and should be reused.
--- configure.ac | 1 - include/lapi/ldt.h | 34 ++++++++++++++++++++++++++++++ testcases/cve/cve-2015-3290.c | 37 +++++++-------------------------- testcases/cve/cve-2017-17053.c | 10 ++++----- testcases/kernel/syscalls/fork/fork05.c | 5 ++--- 5 files changed, 48 insertions(+), 39 deletions(-)
configure.ac +0 -1
@@ -46,7 +46,6 @@ AC_CHECK_DECLS([PR_CAPBSET_DROP, PR_CAPBSET_READ],,,[#include <sys/prctl.h>]) AC_CHECK_DECLS([SEM_STAT_ANY],,,[#include <sys/sem.h>]) AC_CHECK_HEADERS_ONCE([ \ - asm/ldt.h \ asm/prctl.h \ cpuid.h \ emmintrin.h \
include/lapi/ldt.h new file +34 -0
@@ -0,0 +1,34 @@ +// SPDX-License-Identifier: GPL-2.0-or-later +/* +* Copyright (c) 2025 SUSE LLC Ricardo B. Marlière <[email protected]> +*/ + +#ifndef LAPI_LDT_H__ +#define LAPI_LDT_H__ + +#include "config.h" +#include "lapi/syscalls.h" +#include <asm/ldt.h> + +static int modify_ldt (int func,void *ptr,unsigned long bytecount) +{ +return tst_syscall (__NR_modify_ldt, func, ptr, bytecount); +} + +static int safe_modify_ldt (const char *file,const int lineno,int func, +void *ptr,unsigned long bytecount) +{ +int rval; + + rval =modify_ldt (func, ptr, bytecount); +if (rval ==-1 ) +tst_brk_ (file, lineno,TBROK |TERRNO , +"modify_ldt(%d, %p, %lu)" , func, ptr, bytecount); + +return rval; +} + +#define SAFE_MODIFY_LDT (func, ptr, bytecount) \ + safe_modify_ldt(__FILE__, __LINE__, (func), (ptr), (bytecount)) + +#endif /* LAPI_LDT_H__ */
testcases/cve/cve-2015-3290.c +7 -30
@@ -118,12 +118,10 @@ perhaps unsurprisingly.)#include "tst_test.h" #include "tst_timer.h" -#if defined(__x86_64__) || defined(__i386__) - +#if defined(__i386__) || defined(__x86_64__)#include <stdlib.h> #include <stdio.h> #include <inttypes.h> -#include <asm/ldt.h> #include <unistd.h> #include <sys/syscall.h> #include <setjmp.h>
@@ -132,6 +130,7 @@ perhaps unsurprisingly.)#include <sys/wait.h> #include <linux/perf_event.h> +#include "lapi/ldt.h" #include "lapi/syscalls.h" #include "tst_safe_pthread.h"
@@ -187,7 +186,7 @@ static int running = 1;static void set_ldt (void ) {/* Boring 16-bit data segment. */ -const struct user_desc data_desc = { +struct user_desc data_desc = { .entry_number =0 , .base_addr =0 , .limit =0xfffff ,
@@ -199,27 +198,7 @@ static void set_ldt(void) .useable = 0 }; -TEST (tst_syscall (__NR_modify_ldt,1 , &data_desc,sizeof (data_desc))); - -/* -* 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 (TST_RET >0 && ((int )TST_RET ) <0 ) { -tst_res (TINFO , -"WARNING: Libc mishandled modify_ldt() return value" ); -TST_ERR = -(int )TST_RET ; -TST_RET =-1 ; - } - -if (TST_RET ==-1 &&TST_ERR ==EINVAL ) { -tst_brk (TCONF |TTERRNO , -"modify_ldt: 16-bit data segments are probably disabled" ); - }else if (TST_RET !=0 ) { -tst_brk (TBROK |TTERRNO ,"modify_ldt" ); - } +SAFE_MODIFY_LDT (1 , &data_desc,sizeof (data_desc)); }static void try_corrupt_stack (unsigned short *orig_ss)
@@ -528,8 +507,6 @@ static struct tst_test test = { } }; -#else /* defined(__x86_64__) || defined(__i386__) */ - -TST_TEST_TCONF ("not (i386 or x86_64)" ); - -#endif +#else +TST_TEST_TCONF ("Test supported only on x86" ); +#endif /* defined(__i386__) || defined(__x86_64__) */
testcases/cve/cve-2017-17053.c +5 -5
@@ -16,8 +16,7 @@#include "config.h" #include "tst_test.h" -#ifdef HAVE_ASM_LDT_H -#include <asm/ldt.h> +#if defined(__i386__) || defined(__x86_64__)#include <pthread.h> #include <signal.h> #include <stdlib.h>
@@ -26,6 +25,7 @@#include <unistd.h> #include <stdio.h> +#include "lapi/ldt.h" #include "lapi/syscalls.h" #define EXEC_USEC 5000000
@@ -109,7 +109,7 @@ void run_test(void)struct user_desc desc = { .entry_number =8191 };install_sighandler (); -syscall (__NR_modify_ldt,1 , &desc,sizeof (desc)); +SAFE_MODIFY_LDT (1 , &desc,sizeof (desc));for (;;) {if (shm->do_exit)
@@ -164,5 +164,5 @@ static struct tst_test test = { };#else -TST_TEST_TCONF ("no asm/ldt.h header (only for i386 or x86_64)" ); -#endif +TST_TEST_TCONF ("Test supported only on x86" ); +#endif /* defined(__i386__) || defined(__x86_64__) */
testcases/kernel/syscalls/fork/fork05.c +2 -3
@@ -55,8 +55,7 @@#if defined(__i386__) -#include "lapi/syscalls.h" -#include <asm/ldt.h> +#include "lapi/ldt.h" static void run (void ) {
@@ -76,7 +75,7 @@ static void run(void) ldt0.seg_not_present =0 ; ldt0.useable =1 ; -tst_syscall (__NR_modify_ldt,1 , &ldt0,sizeof (ldt0)); +SAFE_MODIFY_LDT (1 , &ldt0,sizeof (ldt0)); asmvolatile ("movw %w0, %%fs" ::"q" (7 )); asmvolatile ("movl %%fs:0, %0" :"=r" (lo));
Signature · 5 lines
2.49.0 -- Mailing list info: https://lists.linux.it/listinfo/ltp
Re: [LTP] [PATCH v5 1/3] syscalls/modify_ldt: Add lapi/ldt.h
Hi Ricardo,
Quoted 2 lines
Add a wrapper to
modify_ldtwhich is used in a few tests and should be reused.
Generally LGTM. Few notes below.
Quoted 15 lines
Reviewed-by Andrea Cervesato <[email protected]>Signed-off-by Ricardo B. Marlière <[email protected]>--- configure.ac | 1 - include/lapi/ldt.h | 34 ++++++++++++++++++++++++++++++ testcases/cve/cve-2015-3290.c | 37 +++++++-------------------------- testcases/cve/cve-2017-17053.c | 10 ++++----- testcases/kernel/syscalls/fork/fork05.c | 5 ++--- 5 files changed, 48 insertions(+), 39 deletions(-)configure.ac +0
-0
configure.ac AC_CHECK_DECLS([PR_CAPBSET_DROP, PR_CAPBSET_READ],,,[#include <sys/prctl.h>]) · line 49
Quoted 4 lines
configure.ac +0
-1@@ -46,7 +46,6 @@ AC_CHECK_DECLS([PR_CAPBSET_DROP, PR_CAPBSET_READ],,,[#include <sys/prctl.h>]) AC_CHECK_DECLS([SEM_STAT_ANY],,,[#include <sys/sem.h>]) AC_CHECK_HEADERS_ONCE([ \ - asm/ldt.h \
I guess because <asm/ldt.h> is old enough (was here before UAPI split in kernel v3.8-rc1 we can remove it. But it'd be nice to mention the reason in the commit message (technically it's a separate change, ok to do that in the commit while you're at it, but mentioning the reason helps in case of regression).
BTW it'd be nice to go over our m4/ and configure.ac and drop things old enough to speedup configure run. AC_CHECK_HEADERS_ONCE() is probably quite quick, m4/ files probably take more time. But every speedup counts.
FYI we support quite old distros: kernel 4.4 (in SLE12-SP2):
https://linux-test-project.readthedocs.io/en/latest/users/supported_systems.html
Quoted 28 lines
configure.ac +0
-0asm/prctl.h \ cpuid.h \ emmintrin.h \include/lapi/ldt.h new file +19
-0@@ -0,0 +1,34 @@ +// SPDX-License-Identifier: GPL-2.0-or-later +/* +* Copyright (c) 2025 SUSE LLC Ricardo B. Marlière <[email protected]> +*/ + +#ifndef LAPI_LDT_H__ +#define LAPI_LDT_H__ + +#include "config.h" +#include "lapi/syscalls.h" +#include <asm/ldt.h> + +static int modify_ldt (int func,void *ptr,unsigned long bytecount) +{ +return tst_syscall (__NR_modify_ldt, func, ptr, bytecount); +} + +static int safe_modify_ldt (const char *file,const int lineno,int func, +void *ptr,unsigned long bytecount)
include/lapi/ldt.h line 29
Quoted 10 lines
include/lapi/ldt.h new file +10
-0+{ +int rval; + + rval =modify_ldt (func, ptr, bytecount); +if (rval ==-1 ) +tst_brk_ (file, lineno,TBROK |TERRNO , +"modify_ldt(%d, %p, %lu)" , func, ptr, bytecount); + +return rval; +}
You dropped 'const' from struct user_desc data_desc definitions. Using const struct user_desc *ptr as a parameter would help to keep the function. Maybe I'm wrong but I guess if there were libc wrapper (no libc has it) it would prefer to have pointer to struct than plain void as a parameter.
static int modify_ldt(int func, const struct user_desc *ptr, unsigned long bytecount)
{
return tst_syscall(__NR_modify_ldt, func, ptr, bytecount);
}static int safe_modify_ldt(const char *file, const int lineno, int func,
const struct user_desc *ptr, unsigned long bytecount)
{
int rval;
rval = modify_ldt(func, ptr, bytecount);
if (rval == -1)
tst_brk_(file, lineno, TBROK | TERRNO,
"modify_ldt(%d, %p, %lu)", func, &ptr, bytecount);
return rval;
}nit: IMHO modify_ldt() is not used anywhere outside lapi file, right? I would also consider instead of creating modify_ldt() just put raw syscall:
rval = tst_syscall(__NR_modify_ldt, func, &ptr, bytecount);
Quoted 12 lines
include/lapi/ldt.h new file +5
-0+ +#define SAFE_MODIFY_LDT (func, ptr, bytecount) \ + safe_modify_ldt(__FILE__, __LINE__, (func), (ptr), (bytecount)) + +#endif /* LAPI_LDT_H__ */ testcases/cve/cve-2015-3290.c +0
-0@@ -118,12 +118,10 @@ perhaps unsurprisingly.)#include "tst_test.h" #include "tst_timer.h"
testcases/cve/cve-2015-3290.c perhaps unsurprisingly.) · line 126
Quoted 10 lines
testcases/cve/cve-2015-3290.c +1
-3-#if defined(__x86_64__) || defined(__i386__) - +#if defined(__i386__) || defined(__x86_64__)#include <stdlib.h> #include <stdio.h> #include <inttypes.h> -#include <asm/ldt.h> #include <unistd.h> #include <sys/syscall.h>
We don't need <sys/syscall.h>
testcases/cve/cve-2015-3290.c perhaps unsurprisingly.) · line 134
Quoted 7 lines
testcases/cve/cve-2015-3290.c +1
-0#include <setjmp.h> @@ -132,6 +130,7 @@ perhaps unsurprisingly.)#include <sys/wait.h> #include <linux/perf_event.h> +#include "lapi/ldt.h" #include "lapi/syscalls.h"
We don't need "lapi/syscalls.h" (it's in "lapi/ldt.h").
Quoted 67 lines
testcases/cve/cve-2015-3290.c +5
-27#include "tst_safe_pthread.h" @@ -187,7 +186,7 @@ static int running = 1;static void set_ldt (void ) {/* Boring 16-bit data segment. */ -const struct user_desc data_desc = { +struct user_desc data_desc = { .entry_number =0 , .base_addr =0 , .limit =0xfffff ,@@ -199,27 +198,7 @@ static void set_ldt(void) .useable = 0 }; -TEST (tst_syscall (__NR_modify_ldt,1 , &data_desc,sizeof (data_desc))); - -/* -* 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 (TST_RET >0 && ((int )TST_RET ) <0 ) { -tst_res (TINFO , -"WARNING: Libc mishandled modify_ldt() return value" ); -TST_ERR = -(int )TST_RET ; -TST_RET =-1 ; - } - -if (TST_RET ==-1 &&TST_ERR ==EINVAL ) { -tst_brk (TCONF |TTERRNO , -"modify_ldt: 16-bit data segments are probably disabled" ); - }else if (TST_RET !=0 ) { -tst_brk (TBROK |TTERRNO ,"modify_ldt" ); - } +SAFE_MODIFY_LDT (1 , &data_desc,sizeof (data_desc)); }static void try_corrupt_stack (unsigned short *orig_ss)@@ -528,8 +507,6 @@ static struct tst_test test = { } }; -#else /* defined(__x86_64__) || defined(__i386__) */ - -TST_TEST_TCONF ("not (i386 or x86_64)" ); - -#endif +#else +TST_TEST_TCONF ("Test supported only on x86" ); +#endif /* defined(__i386__) || defined(__x86_64__) */ testcases/cve/cve-2017-17053.c +1
-2@@ -16,8 +16,7 @@#include "config.h" #include "tst_test.h" -#ifdef HAVE_ASM_LDT_H -#include <asm/ldt.h> +#if defined(__i386__) || defined(__x86_64__)#include <pthread.h> #include <signal.h> #include <stdlib.h>
testcases/cve/cve-2017-17053.c line 29
Quoted 5 lines
testcases/cve/cve-2017-17053.c +1
-0@@ -26,6 +25,7 @@#include <unistd.h> #include <stdio.h> +#include "lapi/ldt.h" #include "lapi/syscalls.h"
nit: We don't need "lapi/syscalls.h" since it's in "lapi/ldt.h". And we don't need <sys/syscall.h>.
Quoted 11 lines
testcases/cve/cve-2017-17053.c +1
-1#define EXEC_USEC 5000000@@ -109,7 +109,7 @@ void run_test(void)struct user_desc desc = { .entry_number =8191 };install_sighandler (); -syscall (__NR_modify_ldt,1 , &desc,sizeof (desc)); +SAFE_MODIFY_LDT (1 , &desc,sizeof (desc));for (;;) {if (shm->do_exit)
testcases/cve/cve-2017-17053.c static struct tst_test test = { · line 167
Quoted 6 lines
testcases/cve/cve-2017-17053.c +1
-2@@ -164,5 +164,5 @@ static struct tst_test test = { };#else -TST_TEST_TCONF ("no asm/ldt.h header (only for i386 or x86_64)" ); -#endif +TST_TEST_TCONF ("Test supported only on x86" );
nit: for some people "x86" means i386 (32 bit intel).
Quoted 16 lines
testcases/cve/cve-2017-17053.c +1
-0+#endif /* defined(__i386__) || defined(__x86_64__) */ testcases/kernel/syscalls/fork/fork05.c +1
-2@@ -55,8 +55,7 @@#if defined(__i386__) -#include "lapi/syscalls.h" -#include <asm/ldt.h> +#include "lapi/ldt.h" static void run (void ) {
testcases/kernel/syscalls/fork/fork05.c static void run(void) · line 79
Quoted 4 lines
testcases/kernel/syscalls/fork/fork05.c +0
-1@@ -76,7 +75,7 @@ static void run(void) ldt0.seg_not_present =0 ; ldt0.useable =1 ; -tst_syscall (__NR_modify_ldt,1 , &ldt0,sizeof (ldt0));
Interesting, no check for return value.
testcases/kernel/syscalls/fork/fork05.c static void run(void) · line 78
Quoted 1 line
testcases/kernel/syscalls/fork/fork05.c +1
-0+SAFE_MODIFY_LDT (1 , &ldt0,sizeof (ldt0));
Kind regards,
Petr
Quoted 2 lines
testcases/kernel/syscalls/fork/fork05.c +0
-0asmvolatile ("movw %w0, %%fs" ::"q" (7 )); asmvolatile ("movl %%fs:0, %0" :"=r" (lo));
Signature · 1 line
Mailing list info: https://lists.linux.it/listinfo/ltp
Re: [LTP] [PATCH v5 1/3] syscalls/modify_ldt: Add lapi/ldt.h
Hi Petr,
Quoted 4 lines · Petr Vorel
nit: IMHO
modify_ldt()is not used anywhere outside lapi file, right? I would also consider instead of creatingmodify_ldt()just put raw syscall:rval = tst_syscall(__NR_modify_ldt, func, &ptr, bytecount);
Just yesterday I got a review from @Cyril asking me to add syscalls function definition which are missing inside the lapi/.h header. The reason is that we want to fallback libc and eventually check for HAVE_FUNCT_* via autotools.
In general I agree with this approach.
Kind regards,
Andrea Cervesato
Signature · 1 line
Mailing list info: https://lists.linux.it/listinfo/ltp
Re: [LTP] [PATCH v5 1/3] syscalls/modify_ldt: Add lapi/ldt.h
Hi Andrea,
Quoted 6 lines
Hi Petr,
Quoted 2 lines · Petr Vorel
nit: IMHO
modify_ldt()is not used anywhere outside lapi file, right? I would also consider instead of creatingmodify_ldt()just put raw syscall:
Quoted 8 lines
Quoted 1 line
rval = tst_syscall(__NR_modify_ldt, func, &ptr, bytecount);Just yesterday I got a review from @Cyril asking me to add syscalls function definition which are missing inside the lapi/.h header. The reason is that we want to fallback libc and eventually check for HAVE_FUNCT_* via autotools.
In general I agree with this approach.
OK, no problem, thanks for info.
Kind regards,
Petr
Quoted 2 lines
Kind regards,
Andrea Cervesato
Signature · 1 line
Mailing list info: https://lists.linux.it/listinfo/ltp
Re: [LTP] [PATCH v5 1/3] syscalls/modify_ldt: Add lapi/ldt.h
In reply to Petr VorelHi Petr,
Quoted 24 lines · Petr Vorel
Hi Ricardo,
Quoted 2 lines
Add a wrapper to
modify_ldtwhich is used in a few tests and should be reused.Generally LGTM. Few notes below.
Quoted 16 lines
Reviewed-by Andrea Cervesato <[email protected]>Signed-off-by Ricardo B. Marlière <[email protected]>--- configure.ac | 1 - include/lapi/ldt.h | 34 ++++++++++++++++++++++++++++++ testcases/cve/cve-2015-3290.c | 37 +++++++-------------------------- testcases/cve/cve-2017-17053.c | 10 ++++----- testcases/kernel/syscalls/fork/fork05.c | 5 ++--- 5 files changed, 48 insertions(+), 39 deletions(-)configure.ac +0
-0@@ -46,7 +46,6 @@ AC_CHECK_DECLS([PR_CAPBSET_DROP, PR_CAPBSET_READ],,,[#include <sys/prctl.h>]) AC_CHECK_DECLS([SEM_STAT_ANY],,,[#include <sys/sem.h>])
Quoted 7 lines
configure.ac AC_CHECK_DECLS([PR_CAPBSET_DROP, PR_CAPBSET_READ],,,[#include <sys/prctl.h>]) · line 49
Quoted 2 lines
configure.ac +0
-1AC_CHECK_HEADERS_ONCE([ \ - asm/ldt.h \I guess because <
asm/ldt.h> is old enough (was here before UAPI split in kernel v3.8-rc1 we can remove it. But it'd be nice to mention the reason in the commit message (technically it's a separate change, ok to do that in the commit while you're at it, but mentioning the reason helps in case of regression).
Makes sense, I'll amend the commit log.
Quoted 3 lines
BTW it'd be nice to go over our m4/ and configure.ac and drop things old enough to speedup configure run.
AC_CHECK_HEADERS_ONCE()is probably quite quick, m4/ files probably take more time. But every speedup counts.
I will take a look and see about that in a future series, if I find anything useful.
Quoted 67 lines
FYI we support quite old distros: kernel 4.4 (in SLE12-SP2):
https://linux-test-project.readthedocs.io/en/latest/users/supported_systems.html
Quoted 28 lines
configure.ac +0
-0asm/prctl.h \ cpuid.h \ emmintrin.h \include/lapi/ldt.h new file +19
-0@@ -0,0 +1,34 @@ +// SPDX-License-Identifier: GPL-2.0-or-later +/* +* Copyright (c) 2025 SUSE LLC Ricardo B. Marlière <[email protected]> +*/ + +#ifndef LAPI_LDT_H__ +#define LAPI_LDT_H__ + +#include "config.h" +#include "lapi/syscalls.h" +#include <asm/ldt.h> + +static int modify_ldt (int func,void *ptr,unsigned long bytecount) +{ +return tst_syscall (__NR_modify_ldt, func, ptr, bytecount); +} + +static int safe_modify_ldt (const char *file,const int lineno,int func, +void *ptr,unsigned long bytecount)include/lapi/ldt.h line 29
Quoted 10 lines
include/lapi/ldt.h new file +10
-0+{ +int rval; + + rval =modify_ldt (func, ptr, bytecount); +if (rval ==-1 ) +tst_brk_ (file, lineno,TBROK |TERRNO , +"modify_ldt(%d, %p, %lu)" , func, ptr, bytecount); + +return rval; +}You dropped 'const' from struct
user_descdata_descdefinitions. Using const structuser_desc*ptr as a parameter would help to keep the function. Maybe I'm wrong but I guess if there were libc wrapper (no libc has it) it would prefer to have pointer to struct than plain void as a parameter.static int
modify_ldt(int func, const struct user_desc *ptr, unsigned long bytecount){ return tst_syscall(__NR_modify_ldt, func, ptr, bytecount); }static int safe_modify_ldt(const char *file, const int lineno, int func,
const structuser_desc*ptr, unsigned long bytecount){ int rval; rval = modify_ldt(func, ptr, bytecount); if (rval == -1) tst_brk_(file, lineno, TBROK | TERRNO, "modify_ldt(%d, %p, %lu)", func, &ptr, bytecount); return rval; }
Quoted 2 lines
nit: IMHO
modify_ldt()is not used anywhere outside lapi file, right? I would also consider instead of creatingmodify_ldt()just put raw syscall:
Actually we need this in modify_ldt01.c:
TST_EXP_FAIL(modify_ldt(tc->tfunc, tc->ptr, tc->bytecount), tc->exp_errno); andTST_EXP_POSITIVE(modify_ldt(tc->tfunc, tc->ptr, tc->bytecount));
Quoted 27 lines
rval = tst_syscall(__NR_modify_ldt, func, &ptr, bytecount);Quoted 12 lines
include/lapi/ldt.h new file +5
-0+ +#define SAFE_MODIFY_LDT (func, ptr, bytecount) \ + safe_modify_ldt(__FILE__, __LINE__, (func), (ptr), (bytecount)) + +#endif /* LAPI_LDT_H__ */ testcases/cve/cve-2015-3290.c +0
-0@@ -118,12 +118,10 @@ perhaps unsurprisingly.)#include "tst_test.h" #include "tst_timer.h" testcases/cve/cve-2015-3290.c perhaps unsurprisingly.) · line 126
Quoted 10 lines
testcases/cve/cve-2015-3290.c +1
-3-#if defined(__x86_64__) || defined(__i386__) - +#if defined(__i386__) || defined(__x86_64__)#include <stdlib.h> #include <stdio.h> #include <inttypes.h> -#include <asm/ldt.h> #include <unistd.h> #include <sys/syscall.h> We don't need <
sys/syscall.h>
Quoted 8 lines
testcases/cve/cve-2015-3290.c perhaps unsurprisingly.) · line 134
Quoted 7 lines
testcases/cve/cve-2015-3290.c +1
-0#include <setjmp.h> @@ -132,6 +130,7 @@ perhaps unsurprisingly.)#include <sys/wait.h> #include <linux/perf_event.h> +#include "lapi/ldt.h" #include "lapi/syscalls.h" We don't need "
lapi/syscalls.h" (it's in "lapi/ldt.h").
Ack.
Quoted 71 lines
Quoted 70 lines
testcases/cve/cve-2015-3290.c +5
-27#include "tst_safe_pthread.h" @@ -187,7 +186,7 @@ static int running = 1;static void set_ldt (void ) {/* Boring 16-bit data segment. */ -const struct user_desc data_desc = { +struct user_desc data_desc = { .entry_number =0 , .base_addr =0 , .limit =0xfffff ,@@ -199,27 +198,7 @@ static void set_ldt(void) .useable = 0 }; -TEST (tst_syscall (__NR_modify_ldt,1 , &data_desc,sizeof (data_desc))); - -/* -* 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 (TST_RET >0 && ((int )TST_RET ) <0 ) { -tst_res (TINFO , -"WARNING: Libc mishandled modify_ldt() return value" ); -TST_ERR = -(int )TST_RET ; -TST_RET =-1 ; - } - -if (TST_RET ==-1 &&TST_ERR ==EINVAL ) { -tst_brk (TCONF |TTERRNO , -"modify_ldt: 16-bit data segments are probably disabled" ); - }else if (TST_RET !=0 ) { -tst_brk (TBROK |TTERRNO ,"modify_ldt" ); - } +SAFE_MODIFY_LDT (1 , &data_desc,sizeof (data_desc)); }static void try_corrupt_stack (unsigned short *orig_ss)@@ -528,8 +507,6 @@ static struct tst_test test = { } }; -#else /* defined(__x86_64__) || defined(__i386__) */ - -TST_TEST_TCONF ("not (i386 or x86_64)" ); - -#endif +#else +TST_TEST_TCONF ("Test supported only on x86" ); +#endif /* defined(__i386__) || defined(__x86_64__) */ testcases/cve/cve-2017-17053.c +1
-2@@ -16,8 +16,7 @@#include "config.h" #include "tst_test.h" -#ifdef HAVE_ASM_LDT_H -#include <asm/ldt.h> +#if defined(__i386__) || defined(__x86_64__)#include <pthread.h> #include <signal.h> #include <stdlib.h> @@ -26,6 +25,7 @@#include <unistd.h> #include <stdio.h>
Quoted 5 lines
testcases/cve/cve-2017-17053.c line 28
Quoted 2 lines
testcases/cve/cve-2017-17053.c +1
-0+#include "lapi/ldt.h" #include "lapi/syscalls.h" nit: We don't need "
lapi/syscalls.h" since it's in "lapi/ldt.h". And we don't need <sys/syscall.h>.
Ack, thanks!
Quoted 14 lines
Quoted 13 lines
testcases/cve/cve-2017-17053.c +1
-1#define EXEC_USEC 5000000@@ -109,7 +109,7 @@ void run_test(void)struct user_desc desc = { .entry_number =8191 };install_sighandler (); -syscall (__NR_modify_ldt,1 , &desc,sizeof (desc)); +SAFE_MODIFY_LDT (1 , &desc,sizeof (desc));for (;;) {if (shm->do_exit)@@ -164,5 +164,5 @@ static struct tst_test test = { };
Quoted 5 lines
testcases/cve/cve-2017-17053.c static struct tst_test test = { · line 167
Quoted 4 lines
testcases/cve/cve-2017-17053.c +1
-2#else -TST_TEST_TCONF ("no asm/ldt.h header (only for i386 or x86_64)" ); -#endif +TST_TEST_TCONF ("Test supported only on x86" );nit: for some people "x86" means i386 (32 bit intel).
Indeed. I borrowed this from the kvm suite, I think we can keep it.
Quoted 20 lines
Quoted 19 lines
testcases/cve/cve-2017-17053.c +1
-0+#endif /* defined(__i386__) || defined(__x86_64__) */ testcases/kernel/syscalls/fork/fork05.c +1
-2@@ -55,8 +55,7 @@#if defined(__i386__) -#include "lapi/syscalls.h" -#include <asm/ldt.h> +#include "lapi/ldt.h" static void run (void ) {@@ -76,7 +75,7 @@ static void run(void) ldt0.seg_not_present =0 ; ldt0.useable =1 ;
Quoted 10 lines
testcases/kernel/syscalls/fork/fork05.c static void run(void) · line 79
Quoted 1 line
testcases/kernel/syscalls/fork/fork05.c +0
-1-tst_syscall (__NR_modify_ldt,1 , &ldt0,sizeof (ldt0));Interesting, no check for return value.
testcases/kernel/syscalls/fork/fork05.c static void run(void) · line 78
Quoted 1 line
testcases/kernel/syscalls/fork/fork05.c +1
-0+SAFE_MODIFY_LDT (1 , &ldt0,sizeof (ldt0));Kind regards,
PetrQuoted 2 lines
testcases/kernel/syscalls/fork/fork05.c +0
-0asmvolatile ("movw %w0, %%fs" ::"q" (7 )); asmvolatile ("movl %%fs:0, %0" :"=r" (lo));
Thanks for reviewing,
- Ricardo.
Signature · 1 line
Mailing list info: https://lists.linux.it/listinfo/ltp
Re: [LTP] [PATCH v5 1/3] syscalls/modify_ldt: Add lapi/ldt.h
In reply to Ricardo B. Marliere via ltpHi Ricardo, Andrea,
Quoted 5 lines
+++
b/include/lapi/ldt.hinclude/lapi/ldt.h new file +3
-0@@ -0,0 +1,34 @@ +// SPDX-License-Identifier: GPL-2.0-or-later +/* +* Copyright (c) 2025 SUSE LLC Ricardo B. Marlière <[email protected]>
include/lapi/ldt.h line 13
Quoted 10 lines
include/lapi/ldt.h new file +10
-0+*/ + +#ifndef LAPI_LDT_H__ +#define LAPI_LDT_H__ + +#include "config.h" +#include "lapi/syscalls.h" +#include <asm/ldt.h> + +static int modify_ldt (int func,void *ptr,unsigned long bytecount)
FYI if this in a header it should be 'static inline'. That would be worth to fix.
We have a lot of 'static inline' in lapi headers. IMHO this is a good approach for these feature specific syscalls, although Martin Doucha tried to get rid of some static inline (moving them to C files in lib/) to avoid compilation problems.
But again, this is worth for some generic files long enough e.g. lib/tst_netlink.c or lib/tst_netdevice.c.
Also static inline makes code to grow, but adding new C source to LTP libs makes IMHO bigger code size increase (besides we don't care about LTP size anyway, otherwise we would change linking similar to busybox - single binary providing many functions).
include/lapi/ldt.h line 20
Quoted 7 lines
include/lapi/ldt.h new file +7
-0+{ +return tst_syscall (__NR_modify_ldt, func, ptr, bytecount); +} + +static int safe_modify_ldt (const char *file,const int lineno,int func, +void *ptr,unsigned long bytecount) +{
And here as well.
Kind regards,
Petr
Quoted 14 lines
include/lapi/ldt.h new file +14
-0+int rval; + + rval =modify_ldt (func, ptr, bytecount); +if (rval ==-1 ) +tst_brk_ (file, lineno,TBROK |TERRNO , +"modify_ldt(%d, %p, %lu)" , func, ptr, bytecount); + + return rval; +} + +#define SAFE_MODIFY_LDT (func, ptr, bytecount) \ + safe_modify_ldt(__FILE__, __LINE__, (func), (ptr), (bytecount)) + +#endif /* LAPI_LDT_H__ */
Signature · 1 line
Mailing list info: https://lists.linux.it/listinfo/ltp
Re: [LTP] [PATCH v5 1/3] syscalls/modify_ldt: Add lapi/ldt.h
Hello Petr!
Quoted 23 lines · Petr Vorel
Hi Ricardo, Andrea,
Quoted 5 lines
+++
b/include/lapi/ldt.hinclude/lapi/ldt.h new file +3
-0@@ -0,0 +1,34 @@ +// SPDX-License-Identifier: GPL-2.0-or-later +/* +* Copyright (c) 2025 SUSE LLC Ricardo B. Marlière <[email protected]> include/lapi/ldt.h line 13
Quoted 10 lines
include/lapi/ldt.h new file +10
-0+*/ + +#ifndef LAPI_LDT_H__ +#define LAPI_LDT_H__ + +#include "config.h" +#include "lapi/syscalls.h" +#include <asm/ldt.h> + +static int modify_ldt (int func,void *ptr,unsigned long bytecount)FYI if this in a header it should be 'static inline'. That would be worth to fix.
We have a lot of 'static inline' in lapi headers. IMHO this is a good approach for these feature specific syscalls, although Martin Doucha tried to get rid of some static inline (moving them to C files in
lib/) to avoid compilation problems.
Quoted 7 lines
But again, this is worth for some generic files long enough e.g.
lib/tst_netlink.corlib/tst_netdevice.c.Also static inline makes code to grow, but adding new C source to LTP libs makes IMHO bigger code size increase (besides we don't care about LTP size anyway, otherwise we would change linking similar to busybox - single binary providing many functions).
Thanks for your review, I will address your points in the next revision :)
Quoted 27 lines
include/lapi/ldt.h line 20
Quoted 8 lines
include/lapi/ldt.h new file +7
-0+{ +return tst_syscall (__NR_modify_ldt, func, ptr, bytecount); +} + +static int safe_modify_ldt (const char *file,const int lineno,int func, +void *ptr,unsigned long bytecount) +{And here as well.
Kind regards,
PetrQuoted 14 lines
include/lapi/ldt.h new file +14
-0+int rval; + + rval =modify_ldt (func, ptr, bytecount); +if (rval ==-1 ) +tst_brk_ (file, lineno,TBROK |TERRNO , +"modify_ldt(%d, %p, %lu)" , func, ptr, bytecount); + + return rval; +} + +#define SAFE_MODIFY_LDT (func, ptr, bytecount) \ + safe_modify_ldt(__FILE__, __LINE__, (func), (ptr), (bytecount)) + +#endif /* LAPI_LDT_H__ */
Signature · 1 line
Mailing list info: https://lists.linux.it/listinfo/ltp
PATCH v5 2/3 syscalls/modify_ldt02: Refactor into new API
In reply to Ricardo B. Marliere via ltpFrom: Ricardo B. Marlière <[email protected]>
--- testcases/kernel/syscalls/modify_ldt/common.h | 30 +++ .../kernel/syscalls/modify_ldt/modify_ldt02.c | 223 +++++---------------- 2 files changed, 80 insertions(+), 173 deletions(-)
testcases/kernel/syscalls/modify_ldt/common.h new file +30 -0
@@ -0,0 +1,30 @@ +// SPDX-License-Identifier: GPL-2.0-or-later +/* +* Copyright (c) International Business Machines Corp., 2001 +* 07/2001 Ported by Wayne Boyer +* Copyright (c) 2025 SUSE LLC Ricardo B. Marlière <[email protected]> +*/ + +#ifndef COMMON_H +#define COMMON_H + +#include "tst_test.h" +#include "lapi/ldt.h" + +int create_segment (void *seg,size_t size) +{ +struct user_desc entry = { + .entry_number =0 , + .base_addr = (unsigned long )seg, + .limit = size, + .seg_32bit =1 , + .contents =0 , + .read_exec_only =0 , + .limit_in_pages =0 , + .seg_not_present =0 , + }; + +return SAFE_MODIFY_LDT (1 , &entry,sizeof (entry)); +} + +#endif
testcases/kernel/syscalls/modify_ldt/modify_ldt02.c +50 -173
249 lines not on this page · raw message
Signature · 5 lines
2.49.0 -- Mailing list info: https://lists.linux.it/listinfo/ltp
PATCH v5 3/3 syscalls/modify_ldt01: Refactor into new API
In reply to Ricardo B. Marliere via ltpFrom: Ricardo B. Marlière <[email protected]>
Now that we're using the wrapped modify_ldt() from the lapi/ldt.h which uses tst_syscall(), it does not make sense to keep the first block of the original test which simply checked for ENOSYS. Also, merge modify_ldt03 into modify_ldt01 and extend the test to cover all the errors from the manual page.
--- testcases/kernel/syscalls/modify_ldt/.gitignore | 5 +- .../kernel/syscalls/modify_ldt/modify_ldt01.c | 261 +++++---------------- .../kernel/syscalls/modify_ldt/modify_ldt03.c | 105 --------- 3 files changed, 55 insertions(+), 316 deletions(-)
testcases/kernel/syscalls/modify_ldt/.gitignore +2 -3
@@ -1,3 +1,2 @@ -/modify_ldt01 -/modify_ldt02 -/modify_ldt03 +modify_ldt01 +modify_ldt02
testcases/kernel/syscalls/modify_ldt/modify_ldt01.c +53 -208
283 lines not on this page · raw message
testcases/kernel/syscalls/modify_ldt/modify_ldt03.c deleted +0 -105
105 lines not on this page · raw message
Signature · 5 lines
2.49.0 -- Mailing list info: https://lists.linux.it/listinfo/ltp
Re: [LTP] [PATCH v5 3/3] syscalls/modify_ldt01: Refactor into new API
Quoted 78 lines · rbm
From: Ricardo B. Marlière <[email protected]>
Now that we're using the wrapped
modify_ldt()from thelapi/ldt.hwhich usestst_syscall(), it does not make sense to keep the first block of the original test which simply checked for ENOSYS. Also, mergemodify_ldt03intomodify_ldt01and extend the test to cover all the errors from the manual page.Signed-off-by Ricardo B. Marlière <[email protected]>--- testcases/kernel/syscalls/modify_ldt/.gitignore | 5 +- .../kernel/syscalls/modify_ldt/modify_ldt01.c | 261 +++++---------------- .../kernel/syscalls/modify_ldt/modify_ldt03.c | 105 --------- 3 files changed, 55 insertions(+), 316 deletions(-)testcases/kernel/syscalls/modify_ldt/.gitignore +2
-3@@ -1,3 +1,2 @@ -/modify_ldt01 -/modify_ldt02 -/modify_ldt03 +modify_ldt01 +modify_ldt02testcases/kernel/syscalls/modify_ldt/modify_ldt01.c +6
-38@@ -1,230 +1,75 @@ +// SPDX-License-Identifier: GPL-2.0-or-later /* -* -* Copyright (c) International Business Machines Corp., 2001 -* -* This program is free software; you can redistribute it and/or modify -* it under the terms of the GNU General Public License as published by -* the Free Software Foundation; either version 2 of the License, or -* (at your option) any later version. -* -* This program is distributed in the hope that it will be useful, -* but WITHOUT ANY WARRANTY; without even the implied warranty of -* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See -* the GNU General Public License for more details. -* -* You should have received a copy of the GNU General Public License -* along with this program; if not, write to the Free Software -* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA +* Copyright (c) International Business Machines Corp., 2001 +* 07/2001 Ported by Wayne Boyer +* Copyright (c) 2025 SUSE LLC Ricardo B. Marlière <[email protected]> */ -/* -* NAME -* modify_ldt01.c -* -* DESCRIPTION -* Testcase to check the error conditions for modify_ldt(2) +/*\ +* Verify that modify_ldt() calls: * -* CALLS -* modify_ldt() -* -* ALGORITHM -* block1: -* Invoke modify_ldt() with a func value which is neither -* 0 or 1. Verify that ENOSYS is set. -* block2: -* Invoke mprotect() with ptr == NULL. Verify that EINVAL -* is set. -* block3: -* Create an LDT segment. -* Try to read from an invalid pointer. -* Verify that EFAULT is set. -* -* USAGE
testcases/kernel/syscalls/modify_ldt/modify_ldt01.c line 13
Quoted 10 lines
testcases/kernel/syscalls/modify_ldt/modify_ldt01.c +3
-7-* modify_ldt01 -* -* HISTORY -* 07/2001 Ported by Wayne Boyer -* -* RESTRICTIONS -* None +* - Fails with EINVAL, when writing (func=1) to an invalid pointer +* - Fails with EFAULT, when reading (func=0) from an invalid pointer +* - Passes when reading (func=0) from a valid pointer
Ah, I forgot to update the description...
Quoted 336 lines
testcases/kernel/syscalls/modify_ldt/modify_ldt01.c +44
-163*/ -#include "config.h" -#include "test.h" - -TCID_DEFINE (modify_ldt01); -int TST_TOTAL =1 ; +#include "tst_test.h" -#if defined(__i386__) && defined(HAVE_MODIFY_LDT ) - -#ifdef HAVE_ASM_LDT_H -#include <asm/ldt.h> -#endif -extern int modify_ldt (int ,void *,unsigned long ); - -#include <asm/unistd.h> -#include <errno.h> - -/* Newer ldt.h files use user_desc, instead of modify_ldt_ldt_s */ -#ifdef HAVE_STRUCT_USER_DESC -typedef struct user_desc modify_ldt_s ; -#elif HAVE_STRUCT_MODIFY_LDT_LDT_S -typedef struct modify_ldt_ldt_s modify_ldt_s ; -#else -typedef struct modify_ldt_ldt_t { -unsigned int entry_number; -unsigned long int base_addr; -unsigned int limit; -unsigned int seg_32bit:1 ; -unsigned int contents:2 ; -unsigned int read_exec_only:1 ; -unsigned int limit_in_pages:1 ; -unsigned int seg_not_present:1 ; -unsigned int useable:1 ; -unsigned int empty:25 ; -}modify_ldt_s ; -#endif - -int create_segment (void *,size_t ); -void cleanup (void ); -void setup (void ); - -int main (int ac,char **av) -{ -int lc; +#ifdef __i386__ +#include "common.h" +static void *ptr; +static char *buf; +static struct user_desc entry; +static struct tcase { +int tfunc;void *ptr; -int retval, func; - -int seg[4 ]; - -tst_parse_opts (ac, av,NULL ,NULL ); - -setup (); - -for (lc =0 ;TEST_LOOPING (lc); lc++) { - -/* reset tst_count in case we are looping */ - tst_count =0 ; - -/* -* Check for ENOSYS. -*/ - ptr =malloc (10 ); - func =100 ; - retval =modify_ldt (func, ptr,sizeof (ptr)); -if (retval <0 ) { -if (errno !=ENOSYS ) { -tst_resm (TFAIL ,"modify_ldt() set invalid " -"errno, expected ENOSYS, got: %d" , - errno); - }else { -tst_resm (TPASS , -"modify_ldt() set expected errno" ); - } - }else { -tst_resm (TFAIL ,"modify_ldt error: " -"unexpected return value %d" , retval); - } - -free (ptr); - -/* -* Check for EINVAL -*/ - ptr =0 ; - - retval =modify_ldt (1 , ptr,sizeof (ptr)); -if (retval <0 ) { -if (errno !=EINVAL ) { -tst_resm (TFAIL ,"modify_ldt() set invalid " -"errno, expected EINVAL, got: %d" , - errno); - }else { -tst_resm (TPASS , -"modify_ldt() set expected errno" ); - } - }else { -tst_resm (TFAIL ,"modify_ldt error: " -"unexpected return value %d" , retval); - } - -/* -* Create a new LDT segment. -*/ -if (create_segment (seg,sizeof (seg)) ==-1 ) { -tst_brkm (TBROK , cleanup,"Creation of segment failed" ); - } - -/* -* Check for EFAULT -*/ - ptr =sbrk (0 ); - - retval =modify_ldt (0 , ptr +0xFFF ,sizeof (ptr)); -if (retval <0 ) { -if (errno !=EFAULT ) { -tst_resm (TFAIL ,"modify_ldt() set invalid " -"errno, expected EFAULT, got: %d" , - errno); - }else { -tst_resm (TPASS , -"modify_ldt() set expected errno" ); - } - }else { -tst_resm (TFAIL ,"modify_ldt error: " -"unexpected return value %d" , retval); - } - } -cleanup (); -tst_exit (); -} - -/* -* create_segment() - -*/ -int create_segment (void *seg,size_t size) +unsigned long bytecount; +int exp_errno; +} tcases[] = { + {0 , &ptr,sizeof (ptr),EFAULT }, + {0 , &buf,sizeof (buf),0 }, + {1 , (void *)0 ,0 ,EINVAL }, + {1 , &entry,sizeof (struct user_desc ) -1 ,EINVAL }, + {1 , &entry,sizeof (struct user_desc ),EINVAL }, + {0x11 , &entry,sizeof (struct user_desc ),EINVAL }, +}; + +void run (unsigned int i) { -modify_ldt_s entry; +struct tcase *tc = &tcases[i]; - entry.entry_number =0 ; - entry.base_addr = (unsigned long )seg; - entry.limit = size; - entry.seg_32bit =1 ; - entry.contents =0 ; - entry.read_exec_only =0 ; - entry.limit_in_pages =0 ; - entry.seg_not_present =0 ; - -return modify_ldt (1 , &entry,sizeof (entry)); +if (tc->exp_errno) +TST_EXP_FAIL (modify_ldt (tc->tfunc, tc->ptr, tc->bytecount), + tc->exp_errno); +else +TST_EXP_POSITIVE (modify_ldt (tc->tfunc, tc->ptr, tc->bytecount)); }void setup (void ) { +int seg[4 ]; -tst_sig (FORK ,DEF_HANDLER , cleanup); - -TEST_PAUSE ; -} +create_segment (seg,sizeof (seg)); -void cleanup (void ) -{ + entry.contents =3 ; + entry.seg_not_present =0 ; + ptr =sbrk (0 ) +0xFFF ; + tcases[0 ].ptr = ptr; } -#elif HAVE_MODIFY_LDT -int main (void ) -{ -tst_brkm (TCONF , -NULL , -"modify_ldt is available but not tested on the platform than __i386__" ); -} +static struct tst_test test = { + .test = run, + .tcnt =ARRAY_SIZE (tcases), + .setup = setup, + .bufs = + (struct tst_buffers []){ + { &buf, .size =sizeof (struct user_desc ) }, + {}, + }, +};#else -int main (void ) -{ -tst_resm (TINFO ,"modify_ldt01 test only for ix86" ); -tst_exit (); -} - -#endif /* defined(__i386__) */ +TST_TEST_TCONF ("Test supported only on i386" ); +#endif /* __i386__ */ testcases/kernel/syscalls/modify_ldt/modify_ldt03.c deleted +0
-105@@ -1,105 +0,0 @@ -/* -* Copyright (c) 2014 Fujitsu Ltd. -* Author: Zeng Linggang <[email protected]> -* -* This program is free software; you can redistribute it and/or modify it -* under the terms of version 2 of the GNU General Public License as -* published by the Free Software Foundation. -* -* This program is distributed in the hope that it would be useful, but -* WITHOUT ANY WARRANTY; without even the implied warranty of -* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. -* -* You should have received a copy of the GNU General Public License along -* with this program. -*/ -/* -* DESCRIPTION -* Basic test for modify_ldt(2) using func=0 argument. -*/ - -#include "config.h" -#include "test.h" - -char *TCID ="modify_ldt03" ; -int TST_TOTAL =1 ; - -#if defined(__i386__) && defined(HAVE_MODIFY_LDT ) - -#ifdef HAVE_ASM_LDT_H -# include <asm/ldt.h> -#endif -extern int modify_ldt (int ,void *,unsigned long ); - -#include <asm/unistd.h> -#include <string.h> -#include <sys/wait.h> -#include <errno.h> -#include "safe_macros.h" - -#ifdef HAVE_STRUCT_USER_DESC -# define SIZE sizeof(struct user_desc) -#else -# define SIZE 16 -#endif - -static char buf[SIZE ]; -static void cleanup (void ); -static void setup (void ); - -int main (int ac,char **av) -{ -int lc; - -tst_parse_opts (ac, av,NULL ,NULL ); - -setup (); - -for (lc =0 ;TEST_LOOPING (lc); lc++) { - - tst_count =0 ; - -TEST (modify_ldt (0 , buf,SIZE )); - -if (TEST_RETURN <0 ) { -tst_resm (TFAIL |TTERRNO , -"modify_ldt() failed with errno: %s" , -strerror (TEST_ERRNO )); - }else { -tst_resm (TPASS ,"modify_ldt() tested success" ); - } - } - -cleanup (); -tst_exit (); -} - -static void setup (void ) -{ -tst_sig (NOFORK ,DEF_HANDLER , cleanup); - -TEST_PAUSE ; -} - -static void cleanup (void ) -{ -} - -#elif HAVE_MODIFY_LDT - -int main (void ) -{ -tst_brkm (TCONF , -NULL ,"modify_ldt is available but not tested on the platform than " -"__i386__" ); -} - -#else /* if defined(__i386__) */ - -int main (void ) -{ -tst_resm (TINFO ,"modify_ldt03 test only for ix86" ); -tst_exit (); -} - -#endif /* if defined(__i386__) */
Signature · 1 line
Mailing list info: https://lists.linux.it/listinfo/ltp
Re: [LTP] [PATCH v5 3/3] syscalls/modify_ldt01: Refactor into new API
Quoted 1 line · Ricardo B. Marlière
On Mon Mar 31, 2025 at 2:43 PM -03, rbm wrote:
(snip)
Quoted 6 lines
Quoted 3 lines
+ * - Fails with EINVAL, when writing (func=1) to an invalid pointer
+ * - Fails with EFAULT, when reading (func=0) from an invalid pointer
+ * - Passes when reading (func=0) from a valid pointerAh, I forgot to update the description...
/*\
* Verify that modify_ldt() calls:
*
* - Fails with EFAULT, when reading (func=0) from an invalid pointer
* - Passes when reading (func=0) from a valid pointer
* - Fails with EINVAL, when writing (func=1) to an invalid pointer
* - Fails with EINVAL, when writing (func=1) with an invalid bytecount value
* - Fails with EINVAL, when writing (func=1) an entry with invalid values
* - Fails with EINVAL, when writing (func=0x11) an entry with invalid values */
Thoughts?
- Ricardo.
Signature · 1 line
Mailing list info: https://lists.linux.it/listinfo/ltp