From: Cyril Hrubis <chrubis@suse.cz>
To: "Ricardo B. Marlière" <rbm@suse.com>
Cc: Linux Test Project <ltp@lists.linux.it>
Subject: Re: [LTP] [PATCH v5 4/4] syscalls: lchown03: Merge into lchown02
Date: Wed, 10 Sep 2025 17:51:25 +0200 [thread overview]
Message-ID: <aMGeffv7V-wbLfCQ@yuki.lan> (raw)
In-Reply-To: <DCOCPDWMUTF5.PXSIFKQYF1IW@suse.com>
Hi!
> > Trying to resolve either of these ends up in ELOOP.
>
> I don't think that will work for lchown, from it's man page:
>
> • lchown() is like chown(), but does not dereference symbolic links.
>
> I guess the original code works because the final component is not a link.
Ah, yes, it's not as easy with lchown since the last component must not
be a link, otherwise the call acts on the link.
And the original code creates a directory that points to itself, i.e.
longpath/longpath points to ../longpath so each time longpath is
resolved it just returns back. And with that we can trigger ELOOP by
stacking enough of these redirections, which is the reason why we
managed to get that. We would get the same result if we stacked enough
links, e.g. symlink("a", "b"), symlink("b", "c") ... symlink("y", "z")
and then trying to resolve "z/file" which may be less confusing than the
directory pointing to itself magic.
> Here's the diff (fails with EPERM):
It should have succeeded though, I suppose that it fails with EPERM
because you added the code to create the symlinks before the test
switches to the test user.
> diff --git a/testcases/kernel/syscalls/lchown/lchown02.c b/testcases/kernel/syscalls/lchown/lchown02.c
> index db068865acdc..db8b29c61d07 100644
> --- a/testcases/kernel/syscalls/lchown/lchown02.c
> +++ b/testcases/kernel/syscalls/lchown/lchown02.c
> @@ -33,6 +33,7 @@
> #define SFILE2 "testdir_1/sfile_2"
> #define TFILE3 "t_file"
> #define SFILE3 "t_file/sfile"
> +#define EFILE1 "eloop"
> #define TEST_EROFS "mntpoint"
> #define MAXPATH (PATH_MAX+2)
>
> @@ -42,7 +43,7 @@ static char *bad_addr;
> static char *maxpath;
> static char *sfile3;
> static char *empty;
> -static char *longpath;
> +static char *eloop;
> static char *erofs;
> static struct passwd *ltpuser;
>
> @@ -57,20 +58,15 @@ static struct test_case_t {
> { &maxpath, "Pathname too long", ENAMETOOLONG },
> { &sfile3, "Path contains regular file", ENOTDIR },
> { &empty, "Pathname is empty", ENOENT },
> - { &longpath, "Too many symlinks", ELOOP },
> + { &eloop, "Too many symlinks", ELOOP },
> { &erofs, "Read-only filesystem", EROFS },
> };
>
> static void run(unsigned int i)
> {
> - uid_t user_id;
> - gid_t group_id;
> struct test_case_t *tc = &test_cases[i];
>
> - UID16_CHECK((user_id = geteuid()), "lchown");
> - GID16_CHECK((group_id = getegid()), "lchown");
> -
> - TST_EXP_FAIL(lchown(*tc->pathname, user_id, group_id), tc->exp_errno, "%s", tc->desc);
> + TST_EXP_FAIL(lchown(*tc->pathname, ltpuser->pw_uid, ltpuser->pw_gid), tc->exp_errno, "%s", tc->desc);
> }
>
> static void setup(void)
> @@ -80,15 +76,21 @@ static void setup(void)
> memset(maxpath, 'a', MAXPATH - 1);
> maxpath[MAXPATH-1] = 0;
>
> - snprintf(longpath, sizeof(longpath), ".");
> - SAFE_MKDIR("longpath", 0755);
> - SAFE_SYMLINK("../longpath", "longpath/longpath");
> - for (int i = 0; i < 43; i++)
> - strcat(longpath, "/longpath");
> + // snprintf(longpath, sizeof(longpath), ".");
> + // SAFE_MKDIR("longpath", 0755);
> + // SAFE_SYMLINK("../longpath", "longpath/longpath");
> + // for (int i = 0; i < 43; i++)
> + // strcat(longpath, "/longpath");
> +
> + SAFE_SYMLINK(EFILE1, "infinite_loop");
> + SAFE_SYMLINK("infinite_loop", EFILE1);
>
> ltpuser = SAFE_GETPWNAM(TEST_USER);
> SAFE_SETGID(ltpuser->pw_uid);
>
> + UID16_CHECK(ltpuser->pw_uid, "lchown");
> + GID16_CHECK(ltpuser->pw_gid, "lchown");
> +
> SAFE_TOUCH(TFILE1, 0666, NULL);
> SAFE_SETEUID(0);
> SAFE_SYMLINK(TFILE1, SFILE1);
> @@ -115,7 +117,7 @@ static struct tst_test test = {
> {&sfile1, .str = SFILE1},
> {&sfile2, .str = SFILE2},
> {&sfile3, .str = SFILE3},
> - {&longpath, .size = PATH_MAX},
> + {&eloop, .str = EFILE1},
> {&empty, .str = ""},
> { &erofs, .str = TEST_EROFS },
> {}
>
>
--
Cyril Hrubis
chrubis@suse.cz
--
Mailing list info: https://lists.linux.it/listinfo/ltp
next prev parent reply other threads:[~2025-09-10 15:51 UTC|newest]
Thread overview: 12+ messages / expand[flat|nested] mbox.gz Atom feed top
2025-08-29 21:01 [LTP] [PATCH v5 0/4] syscalls: lchown: Convert to new API Ricardo B. Marlière via ltp
2025-08-29 21:02 ` [LTP] [PATCH v5 1/4] lib: Add SAFE_LCHOWN Ricardo B. Marlière via ltp
2025-08-29 21:02 ` [LTP] [PATCH v5 2/4] syscalls: lchown01: Convert to new API Ricardo B. Marlière via ltp
2025-09-02 13:41 ` Cyril Hrubis
2025-08-29 21:02 ` [LTP] [PATCH v5 3/4] syscalls: lchown02: " Ricardo B. Marlière via ltp
2025-09-02 14:20 ` Cyril Hrubis
2025-08-29 21:02 ` [LTP] [PATCH v5 4/4] syscalls: lchown03: Merge into lchown02 Ricardo B. Marlière via ltp
2025-09-02 14:27 ` Cyril Hrubis
2025-09-09 14:48 ` Ricardo B. Marlière via ltp
2025-09-10 15:51 ` Cyril Hrubis [this message]
2025-09-10 16:26 ` Cyril Hrubis
2025-09-10 22:16 ` Ricardo B. Marlière 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=aMGeffv7V-wbLfCQ@yuki.lan \
--to=chrubis@suse.cz \
--cc=ltp@lists.linux.it \
--cc=rbm@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.