* Re: [PATCH v4 5/6] add listmount(2) syscall
From: Guenter Roeck @ 2024-01-11 23:57 UTC (permalink / raw)
To: Linus Torvalds, Yoshinori Sato, Rich Felker,
John Paul Adrian Glaubitz
Cc: Miklos Szeredi, linux-fsdevel, linux-kernel, linux-api, linux-man,
linux-security-module, Karel Zak, Ian Kent, David Howells,
Al Viro, Christian Brauner, Amir Goldstein, Matthew House,
Florian Weimer, Arnd Bergmann
In-Reply-To: <CAHk-=wjh6Cypo8WC-McXgSzCaou3UXccxB+7PVeSuGR8AjCphg@mail.gmail.com>
On 1/11/24 12:14, Linus Torvalds wrote:
> On Thu, 11 Jan 2024 at 10:57, Guenter Roeck <linux@roeck-us.net> wrote:
>>
>> Any variance of put_user() with &buf[ctr] or buf + ctr fails
>> if ctr is a variable and permitted to be != 0.
>
> Crazy. But the 64-bit put_user() is a bit special and tends to require
> more registers (the 64-bit value is passed in two registers), so that
> probably then results in the ICE.
>
> Side note: looking at the SH version of __put_user_u64(), I think it's
> buggy and is missing the exception handler for the second 32-bit move.
> I dunno, I don't read sh asm, but it looks suspicious.
>
I wonder if something may be wrong with the definition and use of __m
for u64 accesses. The code below also fixes the build problem.
But then I really don't know what
struct __large_struct { unsigned long buf[100]; };
#define __m(x) (*(struct __large_struct __user *)(x))
is supposed to be doing in the first place, and I still don't understand
why the problem only shows up with CONFIG_MMU=n.
Guenter
---
diff --git a/arch/sh/include/asm/uaccess_32.h b/arch/sh/include/asm/uaccess_32.h
index 5d7ddc092afd..f0451a37b6ff 100644
--- a/arch/sh/include/asm/uaccess_32.h
+++ b/arch/sh/include/asm/uaccess_32.h
@@ -196,7 +196,7 @@ __asm__ __volatile__( \
".long 1b, 3b\n\t" \
".previous" \
: "=r" (retval) \
- : "r" (val), "m" (__m(addr)), "i" (-EFAULT), "0" (retval) \
+ : "r" (val), "m" (*(u64 *)(addr)), "i" (-EFAULT), "0" (retval) \
: "memory"); })
#else
#define __put_user_u64(val,addr,retval) \
@@ -218,7 +218,7 @@ __asm__ __volatile__( \
".long 1b, 3b\n\t" \
".previous" \
: "=r" (retval) \
- : "r" (val), "m" (__m(addr)), "i" (-EFAULT), "0" (retval) \
+ : "r" (val), "m" (*(u64 *)(addr)), "i" (-EFAULT), "0" (retval) \
: "memory"); })
#endif
^ permalink raw reply related
* Re: [PATCH v4 5/6] add listmount(2) syscall
From: Arnd Bergmann @ 2024-01-11 23:01 UTC (permalink / raw)
To: Linus Torvalds, Guenter Roeck, Yoshinori Sato, Rich Felker,
John Paul Adrian Glaubitz
Cc: Miklos Szeredi, linux-fsdevel, linux-kernel, linux-api, linux-man,
linux-security-module, Karel Zak, Ian Kent, David Howells,
Alexander Viro, Christian Brauner, Amir Goldstein, Matthew House,
Florian Weimer
In-Reply-To: <CAHk-=wjh6Cypo8WC-McXgSzCaou3UXccxB+7PVeSuGR8AjCphg@mail.gmail.com>
On Thu, Jan 11, 2024, at 21:14, Linus Torvalds wrote:
> The SH put_user64() needs to be looked at too, but in the meantime,
> maybe something like this fixes the problems with listmount?
I tried changing it to use the generic memcpy() based uaccess
that m68k-nommu and riscv-nommu use, which also avoids the
build failure. I still run into other unrelated build issues
on arch/sh, so I'm not sure if this is a sufficient fix.
Arnd
diff --git a/arch/sh/Kconfig b/arch/sh/Kconfig
index 7500521b2b98..2cc3a541e231 100644
--- a/arch/sh/Kconfig
+++ b/arch/sh/Kconfig
@@ -73,6 +73,7 @@ config SUPERH
select PERF_USE_VMALLOC
select RTC_LIB
select SPARSE_IRQ
+ select UACCESS_MEMCPY if !MMU
select TRACE_IRQFLAGS_SUPPORT
help
The SuperH is a RISC processor targeted for use in embedded systems
diff --git a/arch/sh/include/asm/uaccess.h b/arch/sh/include/asm/uaccess.h
index a79609eb14be..b42764d55901 100644
--- a/arch/sh/include/asm/uaccess.h
+++ b/arch/sh/include/asm/uaccess.h
@@ -2,6 +2,7 @@
#ifndef __ASM_SH_UACCESS_H
#define __ASM_SH_UACCESS_H
+#ifdef CONFIG_MMU
#include <asm/extable.h>
#include <asm-generic/access_ok.h>
@@ -130,4 +131,8 @@ struct mem_access {
int handle_unaligned_access(insn_size_t instruction, struct pt_regs *regs,
struct mem_access *ma, int, unsigned long address);
+#else
+#include <asm-generic/uaccess.h>
+#endif
+
#endif /* __ASM_SH_UACCESS_H */
diff --git a/arch/sh/include/asm/uaccess_32.h b/arch/sh/include/asm/uaccess_32.h
index 5d7ddc092afd..e053f2fd245c 100644
--- a/arch/sh/include/asm/uaccess_32.h
+++ b/arch/sh/include/asm/uaccess_32.h
@@ -35,7 +35,6 @@ do { \
} \
} while (0)
-#ifdef CONFIG_MMU
#define __get_user_asm(x, addr, err, insn) \
({ \
__asm__ __volatile__( \
@@ -56,16 +55,6 @@ __asm__ __volatile__( \
".previous" \
:"=&r" (err), "=&r" (x) \
:"m" (__m(addr)), "i" (-EFAULT), "0" (err)); })
-#else
-#define __get_user_asm(x, addr, err, insn) \
-do { \
- __asm__ __volatile__ ( \
- "mov." insn " %1, %0\n\t" \
- : "=&r" (x) \
- : "m" (__m(addr)) \
- ); \
-} while (0)
-#endif /* CONFIG_MMU */
extern void __get_user_unknown(void);
@@ -140,7 +129,6 @@ do { \
} \
} while (0)
-#ifdef CONFIG_MMU
#define __put_user_asm(x, addr, err, insn) \
do { \
__asm__ __volatile__ ( \
@@ -164,17 +152,6 @@ do { \
: "memory" \
); \
} while (0)
-#else
-#define __put_user_asm(x, addr, err, insn) \
-do { \
- __asm__ __volatile__ ( \
- "mov." insn " %0, %1\n\t" \
- : /* no outputs */ \
- : "r" (x), "m" (__m(addr)) \
- : "memory" \
- ); \
-} while (0)
-#endif /* CONFIG_MMU */
#if defined(CONFIG_CPU_LITTLE_ENDIAN)
#define __put_user_u64(val,addr,retval) \
^ permalink raw reply related
* Re: [PATCH v4 5/6] add listmount(2) syscall
From: Linus Torvalds @ 2024-01-11 20:14 UTC (permalink / raw)
To: Guenter Roeck, Yoshinori Sato, Rich Felker,
John Paul Adrian Glaubitz
Cc: Miklos Szeredi, linux-fsdevel, linux-kernel, linux-api, linux-man,
linux-security-module, Karel Zak, Ian Kent, David Howells,
Al Viro, Christian Brauner, Amir Goldstein, Matthew House,
Florian Weimer, Arnd Bergmann
In-Reply-To: <2f595f28-7fcd-4196-a0b1-6598781530b9@roeck-us.net>
[-- Attachment #1: Type: text/plain, Size: 2074 bytes --]
On Thu, 11 Jan 2024 at 10:57, Guenter Roeck <linux@roeck-us.net> wrote:
>
> Any variance of put_user() with &buf[ctr] or buf + ctr fails
> if ctr is a variable and permitted to be != 0.
Crazy. But the 64-bit put_user() is a bit special and tends to require
more registers (the 64-bit value is passed in two registers), so that
probably then results in the ICE.
Side note: looking at the SH version of __put_user_u64(), I think it's
buggy and is missing the exception handler for the second 32-bit move.
I dunno, I don't read sh asm, but it looks suspicious.
> The following works. Would this be acceptable ?
It might be very easy to trigger this once again if somebody goes "that's silly"
That said, I also absolutely detest the "error handling" in that
function. It's horrible.
Noticing the user access error in the middle is just sad, and if that
was just handled better and at least the range was checked first, the
overflow error couldn't happen and checking for it is thus pointless.
And looking at it all, it really looks like the whole interface is
broken. The "bufsize" argument isn't the size of the buffer at all.
It's the number of entries.
Extra confusingly, in the *other* system call, bufsize is in fact the
size of the buffer.
And the 'ctr' overflow checking is doubly garbage, because the only
reason *that* can happen is that we didn't check the incoming
arguments properly.
Same goes for the whole array_index_nospec() - it's pointless, because
the user controls what that code checks against anyway, so there's no
point to trying to manage some range checking.
The only range checking there that matters would be the one that
put_user() has to do against the address space size, but that's done
by put_user().
End result: that thing needs a rewrite.
The SH put_user64() needs to be looked at too, but in the meantime,
maybe something like this fixes the problems with listmount?
NOTE! ENTIRELY untested, but that naming and lack of argument sanity
checking really is horrendous. We should have caught this earlier.
Linus
[-- Attachment #2: patch.diff --]
[-- Type: text/x-patch, Size: 2265 bytes --]
fs/namespace.c | 31 +++++++++++++++++--------------
1 file changed, 17 insertions(+), 14 deletions(-)
diff --git a/fs/namespace.c b/fs/namespace.c
index ef1fd6829814..df74f4769733 100644
--- a/fs/namespace.c
+++ b/fs/namespace.c
@@ -5043,12 +5043,17 @@ static struct mount *listmnt_next(struct mount *curr)
}
static ssize_t do_listmount(struct mount *first, struct path *orig, u64 mnt_id,
- u64 __user *buf, size_t bufsize,
+ u64 __user *buf, size_t nentries,
const struct path *root)
{
struct mount *r;
- ssize_t ctr;
- int err;
+ const size_t maxentries = (size_t)-1 >> 3;
+ ssize_t ret;
+
+ if (unlikely(nentries > maxentries))
+ return -EFAULT;
+ if (!access_ok(buf, nentries * sizeof(*buf)))
+ return -EFAULT;
/*
* Don't trigger audit denials. We just want to determine what
@@ -5058,26 +5063,24 @@ static ssize_t do_listmount(struct mount *first, struct path *orig, u64 mnt_id,
!ns_capable_noaudit(&init_user_ns, CAP_SYS_ADMIN))
return -EPERM;
- err = security_sb_statfs(orig->dentry);
- if (err)
- return err;
+ ret = security_sb_statfs(orig->dentry);
+ if (ret)
+ return ret;
- for (ctr = 0, r = first; r && ctr < bufsize; r = listmnt_next(r)) {
+ for (ret = 0, r = first; r && nentries; r = listmnt_next(r)) {
if (r->mnt_id_unique == mnt_id)
continue;
if (!is_path_reachable(r, r->mnt.mnt_root, orig))
continue;
- ctr = array_index_nospec(ctr, bufsize);
- if (put_user(r->mnt_id_unique, buf + ctr))
+ if (put_user(r->mnt_id_unique, buf))
return -EFAULT;
- if (check_add_overflow(ctr, 1, &ctr))
- return -ERANGE;
+ buf++, ret++; nentries--;
}
- return ctr;
+ return ret;
}
SYSCALL_DEFINE4(listmount, const struct mnt_id_req __user *, req,
- u64 __user *, buf, size_t, bufsize, unsigned int, flags)
+ u64 __user *, buf, size_t, nentries, unsigned int, flags)
{
struct mnt_namespace *ns = current->nsproxy->mnt_ns;
struct mnt_id_req kreq;
@@ -5111,7 +5114,7 @@ SYSCALL_DEFINE4(listmount, const struct mnt_id_req __user *, req,
else
first = mnt_find_id_at(ns, last_mnt_id + 1);
- ret = do_listmount(first, &orig, mnt_id, buf, bufsize, &root);
+ ret = do_listmount(first, &orig, mnt_id, buf, nentries, &root);
err:
path_put(&root);
up_read(&namespace_sem);
^ permalink raw reply related
* Re: [PATCH v4 5/6] add listmount(2) syscall
From: Guenter Roeck @ 2024-01-11 18:57 UTC (permalink / raw)
To: Linus Torvalds
Cc: Miklos Szeredi, linux-fsdevel, linux-kernel, linux-api, linux-man,
linux-security-module, Karel Zak, Ian Kent, David Howells,
Al Viro, Christian Brauner, Amir Goldstein, Matthew House,
Florian Weimer, Arnd Bergmann
In-Reply-To: <CAHk-=wjdW-4s6Kpa4izJ2D=yPdCje6Ta=eQxxQG6e2SkP42vnw@mail.gmail.com>
On 1/10/24 16:32, Linus Torvalds wrote:
> On Wed, 10 Jan 2024 at 14:23, Guenter Roeck <linux@roeck-us.net> wrote:
>>
>> with this patch in the tree, all sh4 builds fail with ICE.
>>
>> during RTL pass: final
>> In file included from fs/namespace.c:11:
>> fs/namespace.c: In function '__se_sys_listmount':
>> include/linux/syscalls.h:258:9: internal compiler error: in change_address_1, at emit-rtl.c:2275
>
> We do have those very ugly SYSCALL_DEFINEx() macros, but I'm not
> seeing _anything_ that would be odd about the listmount case.
>
> And the "__se_sys" thing in particular is just a fairly trivial wrapper.
>
> It does use that asmlinkage_protect() thing, and it is unquestionably
> horrendously ugly (staring too long at <linux/syscalls.h> has been
> known to cause madness and despair), but we do that for *every* single
> system call and I don't see why the new listmount entry would be
> different.
>
It isn't the syscall. The following hack avoids the problem.
diff --git a/fs/namespace.c b/fs/namespace.c
index ef1fd6829814..28fe2a55bd94 100644
--- a/fs/namespace.c
+++ b/fs/namespace.c
@@ -5070,8 +5070,10 @@ static ssize_t do_listmount(struct mount *first, struct path *orig, u64 mnt_id,
ctr = array_index_nospec(ctr, bufsize);
if (put_user(r->mnt_id_unique, buf + ctr))
return -EFAULT;
+#if 0
if (check_add_overflow(ctr, 1, &ctr))
return -ERANGE;
+#endif
But it isn't check_add_overflow() either. This "helps" as well.
diff --git a/fs/namespace.c b/fs/namespace.c
index ef1fd6829814..b53cb2f13530 100644
--- a/fs/namespace.c
+++ b/fs/namespace.c
@@ -5068,8 +5068,10 @@ static ssize_t do_listmount(struct mount *first, struct path *orig, u64 mnt_id,
if (!is_path_reachable(r, r->mnt.mnt_root, orig))
continue;
ctr = array_index_nospec(ctr, bufsize);
+#if 0
if (put_user(r->mnt_id_unique, buf + ctr))
return -EFAULT;
+#endif
if (check_add_overflow(ctr, 1, &ctr))
return -ERANGE;
Any variance of put_user() with &buf[ctr] or buf + ctr fails
if ctr is a variable and permitted to be != 0. For example,
commenting out the call to check_add_overflow() and starting
the loop with ctr = 1 also triggers the problem, as does replacing
the call to check_add_overflow() with ctr++;. Using a temporary
variable such as in
u64 __user *pbuf;
...
pbuf = buf + ctr;
if (put_user(r->mnt_id_unique, pbuf))
return -EFAULT;
doesn't help either. But this does:
- if (put_user(r->mnt_id_unique, buf + ctr))
+ if (put_user(r->mnt_id_unique, (u32 *)(buf + ctr)))
and "buf + 17" as well as "&buf[17]" work as well. Essentially,
every combination of "buf + ctr" or "&buf[ctr]" fails if buf
is u64* and ctr is a variable.
The following works. Would this be acceptable ?
diff --git a/fs/namespace.c b/fs/namespace.c
index ef1fd6829814..dc0f844205d9 100644
--- a/fs/namespace.c
+++ b/fs/namespace.c
@@ -5068,10 +5068,11 @@ static ssize_t do_listmount(struct mount *first, struct path *orig, u64 mnt_id,
if (!is_path_reachable(r, r->mnt.mnt_root, orig))
continue;
ctr = array_index_nospec(ctr, bufsize);
- if (put_user(r->mnt_id_unique, buf + ctr))
+ if (put_user(r->mnt_id_unique, buf))
return -EFAULT;
if (check_add_overflow(ctr, 1, &ctr))
return -ERANGE;
+ buf++;
}
return ctr;
}
Guenter
^ permalink raw reply related
* Re: Robust mutex ABI problem (kernel docs regression)
From: Rich Felker @ 2024-01-11 16:59 UTC (permalink / raw)
To: libc-alpha, musl, linux-api
In-Reply-To: <20240111164620.GS4163@brightrain.aerifal.cx>
On Thu, Jan 11, 2024 at 11:46:21AM -0500, Rich Felker wrote:
> It came to my attention while reviewing some proposals for additional
> error checking in musl libc that the kernel folks introduced a quiet
> regression in the futex ABI for robust mutexes.
>
> Prior to kernel commit 9c40365a65d62d7c06a95fb331b3442cb02d2fd9, bit
> 29 of the futex lock word was reserved, meaning it could never be part
> of a TID. This allowed both glibc and musl to use special values like
> (glibc):
>
> /* Magic cookie representing robust mutex with dead owner. */
> #define PTHREAD_MUTEX_INCONSISTENT INT_MAX
> /* Magic cookie representing not recoverable robust mutex. */
> #define PTHREAD_MUTEX_NOTRECOVERABLE (INT_MAX - 1)
>
> to represent special states needed for robust mutex consistency
> handling, without the risk that, when masked with FUTEX_TID_MASK
> (0x3fffffff), they could be equal to the TID of a real task, which
> could result in the kernel robustlist-processing mishandling them.
On further investigation, it looks like glibc is not using these
directly in the futex word but keeping them in a separate owner field
protected by the lock. I'll try to follow up with what it actually is
doing, but I don't see a way, without at least having one reserved
value in the low 30 bits (FUTEX_TID_MASK), to represent a lock that
cannot be taken by any task. I'm guessing glibc does some dance of
actually taking the lock then releasing it in this case..?
On musl we keep the entire state in the lock word so that it's all
atomic.
Rich
^ permalink raw reply
* Robust mutex ABI problem (kernel docs regression)
From: Rich Felker @ 2024-01-11 16:46 UTC (permalink / raw)
To: libc-alpha, musl, linux-api
It came to my attention while reviewing some proposals for additional
error checking in musl libc that the kernel folks introduced a quiet
regression in the futex ABI for robust mutexes.
Prior to kernel commit 9c40365a65d62d7c06a95fb331b3442cb02d2fd9, bit
29 of the futex lock word was reserved, meaning it could never be part
of a TID. This allowed both glibc and musl to use special values like
(glibc):
/* Magic cookie representing robust mutex with dead owner. */
#define PTHREAD_MUTEX_INCONSISTENT INT_MAX
/* Magic cookie representing not recoverable robust mutex. */
#define PTHREAD_MUTEX_NOTRECOVERABLE (INT_MAX - 1)
to represent special states needed for robust mutex consistency
handling, without the risk that, when masked with FUTEX_TID_MASK
(0x3fffffff), they could be equal to the TID of a real task, which
could result in the kernel robustlist-processing mishandling them.
In practice this is only a documentation regression. The real limit on
TIDs is well below that, at something like 22-bit last I checked.
However to be future-proof, and as other systems may implement the
Linux API/ABI (e.g. things like WSL1, FreeBSD Linux syscall layer,
etc.), I believe it's important that the documented interface be
compatible with the way it actually needs to be used here. This means
either bit 29 should have its reserved status restored, or there
should be a guarantee that the values 0x3fffffff and 0x3ffffffe are
reserved and compare not-equal to any actual TID.
Depending on how folks want to proceed with this, I can propose a
patch to the documentation, or leave that to others.
Rich
^ permalink raw reply
* Re: 回复: [PATCH] selftests/landlock:Fix two build issues
From: Mickaël Salaün @ 2024-01-11 14:05 UTC (permalink / raw)
To: Huyadi
Cc: jmorris@namei.org, serge@hallyn.com, shuah@kernel.org,
mathieu.desnoyers@efficios.com, linux-api@vger.kernel.org,
linux-kernel@vger.kernel.org,
linux-security-module@vger.kernel.org,
linux-kselftest@vger.kernel.org, 514118380@qq.com
In-Reply-To: <9820400d6083428bbab2dfe5d5682d19@h3c.com>
On Thu, Jan 11, 2024 at 02:34:08AM +0000, Huyadi wrote:
>
> ->On Wed, Jan 10, 2024 at 03:08:54PM +0800, Hu Yadi wrote:
> >> From: "Hu.Yadi" <hu.yadi@h3c.com>
> >>
> >> Two issues comes up while building selftest/landlock:
> >>
> >> the first one is as to gettid
> >>
> >> net_test.c: In function ‘set_service’:
> >> net_test.c:91:45: warning: implicit declaration of function ‘gettid’; did you mean ‘getgid’? [-Wimplicit-function-declaration]
> >> "_selftests-landlock-net-tid%d-index%d", gettid(),
> >> ^~~~~~
> >> getgid
> >> net_test.c:(.text+0x4e0): undefined reference to `gettid'
> >>
> >> the second is compiler error
> >> gcc -Wall -O2 -isystem fs_test.c -lcap -o /home/linux/tools/testing/selftests/landlock/fs_test
> >> fs_test.c:4575:9: error: initializer element is not constant
> >> .mnt = mnt_tmp,
> >> ^~~~~~~
> >
> >What is the version of GCC (and headers) and on which system (and
> >version) are you building these tests?
>
> gcc 7.3 / glibc-2.28/ kernel 4.19/ OpenEulor20.03
These are old versions. You should mention in the commit message which
version of glibc added gettid().
>
> >>
> >> this patch is to fix them
> >>
> >> Signed-off-by: Hu.Yadi <hu.yadi@h3c.com>
> >> Suggested-by: Jiao <jiaoxupo@h3c.com>
> >> Reviewed-by:Berlin <berlin@h3c.com>
> >> ---
> >> tools/testing/selftests/landlock/fs_test.c | 5 ++++-
> >> tools/testing/selftests/landlock/net_test.c | 3 +--
> >> 2 files changed, 5 insertions(+), 3 deletions(-)
> >>
> >> diff --git a/tools/testing/selftests/landlock/fs_test.c
> >> b/tools/testing/selftests/landlock/fs_test.c
> >> index 18e1f86a6234..93eb40a09073 100644
> >> --- a/tools/testing/selftests/landlock/fs_test.c
> >> +++ b/tools/testing/selftests/landlock/fs_test.c
> >> @@ -4572,7 +4572,10 @@ FIXTURE_VARIANT(layout3_fs)
> >> /* clang-format off */
> >> FIXTURE_VARIANT_ADD(layout3_fs, tmpfs) {
> >> /* clang-format on */
> >> - .mnt = mnt_tmp,
Can you just cast mnt_tmp? It exists to avoid such duplicate code.
> >> + .mnt = {
> >> + .type = "tmpfs",
> >> + .data = "size=4m,mode=700",
> >
> >When applying this patch we get: "space before tab in indent"
>
> Sorry for inconvenient, I'll resend it v2 after checkpatch.pl shows no error.
>
> >> + },
> >> .file_path = file1_s1d1,
> >> };
> >>
> >> diff --git a/tools/testing/selftests/landlock/net_test.c
> >> b/tools/testing/selftests/landlock/net_test.c
> >> index 929e21c4db05..8fb357de8c55 100644
> >> --- a/tools/testing/selftests/landlock/net_test.c
> >> +++ b/tools/testing/selftests/landlock/net_test.c
> >> @@ -18,7 +18,6 @@
> >> #include <sys/prctl.h>
> >> #include <sys/socket.h>
> >> #include <sys/un.h>
> >> -
> >> #include "common.h"
> >>
> >> const short sock_port_start = (1 << 10); @@ -88,7 +87,7 @@ static int
> >> set_service(struct service_fixture *const srv,
> >> case AF_UNIX:
> >> srv->unix_addr.sun_family = prot.domain;
> >> sprintf(srv->unix_addr.sun_path,
> >> - "_selftests-landlock-net-tid%d-index%d", gettid(),
> >> + "_selftests-landlock-net-tid%ld-index%d", syscall(SYS_gettid),
> >
> >You sent another patch that "replace SYS_<syscall> with __NR_<syscall>".
> >Why not here?
> >
> >Please follow the same approach:
> >https://git.kernel.org/stable/c/87129ef13603ae46c82bcd09eed948acf0506dbb
Can you please add a getpid() helper like for renameat2() in this
commit?
Also, all Landlock-related code is formatted with clang-format. You can
do it with clang-format -i tools/testing/selftests/landlock/*.[ch]
>
> Got it, I'll resend it v2 including the fix
>
> >> index);
> >> srv->unix_addr_len = SUN_LEN(&srv->unix_addr);
> >> srv->unix_addr.sun_path[0] = '\0';
> >> --
> >> 2.23.0
> >>
> >>
>
>
^ permalink raw reply
* Re: [PATCH v4] selftests/move_mount_set_group:Make tests build with old libc
From: Mickaël Salaün @ 2024-01-11 13:27 UTC (permalink / raw)
To: Hu Yadi
Cc: jmorris, serge, shuah, mathieu.desnoyers, linux-api, linux-kernel,
linux-security-module, linux-kselftest, 514118380,
Christian Brauner, linux-fsdevel, Shuah Khan
In-Reply-To: <20240111113229.10820-1-hu.yadi@h3c.com>
On Thu, Jan 11, 2024 at 07:32:29PM +0800, Hu Yadi wrote:
> From: "Hu.Yadi" <hu.yadi@h3c.com>
>
> Replace SYS_<syscall> with __NR_<syscall>. Using the __NR_<syscall>
> notation, provided by UAPI, is useful to build tests on systems without
> the SYS_<syscall> definitions.
>
> Replace SYS_move_mount with __NR_move_mount
>
> Similar changes: commit 87129ef13603 ("selftests/landlock: Make tests build with old libc")
>
> Acked-by: Mickaël Salaün <mic@digikod.net>
Sorry, it should have been Reviewed-by: Mickaël Salaün <mic@digikod.net>
Also, this is maintained by the VFS maintainers. I CCed three relevant addresses.
> Signed-off-by: Hu.Yadi <hu.yadi@h3c.com>
> Suggested-by: Jiao <jiaoxupo@h3c.com>
> Reviewed-by: Berlin <berlin@h3c.com>
> ---
> Changes v4 -> v3:
> - Adjust comments for consistent
> - Add Acked-by
> Changes v2 -> v3:
> - Adjust comments
> Changes v1 -> v2:
> - Fix mail of Suggested-by and Reviewed-by
>
> .../move_mount_set_group/move_mount_set_group_test.c | 4 ++--
> 1 file changed, 2 insertions(+), 2 deletions(-)
>
> diff --git a/tools/testing/selftests/move_mount_set_group/move_mount_set_group_test.c b/tools/testing/selftests/move_mount_set_group/move_mount_set_group_test.c
> index 50ed5d475dd1..bcf51d785a37 100644
> --- a/tools/testing/selftests/move_mount_set_group/move_mount_set_group_test.c
> +++ b/tools/testing/selftests/move_mount_set_group/move_mount_set_group_test.c
> @@ -218,7 +218,7 @@ static bool move_mount_set_group_supported(void)
> if (mount(NULL, SET_GROUP_FROM, NULL, MS_SHARED, 0))
> return -1;
>
> - ret = syscall(SYS_move_mount, AT_FDCWD, SET_GROUP_FROM,
> + ret = syscall(__NR_move_mount, AT_FDCWD, SET_GROUP_FROM,
> AT_FDCWD, SET_GROUP_TO, MOVE_MOUNT_SET_GROUP);
> umount2("/tmp", MNT_DETACH);
>
> @@ -363,7 +363,7 @@ TEST_F(move_mount_set_group, complex_sharing_copying)
> CLONE_VM | CLONE_FILES); ASSERT_GT(pid, 0);
> ASSERT_EQ(wait_for_pid(pid), 0);
>
> - ASSERT_EQ(syscall(SYS_move_mount, ca_from.mntfd, "",
> + ASSERT_EQ(syscall(__NR_move_mount, ca_from.mntfd, "",
> ca_to.mntfd, "", MOVE_MOUNT_SET_GROUP
> | MOVE_MOUNT_F_EMPTY_PATH | MOVE_MOUNT_T_EMPTY_PATH),
> 0);
> --
> 2.23.0
>
>
^ permalink raw reply
* [PATCH v4] selftests/move_mount_set_group:Make tests build with old libc
From: Hu Yadi @ 2024-01-11 11:32 UTC (permalink / raw)
To: jmorris, serge, shuah, mathieu.desnoyers, mic
Cc: linux-api, linux-kernel, linux-security-module, linux-kselftest,
514118380, Hu.Yadi
From: "Hu.Yadi" <hu.yadi@h3c.com>
Replace SYS_<syscall> with __NR_<syscall>. Using the __NR_<syscall>
notation, provided by UAPI, is useful to build tests on systems without
the SYS_<syscall> definitions.
Replace SYS_move_mount with __NR_move_mount
Similar changes: commit 87129ef13603 ("selftests/landlock: Make tests build with old libc")
Acked-by: Mickaël Salaün <mic@digikod.net>
Signed-off-by: Hu.Yadi <hu.yadi@h3c.com>
Suggested-by: Jiao <jiaoxupo@h3c.com>
Reviewed-by: Berlin <berlin@h3c.com>
---
Changes v4 -> v3:
- Adjust comments for consistent
- Add Acked-by
Changes v2 -> v3:
- Adjust comments
Changes v1 -> v2:
- Fix mail of Suggested-by and Reviewed-by
.../move_mount_set_group/move_mount_set_group_test.c | 4 ++--
1 file changed, 2 insertions(+), 2 deletions(-)
diff --git a/tools/testing/selftests/move_mount_set_group/move_mount_set_group_test.c b/tools/testing/selftests/move_mount_set_group/move_mount_set_group_test.c
index 50ed5d475dd1..bcf51d785a37 100644
--- a/tools/testing/selftests/move_mount_set_group/move_mount_set_group_test.c
+++ b/tools/testing/selftests/move_mount_set_group/move_mount_set_group_test.c
@@ -218,7 +218,7 @@ static bool move_mount_set_group_supported(void)
if (mount(NULL, SET_GROUP_FROM, NULL, MS_SHARED, 0))
return -1;
- ret = syscall(SYS_move_mount, AT_FDCWD, SET_GROUP_FROM,
+ ret = syscall(__NR_move_mount, AT_FDCWD, SET_GROUP_FROM,
AT_FDCWD, SET_GROUP_TO, MOVE_MOUNT_SET_GROUP);
umount2("/tmp", MNT_DETACH);
@@ -363,7 +363,7 @@ TEST_F(move_mount_set_group, complex_sharing_copying)
CLONE_VM | CLONE_FILES); ASSERT_GT(pid, 0);
ASSERT_EQ(wait_for_pid(pid), 0);
- ASSERT_EQ(syscall(SYS_move_mount, ca_from.mntfd, "",
+ ASSERT_EQ(syscall(__NR_move_mount, ca_from.mntfd, "",
ca_to.mntfd, "", MOVE_MOUNT_SET_GROUP
| MOVE_MOUNT_F_EMPTY_PATH | MOVE_MOUNT_T_EMPTY_PATH),
0);
--
2.23.0
^ permalink raw reply related
* Re: 回复: [PATCH v2] selftests/move_mount_set_group:Make tests build with old libc
From: Mickaël Salaün @ 2024-01-11 11:13 UTC (permalink / raw)
To: Huyadi
Cc: jmorris@namei.org, serge@hallyn.com, shuah@kernel.org,
mathieu.desnoyers@efficios.com, linux-api@vger.kernel.org,
linux-kernel@vger.kernel.org,
linux-security-module@vger.kernel.org,
linux-kselftest@vger.kernel.org, 514118380@qq.com
In-Reply-To: <6c398076d4624691a97766bad168d975@h3c.com>
On Thu, Jan 11, 2024 at 02:25:03AM +0000, Huyadi wrote:
>
> >On Wed, Jan 10, 2024 at 03:29:01PM +0800, Hu Yadi wrote:
> >> From: "Hu.Yadi" <hu.yadi@h3c.com>
> >>
> >> Replace SYS_<syscall> with __NR_<syscall>. Using the __NR_<syscall>
> >> notation, provided by UAPI, is useful to build tests on systems
> >> without the SYS_<syscall> definitions.
> >
> >This looks a lot like that...
> >https://git.kernel.org/stable/c/87129ef13603ae46c82bcd09eed948acf0506dbb
>
> Yes, I picked up comments from above commit in order for consistent,
> I would send v3 patch if it is inappropriate.
This is not an issue at all to use the same wording if it makes sense.
Actually, the description of v3 is less explanatory. It might just be
appropriate to reference past similar work. That would justify your
work, add a precedent, and if there is any issue we could fix both
changes.
You can append this to the commit message (with the v2 description):
Similar changes: commit 87129ef13603 ("selftests/landlock: Make tests
build with old libc")
Acked-by: Mickaël Salaün <mic@digikod.net>
>
> >>
> >> Replace SYS_move_mount with __NR_move_mount
> >>
> >> Signed-off-by: Hu.Yadi <hu.yadi@h3c.com> Suggested-by:Jiao
> >> <jiaoxupo@h3c.com> Reviewed-by:Berlin <berlin@h3c.com>
> >> ---
> >> Changes v1 -> v2:
> >> - Fix mail of Suggested-by and Reviewed-by
> >>
> >> .../move_mount_set_group/move_mount_set_group_test.c | 4 ++--
> >> 1 file changed, 2 insertions(+), 2 deletions(-)
> >>
> >> diff --git
> >> a/tools/testing/selftests/move_mount_set_group/move_mount_set_group_te
> >> st.c
> >> b/tools/testing/selftests/move_mount_set_group/move_mount_set_group_te
> >> st.c index 50ed5d475dd1..bcf51d785a37 100644
> >> ---
> >> a/tools/testing/selftests/move_mount_set_group/move_mount_set_group_te
> >> st.c
> >> +++ b/tools/testing/selftests/move_mount_set_group/move_mount_set_grou
> >> +++ p_test.c
> >> @@ -218,7 +218,7 @@ static bool move_mount_set_group_supported(void)
> >> if (mount(NULL, SET_GROUP_FROM, NULL, MS_SHARED, 0))
> >> return -1;
> >>
> >> - ret = syscall(SYS_move_mount, AT_FDCWD, SET_GROUP_FROM,
> >> + ret = syscall(__NR_move_mount, AT_FDCWD, SET_GROUP_FROM,
> >> AT_FDCWD, SET_GROUP_TO, MOVE_MOUNT_SET_GROUP);
> >> umount2("/tmp", MNT_DETACH);
> >>
> >> @@ -363,7 +363,7 @@ TEST_F(move_mount_set_group, complex_sharing_copying)
> >> CLONE_VM | CLONE_FILES); ASSERT_GT(pid, 0);
> >> ASSERT_EQ(wait_for_pid(pid), 0);
> >>
> >> - ASSERT_EQ(syscall(SYS_move_mount, ca_from.mntfd, "",
> >> + ASSERT_EQ(syscall(__NR_move_mount, ca_from.mntfd, "",
> >> ca_to.mntfd, "", MOVE_MOUNT_SET_GROUP
> >> | MOVE_MOUNT_F_EMPTY_PATH | MOVE_MOUNT_T_EMPTY_PATH),
> >> 0);
> >> --
> >> 2.23.0
> >>
^ permalink raw reply
* Re: [PATCH v3] posix-timers: add multi_clock_gettime system call
From: Richard Cochran @ 2024-01-11 7:31 UTC (permalink / raw)
To: Arnd Bergmann
Cc: Sagi Maimon, Andy Lutomirski, tglx, Ingo Molnar, Borislav Petkov,
Dave Hansen, x86, H. Peter Anvin, Geert Uytterhoeven,
Peter Zijlstra, Johannes Weiner, Sohil Mehta, Rick Edgecombe,
Nhat Pham, Palmer Dabbelt, Kees Cook, Alexey Gladkov,
Mark Rutland, linux-kernel, linux-api, Linux-Arch, Netdev
In-Reply-To: <84d8e9d7-09ce-4781-8dfa-a74bb0955ae8@app.fastmail.com>
On Tue, Jan 02, 2024 at 12:29:59PM +0100, Arnd Bergmann wrote:
> I think Andy's suggestion of exposing time offsets instead
> of absolute times would actually achieve that: If the
> interface is changed to return the offset against
> CLOCK_MONOTONIC, CLOCK_MONOTONIC_RAW or CLOCK_BOOTTIME
> (not sure what is best here), then the new syscall can use
> getcrosststamp() where supported for the best results or
> fall back to gettimex64() or gettime64() otherwise to
> provide a consistent user interface.
Yes, it makes more sense to provide the offset, since that is what the
user needs in the end.
Can we change the name of the system call to "clock compare"?
int clock_compare(clockid_t a, clockid_t b,
int64_t *offset, int64_t *error);
returns: zero or error code,
offset = a - b
error = maximum error due to asymmetry
If clocks a and b are both System-V clocks, then *error=0 and *offset
can be returned directly from the kernel's time keeping state.
If getcrosststamp() is supported on a or b, then invoke it.
otherwise do this:
t1 = gettime(a)
t2 = gettime(b)
t3 - gettime(c)
*offset = (t1 + t3)/2 - t2
*error = (t3 - t1)/2
There is no need for repeated measurement, since user space can call
again when `error` is unacceptable.
Thanks,
Richard
^ permalink raw reply
* Re: [PATCH v4 5/6] add listmount(2) syscall
From: Guenter Roeck @ 2024-01-11 5:12 UTC (permalink / raw)
To: Linus Torvalds
Cc: Miklos Szeredi, linux-fsdevel, linux-kernel, linux-api, linux-man,
linux-security-module, Karel Zak, Ian Kent, David Howells,
Al Viro, Christian Brauner, Amir Goldstein, Matthew House,
Florian Weimer, Arnd Bergmann
In-Reply-To: <CAHk-=wjdW-4s6Kpa4izJ2D=yPdCje6Ta=eQxxQG6e2SkP42vnw@mail.gmail.com>
On 1/10/24 16:32, Linus Torvalds wrote:
> On Wed, 10 Jan 2024 at 14:23, Guenter Roeck <linux@roeck-us.net> wrote:
>>
>> with this patch in the tree, all sh4 builds fail with ICE.
>>
>> during RTL pass: final
>> In file included from fs/namespace.c:11:
>> fs/namespace.c: In function '__se_sys_listmount':
>> include/linux/syscalls.h:258:9: internal compiler error: in change_address_1, at emit-rtl.c:2275
>
> We do have those very ugly SYSCALL_DEFINEx() macros, but I'm not
> seeing _anything_ that would be odd about the listmount case.
>
> And the "__se_sys" thing in particular is just a fairly trivial wrapper.
>
> It does use that asmlinkage_protect() thing, and it is unquestionably
> horrendously ugly (staring too long at <linux/syscalls.h> has been
> known to cause madness and despair), but we do that for *every* single
> system call and I don't see why the new listmount entry would be
> different.
>
I don't have much of a clue either, but here is a hint: The problem is
only seen if CONFIG_MMU=n. I tested with all configurations in
arch/sh/configs.
Guenter
^ permalink raw reply
* [PATCH v2] selftests/landlock:Fix two build issues
From: Hu Yadi @ 2024-01-11 3:51 UTC (permalink / raw)
To: jmorris, serge, shuah, mathieu.desnoyers, mic
Cc: linux-api, linux-kernel, linux-security-module, linux-kselftest,
514118380, jiaoxupo, Hu.Yadi
From: "Hu.Yadi" <hu.yadi@h3c.com>
Two issues comes up while building selftest/landlock:
the first one is as to gettid
net_test.c: In function ‘set_service’:
net_test.c:91:45: warning: implicit declaration of function ‘gettid’; [-Wimplicit-function-declaration]
"_selftests-landlock-net-tid%d-index%d", gettid(),
^~~~~~
getgid
net_test.c:(.text+0x4e0): undefined reference to `gettid'
the second is compiler error
gcc -Wall -O2 -isystem fs_test.c -lcap -o selftests/landlock/fs_test
fs_test.c:4575:9: error: initializer element is not constant
.mnt = mnt_tmp,
^~~~~~~
this patch is to fix them
Signed-off-by: Hu.Yadi <hu.yadi@h3c.com>
Suggested-by: Jiao <jiaoxupo@h3c.com>
Reviewed-by: Berlin <berlin@h3c.com>
---
Changes v1 -> v2:
- fix whitespace error
- replace SYS_gettid with _NR_gettid
tools/testing/selftests/landlock/fs_test.c | 5 ++++-
tools/testing/selftests/landlock/net_test.c | 2 +-
2 files changed, 5 insertions(+), 2 deletions(-)
diff --git a/tools/testing/selftests/landlock/fs_test.c b/tools/testing/selftests/landlock/fs_test.c
index 18e1f86a6234..a992cf7c0ad1 100644
--- a/tools/testing/selftests/landlock/fs_test.c
+++ b/tools/testing/selftests/landlock/fs_test.c
@@ -4572,7 +4572,10 @@ FIXTURE_VARIANT(layout3_fs)
/* clang-format off */
FIXTURE_VARIANT_ADD(layout3_fs, tmpfs) {
/* clang-format on */
- .mnt = mnt_tmp,
+ .mnt = {
+ .type = "tmpfs",
+ .data = "size=4m,mode=700",
+ },
.file_path = file1_s1d1,
};
diff --git a/tools/testing/selftests/landlock/net_test.c b/tools/testing/selftests/landlock/net_test.c
index 929e21c4db05..455f4efe7346 100644
--- a/tools/testing/selftests/landlock/net_test.c
+++ b/tools/testing/selftests/landlock/net_test.c
@@ -88,7 +88,7 @@ static int set_service(struct service_fixture *const srv,
case AF_UNIX:
srv->unix_addr.sun_family = prot.domain;
sprintf(srv->unix_addr.sun_path,
- "_selftests-landlock-net-tid%d-index%d", gettid(),
+ "_selftests-landlock-net-tid%ld-index%d", syscall(__NR_gettid),
index);
srv->unix_addr_len = SUN_LEN(&srv->unix_addr);
srv->unix_addr.sun_path[0] = '\0';
--
2.23.0
^ permalink raw reply related
* [PATCH] selftests/core: Fix build issue with CLOSE_RANGE_UNSHARE
From: Hu Yadi @ 2024-01-11 3:47 UTC (permalink / raw)
To: jmorris, serge, shuah, mathieu.desnoyers, mic
Cc: linux-api, linux-kernel, linux-security-module, linux-kselftest,
514118380, jiaoxupo, Hu.Yadi
From: "Hu.Yadi" <hu.yadi@h3c.com>
Add head file to fix cpmpile error:
gcc -g -isystem /home/linux/usr/include close_range_test.c -o /home/linux/tools/testing/selftests/core/close_range_test
close_range_test.c: In function ‘close_range_unshare’:
close_range_test.c:111:11: error: ‘CLOSE_RANGE_UNSHARE’ undeclared (first use in this function); did you mean ‘CLONE_NEWUSER’?
CLOSE_RANGE_UNSHARE);
^~~~~~~~~~~~~~~~~~~
Signed-off-by: Hu.Yadi <hu.yadi@h3c.com>
Suggested-by: Jiao <jiaoxupo@h3c.com>
Reviewed-by: Berlin <berlin@h3c.com>
---
tools/testing/selftests/core/close_range_test.c | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/tools/testing/selftests/core/close_range_test.c b/tools/testing/selftests/core/close_range_test.c
index 534576f06df1..563bc1e55937 100644
--- a/tools/testing/selftests/core/close_range_test.c
+++ b/tools/testing/selftests/core/close_range_test.c
@@ -12,7 +12,7 @@
#include <syscall.h>
#include <unistd.h>
#include <sys/resource.h>
-
+#include <linux/close_range.h>
#include "../kselftest_harness.h"
#include "../clone3/clone3_selftests.h"
--
2.23.0
^ permalink raw reply related
* [PATCH v3] selftests/move_mount_set_group:Fix build issue with old libc
From: Hu Yadi @ 2024-01-11 3:39 UTC (permalink / raw)
To: jmorris, serge, shuah, mathieu.desnoyers, mic
Cc: linux-api, linux-kernel, linux-security-module, linux-kselftest,
514118380, jiaoxupo, Hu.Yadi
From: "Hu.Yadi" <hu.yadi@h3c.com>
Replace SYS_move_mount with __NR_move_mount to fix build error
with old libc.
Signed-off-by: Hu.Yadi <hu.yadi@h3c.com>
Suggested-by: Jiao <jiaoxupo@h3c.com>
Reviewed-by: Berlin <berlin@h3c.com>
---
Changes v2 -> v3:
- Adjust comments
Changes v1 -> v2:
- Fix mail of Suggested-by and Reviewed-by
.../move_mount_set_group/move_mount_set_group_test.c | 4 ++--
1 file changed, 2 insertions(+), 2 deletions(-)
diff --git a/tools/testing/selftests/move_mount_set_group/move_mount_set_group_test.c b/tools/testing/selftests/move_mount_set_group/move_mount_set_group_test.c
index 50ed5d475dd1..bcf51d785a37 100644
--- a/tools/testing/selftests/move_mount_set_group/move_mount_set_group_test.c
+++ b/tools/testing/selftests/move_mount_set_group/move_mount_set_group_test.c
@@ -218,7 +218,7 @@ static bool move_mount_set_group_supported(void)
if (mount(NULL, SET_GROUP_FROM, NULL, MS_SHARED, 0))
return -1;
- ret = syscall(SYS_move_mount, AT_FDCWD, SET_GROUP_FROM,
+ ret = syscall(__NR_move_mount, AT_FDCWD, SET_GROUP_FROM,
AT_FDCWD, SET_GROUP_TO, MOVE_MOUNT_SET_GROUP);
umount2("/tmp", MNT_DETACH);
@@ -363,7 +363,7 @@ TEST_F(move_mount_set_group, complex_sharing_copying)
CLONE_VM | CLONE_FILES); ASSERT_GT(pid, 0);
ASSERT_EQ(wait_for_pid(pid), 0);
- ASSERT_EQ(syscall(SYS_move_mount, ca_from.mntfd, "",
+ ASSERT_EQ(syscall(__NR_move_mount, ca_from.mntfd, "",
ca_to.mntfd, "", MOVE_MOUNT_SET_GROUP
| MOVE_MOUNT_F_EMPTY_PATH | MOVE_MOUNT_T_EMPTY_PATH),
0);
--
2.23.0
^ permalink raw reply related
* 回复: [PATCH] selftests/landlock:Fix two build issues
From: Huyadi @ 2024-01-11 2:34 UTC (permalink / raw)
To: Mickaël Salaün
Cc: jmorris@namei.org, serge@hallyn.com, shuah@kernel.org,
mathieu.desnoyers@efficios.com, linux-api@vger.kernel.org,
linux-kernel@vger.kernel.org,
linux-security-module@vger.kernel.org,
linux-kselftest@vger.kernel.org, 514118380@qq.com, Huyadi
In-Reply-To: <20240110.ob2roh1Xai9y@digikod.net>
->On Wed, Jan 10, 2024 at 03:08:54PM +0800, Hu Yadi wrote:
>> From: "Hu.Yadi" <hu.yadi@h3c.com>
>>
>> Two issues comes up while building selftest/landlock:
>>
>> the first one is as to gettid
>>
>> net_test.c: In function ‘set_service’:
>> net_test.c:91:45: warning: implicit declaration of function ‘gettid’; did you mean ‘getgid’? [-Wimplicit-function-declaration]
>> "_selftests-landlock-net-tid%d-index%d", gettid(),
>> ^~~~~~
>> getgid
>> net_test.c:(.text+0x4e0): undefined reference to `gettid'
>>
>> the second is compiler error
>> gcc -Wall -O2 -isystem fs_test.c -lcap -o /home/linux/tools/testing/selftests/landlock/fs_test
>> fs_test.c:4575:9: error: initializer element is not constant
>> .mnt = mnt_tmp,
>> ^~~~~~~
>
>What is the version of GCC (and headers) and on which system (and
>version) are you building these tests?
gcc 7.3 / glibc-2.28/ kernel 4.19/ OpenEulor20.03
>>
>> this patch is to fix them
>>
>> Signed-off-by: Hu.Yadi <hu.yadi@h3c.com>
>> Suggested-by: Jiao <jiaoxupo@h3c.com>
>> Reviewed-by:Berlin <berlin@h3c.com>
>> ---
>> tools/testing/selftests/landlock/fs_test.c | 5 ++++-
>> tools/testing/selftests/landlock/net_test.c | 3 +--
>> 2 files changed, 5 insertions(+), 3 deletions(-)
>>
>> diff --git a/tools/testing/selftests/landlock/fs_test.c
>> b/tools/testing/selftests/landlock/fs_test.c
>> index 18e1f86a6234..93eb40a09073 100644
>> --- a/tools/testing/selftests/landlock/fs_test.c
>> +++ b/tools/testing/selftests/landlock/fs_test.c
>> @@ -4572,7 +4572,10 @@ FIXTURE_VARIANT(layout3_fs)
>> /* clang-format off */
>> FIXTURE_VARIANT_ADD(layout3_fs, tmpfs) {
>> /* clang-format on */
>> - .mnt = mnt_tmp,
>> + .mnt = {
>> + .type = "tmpfs",
>> + .data = "size=4m,mode=700",
>
>When applying this patch we get: "space before tab in indent"
Sorry for inconvenient, I'll resend it v2 after checkpatch.pl shows no error.
>> + },
>> .file_path = file1_s1d1,
>> };
>>
>> diff --git a/tools/testing/selftests/landlock/net_test.c
>> b/tools/testing/selftests/landlock/net_test.c
>> index 929e21c4db05..8fb357de8c55 100644
>> --- a/tools/testing/selftests/landlock/net_test.c
>> +++ b/tools/testing/selftests/landlock/net_test.c
>> @@ -18,7 +18,6 @@
>> #include <sys/prctl.h>
>> #include <sys/socket.h>
>> #include <sys/un.h>
>> -
>> #include "common.h"
>>
>> const short sock_port_start = (1 << 10); @@ -88,7 +87,7 @@ static int
>> set_service(struct service_fixture *const srv,
>> case AF_UNIX:
>> srv->unix_addr.sun_family = prot.domain;
>> sprintf(srv->unix_addr.sun_path,
>> - "_selftests-landlock-net-tid%d-index%d", gettid(),
>> + "_selftests-landlock-net-tid%ld-index%d", syscall(SYS_gettid),
>
>You sent another patch that "replace SYS_<syscall> with __NR_<syscall>".
>Why not here?
>
>Please follow the same approach:
>https://git.kernel.org/stable/c/87129ef13603ae46c82bcd09eed948acf0506dbb
Got it, I'll resend it v2 including the fix
>> index);
>> srv->unix_addr_len = SUN_LEN(&srv->unix_addr);
>> srv->unix_addr.sun_path[0] = '\0';
>> --
>> 2.23.0
>>
>>
^ permalink raw reply
* 回复: [PATCH v2] selftests/move_mount_set_group:Make tests build with old libc
From: Huyadi @ 2024-01-11 2:25 UTC (permalink / raw)
To: Mickaël Salaün
Cc: jmorris@namei.org, serge@hallyn.com, shuah@kernel.org,
mathieu.desnoyers@efficios.com, linux-api@vger.kernel.org,
linux-kernel@vger.kernel.org,
linux-security-module@vger.kernel.org,
linux-kselftest@vger.kernel.org, 514118380@qq.com
In-Reply-To: <20240110.Yap9Aw9aeghu@digikod.net>
>On Wed, Jan 10, 2024 at 03:29:01PM +0800, Hu Yadi wrote:
>> From: "Hu.Yadi" <hu.yadi@h3c.com>
>>
>> Replace SYS_<syscall> with __NR_<syscall>. Using the __NR_<syscall>
>> notation, provided by UAPI, is useful to build tests on systems
>> without the SYS_<syscall> definitions.
>
>This looks a lot like that...
>https://git.kernel.org/stable/c/87129ef13603ae46c82bcd09eed948acf0506dbb
Yes, I picked up comments from above commit in order for consistent,
I would send v3 patch if it is inappropriate.
>>
>> Replace SYS_move_mount with __NR_move_mount
>>
>> Signed-off-by: Hu.Yadi <hu.yadi@h3c.com> Suggested-by:Jiao
>> <jiaoxupo@h3c.com> Reviewed-by:Berlin <berlin@h3c.com>
>> ---
>> Changes v1 -> v2:
>> - Fix mail of Suggested-by and Reviewed-by
>>
>> .../move_mount_set_group/move_mount_set_group_test.c | 4 ++--
>> 1 file changed, 2 insertions(+), 2 deletions(-)
>>
>> diff --git
>> a/tools/testing/selftests/move_mount_set_group/move_mount_set_group_te
>> st.c
>> b/tools/testing/selftests/move_mount_set_group/move_mount_set_group_te
>> st.c index 50ed5d475dd1..bcf51d785a37 100644
>> ---
>> a/tools/testing/selftests/move_mount_set_group/move_mount_set_group_te
>> st.c
>> +++ b/tools/testing/selftests/move_mount_set_group/move_mount_set_grou
>> +++ p_test.c
>> @@ -218,7 +218,7 @@ static bool move_mount_set_group_supported(void)
>> if (mount(NULL, SET_GROUP_FROM, NULL, MS_SHARED, 0))
>> return -1;
>>
>> - ret = syscall(SYS_move_mount, AT_FDCWD, SET_GROUP_FROM,
>> + ret = syscall(__NR_move_mount, AT_FDCWD, SET_GROUP_FROM,
>> AT_FDCWD, SET_GROUP_TO, MOVE_MOUNT_SET_GROUP);
>> umount2("/tmp", MNT_DETACH);
>>
>> @@ -363,7 +363,7 @@ TEST_F(move_mount_set_group, complex_sharing_copying)
>> CLONE_VM | CLONE_FILES); ASSERT_GT(pid, 0);
>> ASSERT_EQ(wait_for_pid(pid), 0);
>>
>> - ASSERT_EQ(syscall(SYS_move_mount, ca_from.mntfd, "",
>> + ASSERT_EQ(syscall(__NR_move_mount, ca_from.mntfd, "",
>> ca_to.mntfd, "", MOVE_MOUNT_SET_GROUP
>> | MOVE_MOUNT_F_EMPTY_PATH | MOVE_MOUNT_T_EMPTY_PATH),
>> 0);
>> --
>> 2.23.0
>>
^ permalink raw reply
* Re: [PATCH v4 5/6] add listmount(2) syscall
From: Linus Torvalds @ 2024-01-11 0:32 UTC (permalink / raw)
To: Guenter Roeck
Cc: Miklos Szeredi, linux-fsdevel, linux-kernel, linux-api, linux-man,
linux-security-module, Karel Zak, Ian Kent, David Howells,
Al Viro, Christian Brauner, Amir Goldstein, Matthew House,
Florian Weimer, Arnd Bergmann
In-Reply-To: <75b87a85-7d2c-4078-91e3-024ea36cfb42@roeck-us.net>
On Wed, 10 Jan 2024 at 14:23, Guenter Roeck <linux@roeck-us.net> wrote:
>
> with this patch in the tree, all sh4 builds fail with ICE.
>
> during RTL pass: final
> In file included from fs/namespace.c:11:
> fs/namespace.c: In function '__se_sys_listmount':
> include/linux/syscalls.h:258:9: internal compiler error: in change_address_1, at emit-rtl.c:2275
We do have those very ugly SYSCALL_DEFINEx() macros, but I'm not
seeing _anything_ that would be odd about the listmount case.
And the "__se_sys" thing in particular is just a fairly trivial wrapper.
It does use that asmlinkage_protect() thing, and it is unquestionably
horrendously ugly (staring too long at <linux/syscalls.h> has been
known to cause madness and despair), but we do that for *every* single
system call and I don't see why the new listmount entry would be
different.
Linus
^ permalink raw reply
* Re: [PATCH v4 5/6] add listmount(2) syscall
From: Guenter Roeck @ 2024-01-10 22:23 UTC (permalink / raw)
To: Miklos Szeredi
Cc: linux-fsdevel, linux-kernel, linux-api, linux-man,
linux-security-module, Karel Zak, Ian Kent, David Howells,
Linus Torvalds, Al Viro, Christian Brauner, Amir Goldstein,
Matthew House, Florian Weimer, Arnd Bergmann
In-Reply-To: <20231025140205.3586473-6-mszeredi@redhat.com>
Hi,
On Wed, Oct 25, 2023 at 04:02:03PM +0200, Miklos Szeredi wrote:
> Add way to query the children of a particular mount. This is a more
> flexible way to iterate the mount tree than having to parse the complete
> /proc/self/mountinfo.
>
> Allow listing either
>
> - immediate child mounts only, or
>
> - recursively all descendant mounts (depth first).
>
> Lookup the mount by the new 64bit mount ID. If a mount needs to be queried
> based on path, then statx(2) can be used to first query the mount ID
> belonging to the path.
>
> Return an array of new (64bit) mount ID's. Without privileges only mounts
> are listed which are reachable from the task's root.
>
> Signed-off-by: Miklos Szeredi <mszeredi@redhat.com>
with this patch in the tree, all sh4 builds fail with ICE.
during RTL pass: final
In file included from fs/namespace.c:11:
fs/namespace.c: In function '__se_sys_listmount':
include/linux/syscalls.h:258:9: internal compiler error: in change_address_1, at emit-rtl.c:2275
I tested with gcc 8.2, 11.3, 11.4, and 12.3. The compiler version
does not make a difference. Has anyone else seen the same problem ?
If so, any idea what to do about it ?
Thanks,
Guenter
^ permalink raw reply
* Re: [musl] Protect pthreads' mutexes against use-after-destroy
From: Rich Felker @ 2024-01-10 21:24 UTC (permalink / raw)
To: musl; +Cc: linux-api
In-Reply-To: <20240110015550.GP4163@brightrain.aerifal.cx>
On Tue, Jan 09, 2024 at 08:55:50PM -0500, Rich Felker wrote:
> On Tue, Jan 09, 2024 at 02:07:26PM -0500, Rich Felker wrote:
> > On Tue, Jan 09, 2024 at 03:37:17PM +0100, jvoisin wrote:
> > > Ohai,
> > >
> > > as discussed on irc, Android's bionic has a check to prevent
> > > use-after-destroy on phtread mutexes
> > > (https://github.com/LineageOS/android_bionic/blob/e0aac7df6f58138dae903b5d456c947a3f8092ea/libc/bionic/pthread_mutex.cpp#L803),
> > > and musl doesn't.
> > >
> > > While odds are that this is a super-duper common bug, it would still be
> > > nice to have this kind of protection, since it's cheap, and would
> > > prevent/make it easy to diagnose weird states.
> > >
> > > Is this something that should/could be implemented?
> > >
> > > o/
> >
> > I think you meant that the odds are it's not common. There's already
> > enough complexity in the code paths for supporting all the different
> > mutex types that my leaning would be, if we do any hardening for
> > use-after-destroy, that it should probably just take the form of
> > putting the object in a state that will naturally deadlock or error
> > rather than adding extra checks to every path where it's used.
> >
> > If OTOH we do want it to actually trap in all cases where it's used
> > after destroy, the simplest way to achieve that is probably to set it
> > up as a non-robust non-PI recursive or errorchecking mutex with
> > invalid prev/next pointers and owner of 0x3fffffff. Then the only
> > place that would actually have to have an explicit trap is trylock in
> > the code path:
> >
> > if (own == 0x3fffffff) return ENOTRECOVERABLE;
> >
> > where it could trap if type isn't robust. The unlock code path would
> > trap on accessing invalid prev/next pointers.
>
> Unfortunately I discovered a problem we need to deal with in
> researching for this: at some point Linux quietly changed the futex
> ABI, so that bit 29 is no longer reserved but potentially a tid bit.
> This was documented in 9c40365a65d62d7c06a95fb331b3442cb02d2fd9 but
> apparently actually happened at the source level a long time before
> that. So, we cannot assume 0x3fffffff is not a valid tid, and thereby
> cannot assume 0x7fffffff is not equal to ownerdead|valid_tid.
>
> This probably means we need to find a way to encode "not recoverable"
> as 0x40000000, as 0 is now the _only_ value in the low-30-bits that
> can't potentially be a valid tid.
>
> I'll look at this more over the next day or two. It's probably fixable
> but requires fiddling with delicate logic.
>
> Note that the only in-the-wild breakage possible is on systems where
> the pid/tid limit has been set extremely high, where attempts to lock
> a recursive or errorchecking mutex owned by a thread with tid
> 0x3fffffff could malfunction.
OK, more fun. The kernel documentation (locking/robust-futex-ABI.rst)
is *wrong*. It claims that, when processing the robust list for a
dying task, the only actions are:
1) if bit 31 (0x80000000) is set in that word, then attempt a futex
wakeup on that address, which will waken the next thread that has
used to the futex mechanism to wait on that address, and
2) atomically set bit 30 (0x40000000) in the 'lock word'.
However, 2 is incorrect. There is no "set bit 30" operation in the
kernel. Rather, it atomically replaces the old lock value (tid of the
dying task, possibly with bit 31 added on for "waiters present") with
0x40000000 (no waiters) or 0xc0000000 (maybe waiters), clearing out
the tid of the dying task.
Thus, we cannot use 0x40000000 as the "not recoverable" value; this is
the only value the kernel ever used for "owner died" state.
At first this sounds good: we should be able to use any value with bit
30 set, including something like 0x7fffffff like we're using now, as
the "not recoverable" state. Unfortunately, that's not quite true. The
kernel's robust list processing at task death masks off bit 30, so if
a task with tid 0x3fffffff were to die with the unrecoverable mutex in
its robust list or or pending slot, it would wrongly get converted
back by the kernel from "not recoverable" state to "owner died" state.
Naively one would expect an already not-recoverable not to be able to
be added to the robust list, and this is correct; however, it can be
added to the pending slot if a thread attempting to lock it was
suspended after checking the old state, before it was in
not-recoverable state, but before attempting the atomic CAS to take
the lock, seeing that fail, and removing it from the pending slot.
I don't see any solution to this problem without having one or more
values of the low 30 bits (bits 0-29) that are reserved and guaranteed
never to match a real task. AIUI, Linux presently doesn't support more
than 22 bits of tid anyway, so this probably is not a real issue, but
it is an issue for future-proofing the user-kernel interface. What
we're doing now (using 0x7fffffff as the unrecoverable value) is
unsafe if Linux or any kernel purporting to honor the Linux syscall
API/ABI ever supports full 30-bit tids.
I think we should probably ask the kernel folks to reinstate the
original specification that bit 29 (0x20000000) is reserved and
guaranteed not to be present in a valid tid. If that's deemed
inappropriate, just reserving a single value 0x3fffffff that's
guaranteed not to be a real tid should suffice. Either would make what
we're doing now (based on the old pre-2020 documentation) valid and
future-proof once again.
Rich
^ permalink raw reply
* Re: [PATCH v2] selftests/move_mount_set_group:Make tests build with old libc
From: Mickaël Salaün @ 2024-01-10 17:45 UTC (permalink / raw)
To: Hu Yadi
Cc: jmorris, serge, shuah, mathieu.desnoyers, linux-api, linux-kernel,
linux-security-module, linux-kselftest, 514118380, berlin
In-Reply-To: <20240110072901.5873-1-hu.yadi@h3c.com>
On Wed, Jan 10, 2024 at 03:29:01PM +0800, Hu Yadi wrote:
> From: "Hu.Yadi" <hu.yadi@h3c.com>
>
> Replace SYS_<syscall> with __NR_<syscall>. Using the __NR_<syscall>
> notation, provided by UAPI, is useful to build tests on systems without
> the SYS_<syscall> definitions.
This looks a lot like that...
https://git.kernel.org/stable/c/87129ef13603ae46c82bcd09eed948acf0506dbb
>
> Replace SYS_move_mount with __NR_move_mount
>
> Signed-off-by: Hu.Yadi <hu.yadi@h3c.com>
> Suggested-by:Jiao <jiaoxupo@h3c.com>
> Reviewed-by:Berlin <berlin@h3c.com>
> ---
> Changes v1 -> v2:
> - Fix mail of Suggested-by and Reviewed-by
>
> .../move_mount_set_group/move_mount_set_group_test.c | 4 ++--
> 1 file changed, 2 insertions(+), 2 deletions(-)
>
> diff --git a/tools/testing/selftests/move_mount_set_group/move_mount_set_group_test.c b/tools/testing/selftests/move_mount_set_group/move_mount_set_group_test.c
> index 50ed5d475dd1..bcf51d785a37 100644
> --- a/tools/testing/selftests/move_mount_set_group/move_mount_set_group_test.c
> +++ b/tools/testing/selftests/move_mount_set_group/move_mount_set_group_test.c
> @@ -218,7 +218,7 @@ static bool move_mount_set_group_supported(void)
> if (mount(NULL, SET_GROUP_FROM, NULL, MS_SHARED, 0))
> return -1;
>
> - ret = syscall(SYS_move_mount, AT_FDCWD, SET_GROUP_FROM,
> + ret = syscall(__NR_move_mount, AT_FDCWD, SET_GROUP_FROM,
> AT_FDCWD, SET_GROUP_TO, MOVE_MOUNT_SET_GROUP);
> umount2("/tmp", MNT_DETACH);
>
> @@ -363,7 +363,7 @@ TEST_F(move_mount_set_group, complex_sharing_copying)
> CLONE_VM | CLONE_FILES); ASSERT_GT(pid, 0);
> ASSERT_EQ(wait_for_pid(pid), 0);
>
> - ASSERT_EQ(syscall(SYS_move_mount, ca_from.mntfd, "",
> + ASSERT_EQ(syscall(__NR_move_mount, ca_from.mntfd, "",
> ca_to.mntfd, "", MOVE_MOUNT_SET_GROUP
> | MOVE_MOUNT_F_EMPTY_PATH | MOVE_MOUNT_T_EMPTY_PATH),
> 0);
> --
> 2.23.0
>
^ permalink raw reply
* Re: [PATCH] selftests/landlock:Fix two build issues
From: Mickaël Salaün @ 2024-01-10 17:45 UTC (permalink / raw)
To: Hu Yadi
Cc: jmorris, serge, shuah, mathieu.desnoyers, linux-api, linux-kernel,
linux-security-module, linux-kselftest, 514118380, berlin
In-Reply-To: <20240110070854.7077-1-hu.yadi@h3c.com>
On Wed, Jan 10, 2024 at 03:08:54PM +0800, Hu Yadi wrote:
> From: "Hu.Yadi" <hu.yadi@h3c.com>
>
> Two issues comes up while building selftest/landlock:
>
> the first one is as to gettid
>
> net_test.c: In function ‘set_service’:
> net_test.c:91:45: warning: implicit declaration of function ‘gettid’; did you mean ‘getgid’? [-Wimplicit-function-declaration]
> "_selftests-landlock-net-tid%d-index%d", gettid(),
> ^~~~~~
> getgid
> net_test.c:(.text+0x4e0): undefined reference to `gettid'
>
> the second is compiler error
> gcc -Wall -O2 -isystem fs_test.c -lcap -o /home/linux/tools/testing/selftests/landlock/fs_test
> fs_test.c:4575:9: error: initializer element is not constant
> .mnt = mnt_tmp,
> ^~~~~~~
What is the version of GCC (and headers) and on which system (and
version) are you building these tests?
>
> this patch is to fix them
>
> Signed-off-by: Hu.Yadi <hu.yadi@h3c.com>
> Suggested-by: Jiao <jiaoxupo@h3c.com>
> Reviewed-by:Berlin <berlin@h3c.com>
> ---
> tools/testing/selftests/landlock/fs_test.c | 5 ++++-
> tools/testing/selftests/landlock/net_test.c | 3 +--
> 2 files changed, 5 insertions(+), 3 deletions(-)
>
> diff --git a/tools/testing/selftests/landlock/fs_test.c b/tools/testing/selftests/landlock/fs_test.c
> index 18e1f86a6234..93eb40a09073 100644
> --- a/tools/testing/selftests/landlock/fs_test.c
> +++ b/tools/testing/selftests/landlock/fs_test.c
> @@ -4572,7 +4572,10 @@ FIXTURE_VARIANT(layout3_fs)
> /* clang-format off */
> FIXTURE_VARIANT_ADD(layout3_fs, tmpfs) {
> /* clang-format on */
> - .mnt = mnt_tmp,
> + .mnt = {
> + .type = "tmpfs",
> + .data = "size=4m,mode=700",
When applying this patch we get: "space before tab in indent"
> + },
> .file_path = file1_s1d1,
> };
>
> diff --git a/tools/testing/selftests/landlock/net_test.c b/tools/testing/selftests/landlock/net_test.c
> index 929e21c4db05..8fb357de8c55 100644
> --- a/tools/testing/selftests/landlock/net_test.c
> +++ b/tools/testing/selftests/landlock/net_test.c
> @@ -18,7 +18,6 @@
> #include <sys/prctl.h>
> #include <sys/socket.h>
> #include <sys/un.h>
> -
> #include "common.h"
>
> const short sock_port_start = (1 << 10);
> @@ -88,7 +87,7 @@ static int set_service(struct service_fixture *const srv,
> case AF_UNIX:
> srv->unix_addr.sun_family = prot.domain;
> sprintf(srv->unix_addr.sun_path,
> - "_selftests-landlock-net-tid%d-index%d", gettid(),
> + "_selftests-landlock-net-tid%ld-index%d", syscall(SYS_gettid),
You sent another patch that "replace SYS_<syscall> with __NR_<syscall>".
Why not here?
Please follow the same approach:
https://git.kernel.org/stable/c/87129ef13603ae46c82bcd09eed948acf0506dbb
> index);
> srv->unix_addr_len = SUN_LEN(&srv->unix_addr);
> srv->unix_addr.sun_path[0] = '\0';
> --
> 2.23.0
>
>
^ permalink raw reply
* Re: [PATCH RESEND] x86/entry/ia32: Ensure s32 is sign extended to s64
From: Arnd Bergmann @ 2024-01-10 13:42 UTC (permalink / raw)
To: Nikolay Borisov, linux-kernel, x86; +Cc: linux-api, Richard Palethorpe
In-Reply-To: <20240110130122.3836513-1-nik.borisov@suse.com>
On Wed, Jan 10, 2024, at 14:01, Nikolay Borisov wrote:
>
> This patch has been sent previously by Richard back in 2021 [0].
> However it
> seems to have been dropped at some point and never merged. So I'm
> resending again
> to consider it for merging given that io_pgetevents_time64 LTP test
> still fails.
>
>
> [0] https://lore.kernel.org/all/20210927161955.28494-1-rpalethorpe@suse.com/
Thank you for resending this, I hadn't noticed that this never
went in, but I also see that I still keep the same patch in
my testing tree.
I think the entire syscall entry logic needs a larger
cross-architecture overhaul to avoid these confusing macros
and make sure we get it right everywhere, but that's not
going to happen overnight, so this patch is what should
get merged and backported to LTS kernels first.
arnd
^ permalink raw reply
* [PATCH RESEND] x86/entry/ia32: Ensure s32 is sign extended to s64
From: Nikolay Borisov @ 2024-01-10 13:01 UTC (permalink / raw)
To: linux-kernel, x86; +Cc: arnd, linux-api, Richard Palethorpe, Nikolay Borisov
From: Richard Palethorpe <rpalethorpe@suse.com>
Presently ia32 registers stored in ptregs are unconditionally cast to
unsigned int by the ia32 stub. They are then cast to long when passed
to __se_sys*, but will not be sign extended.
This takes the sign of the syscall argument into account in the ia32
stub. It still casts to unsigned int to avoid implementation specific
behavior. However then casts to int or unsigned int as necessary. So
that the following cast to long sign extends the value.
This fixes the io_pgetevents02 LTP test when compiled with
-m32. Presently the systemcall io_pgetevents_time64 unexpectedly
accepts -1 for the maximum number of events. It doesn't appear other
systemcalls with signed arguments are effected because they all have
compat variants defined and wired up. A less general solution is to
wire up the systemcall:
https://lore.kernel.org/ltp/20210921130127.24131-1-rpalethorpe@suse.com/
Fixes: ebeb8c82ffaf ("syscalls/x86: Use 'struct pt_regs' based syscall calling for IA32_EMULATION and x32")
Signed-off-by: Richard Palethorpe <rpalethorpe@suse.com>
Suggested-by: Arnd Bergmann <arnd@arndb.de>
Reviewed-by: Arnd Bergmann <arnd@arndb.de>
Signed-off-by: Nikolay Borisov <nik.borisov@suse.com>
---
This patch has been sent previously by Richard back in 2021 [0]. However it
seems to have been dropped at some point and never merged. So I'm resending again
to consider it for merging given that io_pgetevents_time64 LTP test still fails.
[0] https://lore.kernel.org/all/20210927161955.28494-1-rpalethorpe@suse.com/
arch/x86/include/asm/syscall_wrapper.h | 25 +++++++++++++++++++++----
include/linux/syscalls.h | 1 +
2 files changed, 22 insertions(+), 4 deletions(-)
diff --git a/arch/x86/include/asm/syscall_wrapper.h b/arch/x86/include/asm/syscall_wrapper.h
index 21f9407be5d3..7e88705e907f 100644
--- a/arch/x86/include/asm/syscall_wrapper.h
+++ b/arch/x86/include/asm/syscall_wrapper.h
@@ -58,12 +58,29 @@ extern long __ia32_sys_ni_syscall(const struct pt_regs *regs);
,,regs->di,,regs->si,,regs->dx \
,,regs->r10,,regs->r8,,regs->r9) \
+
+/* SYSCALL_PT_ARGS is Adapted from s390x */
+#define SYSCALL_PT_ARG6(m, t1, t2, t3, t4, t5, t6) \
+ SYSCALL_PT_ARG5(m, t1, t2, t3, t4, t5), m(t6, (regs->bp))
+#define SYSCALL_PT_ARG5(m, t1, t2, t3, t4, t5) \
+ SYSCALL_PT_ARG4(m, t1, t2, t3, t4), m(t5, (regs->di))
+#define SYSCALL_PT_ARG4(m, t1, t2, t3, t4) \
+ SYSCALL_PT_ARG3(m, t1, t2, t3), m(t4, (regs->si))
+#define SYSCALL_PT_ARG3(m, t1, t2, t3) \
+ SYSCALL_PT_ARG2(m, t1, t2), m(t3, (regs->dx))
+#define SYSCALL_PT_ARG2(m, t1, t2) \
+ SYSCALL_PT_ARG1(m, t1), m(t2, (regs->cx))
+#define SYSCALL_PT_ARG1(m, t1) m(t1, (regs->bx))
+#define SYSCALL_PT_ARGS(x, ...) SYSCALL_PT_ARG##x(__VA_ARGS__)
+
+#define __SC_COMPAT_CAST(t, a) \
+ (__typeof(__builtin_choose_expr(__TYPE_IS_L(t), 0, 0U))) \
+ (unsigned int)a
+
/* Mapping of registers to parameters for syscalls on i386 */
#define SC_IA32_REGS_TO_ARGS(x, ...) \
- __MAP(x,__SC_ARGS \
- ,,(unsigned int)regs->bx,,(unsigned int)regs->cx \
- ,,(unsigned int)regs->dx,,(unsigned int)regs->si \
- ,,(unsigned int)regs->di,,(unsigned int)regs->bp)
+ SYSCALL_PT_ARGS(x, __SC_COMPAT_CAST, \
+ __MAP(x, __SC_TYPE, __VA_ARGS__)) \
#define __SYS_STUB0(abi, name) \
long __##abi##_##name(const struct pt_regs *regs); \
diff --git a/include/linux/syscalls.h b/include/linux/syscalls.h
index 5c0dbef55792..80a059cab260 100644
--- a/include/linux/syscalls.h
+++ b/include/linux/syscalls.h
@@ -128,6 +128,7 @@ struct mnt_id_req;
#define __TYPE_IS_LL(t) (__TYPE_AS(t, 0LL) || __TYPE_AS(t, 0ULL))
#define __SC_LONG(t, a) __typeof(__builtin_choose_expr(__TYPE_IS_LL(t), 0LL, 0L)) a
#define __SC_CAST(t, a) (__force t) a
+#define __SC_TYPE(t, a) t
#define __SC_ARGS(t, a) a
#define __SC_TEST(t, a) (void)BUILD_BUG_ON_ZERO(!__TYPE_IS_LL(t) && sizeof(t) > sizeof(long))
--
2.34.1
^ permalink raw reply related
* [PATCH v2] selftests/move_mount_set_group:Make tests build with old libc
From: Hu Yadi @ 2024-01-10 7:29 UTC (permalink / raw)
To: jmorris, serge, shuah, mathieu.desnoyers, mic
Cc: linux-api, linux-kernel, linux-security-module, linux-kselftest,
514118380, berlin, Hu.Yadi
From: "Hu.Yadi" <hu.yadi@h3c.com>
Replace SYS_<syscall> with __NR_<syscall>. Using the __NR_<syscall>
notation, provided by UAPI, is useful to build tests on systems without
the SYS_<syscall> definitions.
Replace SYS_move_mount with __NR_move_mount
Signed-off-by: Hu.Yadi <hu.yadi@h3c.com>
Suggested-by:Jiao <jiaoxupo@h3c.com>
Reviewed-by:Berlin <berlin@h3c.com>
---
Changes v1 -> v2:
- Fix mail of Suggested-by and Reviewed-by
.../move_mount_set_group/move_mount_set_group_test.c | 4 ++--
1 file changed, 2 insertions(+), 2 deletions(-)
diff --git a/tools/testing/selftests/move_mount_set_group/move_mount_set_group_test.c b/tools/testing/selftests/move_mount_set_group/move_mount_set_group_test.c
index 50ed5d475dd1..bcf51d785a37 100644
--- a/tools/testing/selftests/move_mount_set_group/move_mount_set_group_test.c
+++ b/tools/testing/selftests/move_mount_set_group/move_mount_set_group_test.c
@@ -218,7 +218,7 @@ static bool move_mount_set_group_supported(void)
if (mount(NULL, SET_GROUP_FROM, NULL, MS_SHARED, 0))
return -1;
- ret = syscall(SYS_move_mount, AT_FDCWD, SET_GROUP_FROM,
+ ret = syscall(__NR_move_mount, AT_FDCWD, SET_GROUP_FROM,
AT_FDCWD, SET_GROUP_TO, MOVE_MOUNT_SET_GROUP);
umount2("/tmp", MNT_DETACH);
@@ -363,7 +363,7 @@ TEST_F(move_mount_set_group, complex_sharing_copying)
CLONE_VM | CLONE_FILES); ASSERT_GT(pid, 0);
ASSERT_EQ(wait_for_pid(pid), 0);
- ASSERT_EQ(syscall(SYS_move_mount, ca_from.mntfd, "",
+ ASSERT_EQ(syscall(__NR_move_mount, ca_from.mntfd, "",
ca_to.mntfd, "", MOVE_MOUNT_SET_GROUP
| MOVE_MOUNT_F_EMPTY_PATH | MOVE_MOUNT_T_EMPTY_PATH),
0);
--
2.23.0
^ permalink raw reply related
page: next (older) | prev (newer) | latest
- recent:[subjects (threaded)|topics (new)|topics (active)]
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox