From: linuxtestproject.agent@gmail.com
To: Xuewen Wang <wangxuewen_ky@163.com>
Cc: ltp@lists.linux.it
Subject: Re: [LTP] syscalls/cachestat05: Add test for permission checks
Date: Thu, 5 Nov 2026 15:58:57 +0000 [thread overview]
Message-ID: <20261105155857.3662-1-linuxtestproject.agent@gmail.com> (raw)
In-Reply-To: <20261105104617.996224-1-wangxuewen_ky@163.com>
Hi Xuewen,
On Thu Nov 5 18:46:17 2026 +0800, Xuewen Wang <wangxuewen@kylinos.cn> wrote:
> syscalls/cachestat05: Add test for permission checks
> +/*\
> + * Verify that cachestat() is only allowed on file descriptors with write
> + * access to the underlying file.
Use :manpage:`cachestat(2)` when referring to the syscall in the
documentation comment block.
> +static struct tcase {
> + const char *file;
> + int open_flags;
> + int exp_errno;
> + int needs_fix;
> + const char *desc;
> +} tcases[] = {
> + {FILE_RDWR, O_RDWR, 0, 0, "descriptor open for writing"},
> + {FILE_OWNED, O_RDONLY, 0, 0, "file owned by the caller"},
> + {FILE_RDWR, O_RDONLY, 0, 0, "file writable by the caller"},
> + {FILE_RDONLY, O_RDONLY, EPERM, 1, "file read-only for the caller"},
> +};
> +
> +static void verify_cachestat(unsigned int n)
> +{
> + struct tcase *tc = &tcases[n];
> + int fd;
> +
> + if (tc->needs_fix && tst_kvercmp(6, 14, 0) < 0) {
> + tst_res(TCONF, "cachestat() permission check added in v6.14");
> + return;
> + }
Remove the kernel version check and tc->needs_fix. Commit 5f537664e705 is a
bug fix already recorded in .tags, so unpatched kernels should fail and print
the missing-fix hint rather than skipping with TCONF.
> + SAFE_SETGROUPS(0, NULL);
> + SAFE_SETGID(gid);
> + SAFE_SETUID(uid);
> +
> + fd = SAFE_OPEN(tc->file, tc->open_flags);
Opening FILE_RDWR (mode 0666) after dropping privileges means the caller also
has write permission on the file, so the FMODE_WRITE check in
can_do_cachestat() is not isolated from file_permission(f, MAY_WRITE). Open
tc->file before dropping privileges and use FILE_RDONLY with O_RDWR for the
first test case.
> + fd = SAFE_OPEN(FILE_OWNED, O_CREAT | O_RDWR, 0600);
> + SAFE_CLOSE(fd);
> + SAFE_CHOWN(FILE_OWNED, uid, -1);
FILE_OWNED is created with mode 0600, which gives the owner write permission
and satisfies file_permission(f, MAY_WRITE) in addition to
file_owner_or_capable(). Create FILE_OWNED with mode 0400 so the ownership
check is tested without write permission.
Verdict - Needs revision
---
Note:
The agent can sometimes produce false positives although often its
findings are genuine. If you find issues with the review, please
comment this email or ignore the suggestions.
Regards,
LTP AI Reviewer
--
Mailing list info: https://lists.linux.it/listinfo/ltp
next prev parent reply other threads:[~2026-11-05 15:59 UTC|newest]
Thread overview: 3+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-11-05 10:46 [LTP] [PATCH] syscalls/cachestat05: Add test for permission checks Xuewen Wang
2026-11-05 15:58 ` linuxtestproject.agent [this message]
-- strict thread matches above, loose matches on Subject: below --
2026-11-06 3:29 [LTP] [PATCH v2] " Xuewen Wang
2026-11-06 11:34 ` [LTP] " linuxtestproject.agent
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=20261105155857.3662-1-linuxtestproject.agent@gmail.com \
--to=linuxtestproject.agent@gmail.com \
--cc=ltp@lists.linux.it \
--cc=wangxuewen_ky@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