All of lore.kernel.org
 help / color / mirror / Atom feed
From: Petr Vorel <pvorel@suse.cz>
To: Wei Gao <wegao@suse.com>
Cc: ltp@lists.linux.it
Subject: Re: [LTP] [PATCH v4] getcwd01: Use syscall directly check invalid argument
Date: Fri, 1 Dec 2023 11:14:15 +0100	[thread overview]
Message-ID: <20231201101415.GB1710028@pevik> (raw)
In-Reply-To: <20231201031512.27513-1-wegao@suse.com>

Hi Wei,

> Fixes: #1084

> User space wrap getcwd with different implementation, for example
> glibc will directly input parameter into kernel in normal situation
> but uclibc-ng and musl will malloc buffer when buffer is NULL, so for
> uclibc and musl the parameter size will be ignored. Use system call
> directly check invalid argument can be a solution.

For the sake of the correctness: there is no malloc() in musl [1] (nor in the
mirror source you posted to #1084), that's only in uclibc-ng [2] and glibc [3].

The reason why musl failed was already described by Richie and Cyril in #1084:
musl ignores the size parameter when buffer is NULL and allocates it with PATH_MAX
and passes this size to kernel.

Therefore I reword the commit message.

[1] https://git.musl-libc.org/cgit/musl/tree/src/unistd/getcwd.c
[2] https://cgit.uclibc-ng.org/cgi/cgit/uclibc-ng.git/tree/libc/sysdeps/linux/common/getcwd.c#n38
[3] https://sourceware.org/git/?p=glibc.git;a=blob;f=sysdeps/unix/sysv/linux/getcwd.c;h=5b0b6879ed28f278f07ce494f9be30f504757daa;hb=HEAD#l47

...
> -	tst_res(TPASS | TTERRNO, "getcwd() failed as expected");
> +	TST_EXP_FAIL2(syscall(__NR_getcwd, tc->buf, tc->size), tc->exp_err);
While syscalls() would work everywhere, it's better is LTP wrapper tst_syscall()
(it TCONF in case when syscall is not implemented which is I admit nearly
impossible).

I used that and merged.
Thank you!

NOTE: we should implement .test_variants, where you just skip affected NULL
buffer test (it's enough to test it with raw syscall). Please send a patch or
let me know that you don't plan to do it and I'll do it.

Kind regards,
Petr

-- 
Mailing list info: https://lists.linux.it/listinfo/ltp

  reply	other threads:[~2023-12-01 10:14 UTC|newest]

Thread overview: 12+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2023-09-28  1:08 [LTP] [PATCH v1] getcwd01: Only check buffer NULL on glibc Wei Gao via ltp
2023-09-28  7:06 ` Richard Palethorpe
2023-09-28  8:44 ` [LTP] [PATCH v2] getcwd01: Use syscall directly check invalid argument Wei Gao via ltp
2023-09-28 17:55   ` Petr Vorel
2023-09-29  0:49     ` Wei Gao via ltp
2023-09-29  0:45   ` [LTP] [PATCH v3] " Wei Gao via ltp
2023-11-28 10:52     ` Petr Vorel
2023-12-01  3:52       ` Wei Gao via ltp
2023-11-28 10:53     ` Petr Vorel
2023-12-01  3:15     ` [LTP] [PATCH v4] " Wei Gao via ltp
2023-12-01 10:14       ` Petr Vorel [this message]
2023-12-04  0:06         ` Wei Gao via ltp

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=20231201101415.GB1710028@pevik \
    --to=pvorel@suse.cz \
    --cc=ltp@lists.linux.it \
    --cc=wegao@suse.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 an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.