From: Laurent Vivier <laurent@vivier.eu>
To: Zhang He <zhanghe9702@163.com>
Cc: qemu-devel@nongnu.org
Subject: Re: [PATCH] Fixes: failed to call mq_open/mq_unlink in qemu-arm
Date: Fri, 6 Jun 2025 09:17:57 +0200 [thread overview]
Message-ID: <1ec605e1-6ea4-4970-b2fd-148ae26e4519@vivier.eu> (raw)
In-Reply-To: <20250605144603.17475-1-zhanghe9702@163.com>
Le 05/06/2025 à 16:46, Zhang He a écrit :
> i write some bare-metal c code need mq_open/mq_unlink syscall, but
> the syscall failed in passed name param check, arg1 in this scenario
> is the correct address from user-space, arg1 - 1 not.
> i have tested in arm cortex-m55 cpu model, maybe should add conditional compile macro?
>
> Signed-off-by: Zhang He <zhanghe9702@163.com>
> ---
> linux-user/syscall.c | 4 ++--
> 1 file changed, 2 insertions(+), 2 deletions(-)
>
> diff --git a/linux-user/syscall.c b/linux-user/syscall.c
> index fc37028597..be9610176a 100644
> --- a/linux-user/syscall.c
> +++ b/linux-user/syscall.c
> @@ -13058,7 +13058,7 @@ static abi_long do_syscall1(CPUArchState *cpu_env, int num, abi_long arg1,
> }
> pposix_mq_attr = &posix_mq_attr;
> }
> - p = lock_user_string(arg1 - 1);
> + p = lock_user_string(arg1);
> if (!p) {
> return -TARGET_EFAULT;
> }
> @@ -13068,7 +13068,7 @@ static abi_long do_syscall1(CPUArchState *cpu_env, int num, abi_long arg1,
> return ret;
>
> case TARGET_NR_mq_unlink:
> - p = lock_user_string(arg1 - 1);
> + p = lock_user_string(arg1);
> if (!p) {
> return -TARGET_EFAULT;
> }
According to the original thread:
Re: [Qemu-devel] [linux-user] Added posix message queue syscalls except
https://mail.gnu.org/archive/html/qemu-devel/2008-12/msg00966.html
It comes from glibc:
/* Remove message queue named NAME. */
int
__mq_unlink (const char *name)
{
if (name[0] != '/')
return INLINE_SYSCALL_ERROR_RETURN_VALUE (EINVAL);
int ret = INTERNAL_SYSCALL_CALL (mq_unlink, name + 1);
/* While unlink can return either EPERM or EACCES, mq_unlink should
return just EACCES. */
if (__glibc_unlikely (INTERNAL_SYSCALL_ERROR_P (ret)))
{
ret = INTERNAL_SYSCALL_ERRNO (ret);
if (ret == EPERM)
ret = EACCES;
return INLINE_SYSCALL_ERROR_RETURN_VALUE (ret);
}
return ret;
}
I think the '+' is to remove the starting '/'.
So if we call it from linux-user app, the string is '/XXXX', then into
the linux-user glibc it becomes 'XXXX', so to pass it to the host glibc
again we need to restore the '/' by doing '- 1'.
So I don't think your change is correct.
Thanks,
Laurent
prev parent reply other threads:[~2025-06-06 7:19 UTC|newest]
Thread overview: 2+ messages / expand[flat|nested] mbox.gz Atom feed top
2025-06-05 14:46 [PATCH] Fixes: failed to call mq_open/mq_unlink in qemu-arm Zhang He
2025-06-06 7:17 ` Laurent Vivier [this message]
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=1ec605e1-6ea4-4970-b2fd-148ae26e4519@vivier.eu \
--to=laurent@vivier.eu \
--cc=qemu-devel@nongnu.org \
--cc=zhanghe9702@163.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).