[LTP] [PATCH v8 1/3] syscalls/modify_ldt: Add lapi/ldt.h
Andrea Cervesato
andrea.cervesato@suse.com
Tue Apr 29 09:40:31 CEST 2025
Hi Ricardo,
On 4/8/25 13:26, Ricardo B. Marlière wrote:
> From: Ricardo B. Marlière <rbm@suse.com>
>
> Add a wrapper to modify_ldt and a fallback definition to struct user_desc,
> which are needed in a few tests and should be reused.
>
> Reviewed-by: Cyril Hrubis <chrubis@suse.cz>
> Reviewed-by: Andrea Cervesato <andrea.cervesato@suse.com>
> Signed-off-by: Ricardo B. Marlière <rbm@suse.com>
> ---
> include/lapi/ldt.h | 58 +++++++++++++++++++++++++++++++++
> testcases/cve/cve-2015-3290.c | 26 ++-------------
> testcases/cve/cve-2017-17053.c | 6 ++--
> testcases/kernel/syscalls/fork/fork05.c | 5 ++-
> 4 files changed, 64 insertions(+), 31 deletions(-)
>
> diff --git a/include/lapi/ldt.h b/include/lapi/ldt.h
> new file mode 100644
> index 0000000000000000000000000000000000000000..cfb98883633b4048babb93c83f09c6b413c004f6
> --- /dev/null
> +++ b/include/lapi/ldt.h
> @@ -0,0 +1,58 @@
> +// SPDX-License-Identifier: GPL-2.0-or-later
> +/*
> + * Copyright (c) 2025 SUSE LLC Ricardo B. Marlière <rbm@suse.com>
> + */
> +
> +#ifndef LAPI_LDT_H__
> +#define LAPI_LDT_H__
> +
> +#include "config.h"
> +#include "lapi/syscalls.h"
> +
> +#ifdef HAVE_ASM_LDT_H
> +#include <asm/ldt.h>
> +#else
> +struct user_desc {
> + unsigned int entry_number;
> + unsigned 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;
> +#ifdef __x86_64__
> + unsigned int lm : 1;
> +#endif /* __x86_64__ */
> +};
> +#endif /* HAVE_ASM_LDT_H */
> +
> +static inline int modify_ldt(int func, const struct user_desc *ptr,
> + unsigned long bytecount)
> +{
> + return tst_syscall(__NR_modify_ldt, func, ptr, bytecount);
> +}
> +
> +static inline 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);
> + else if (rval)
> + tst_brk_(file, lineno, TBROK | TERRNO,
> + "modify_ltd(%d, %p, %lu) invalid retval %i", func, ptr,
> + bytecount, rval);
The LTP/Kernel coding convention is that a statement using more than one
line needs to be surrounded by braces:
https://www.kernel.org/doc/html/latest/process/coding-style.html#indentation
The rest looks ok.
Reviewed-by: Andrea Cervesato <andrea.cervesato@suse.com>
- Andrea
More information about the ltp
mailing list