* [LTP] [PATCH] fsconfig03: Fix return value validation on older kernels
@ 2023-03-02 10:35 Martin Doucha
2023-03-02 10:47 ` Petr Vorel
0 siblings, 1 reply; 2+ messages in thread
From: Martin Doucha @ 2023-03-02 10:35 UTC (permalink / raw)
To: ltp
On older kernels, Btrfs is not the only filesystem using the legacy
fsconfig() handlers. Assume that fsconfig() is using legacy_parse_param()
and allow it to return success regardless of filesystem up until the point
where the legacy buffer would get full.
Signed-off-by: Martin Doucha <mdoucha@suse.cz>
---
Tested on kernel 5.3 both with and without the CVE fix.
.../kernel/syscalls/fsconfig/fsconfig03.c | 27 +++++++++++++++----
1 file changed, 22 insertions(+), 5 deletions(-)
diff --git a/testcases/kernel/syscalls/fsconfig/fsconfig03.c b/testcases/kernel/syscalls/fsconfig/fsconfig03.c
index 7ee37f4ae..e891c9f98 100644
--- a/testcases/kernel/syscalls/fsconfig/fsconfig03.c
+++ b/testcases/kernel/syscalls/fsconfig/fsconfig03.c
@@ -45,11 +45,21 @@ static void run(void)
/* use same logic in kernel legacy_parse_param function */
const size_t len = i * (strlen(val) + 2) + (strlen(val) + 1) + 2;
- if (!strcmp(tst_device->fs_type, "btrfs") && len <= (size_t)pagesize)
- TST_EXP_PASS_SILENT(fsconfig(fd, FSCONFIG_SET_STRING, "\x00", val, 0));
- else
- TST_EXP_FAIL_SILENT(fsconfig(fd, FSCONFIG_SET_STRING, "\x00", val, 0),
- EINVAL);
+ TEST(fsconfig(fd, FSCONFIG_SET_STRING, "\x00", val, 0));
+
+ /* Legacy fsconfig() just copies arguments to buffer */
+ if (!TST_RET && len <= (size_t)pagesize)
+ continue;
+
+ if (!TST_RET) {
+ tst_res(TFAIL, "fsconfig() passed unexpectedly");
+ } else if (TST_RET != -1) {
+ tst_brk(TBROK | TTERRNO,
+ "Invalid fsconfig() return value %ld", TST_RET);
+ } else if (TST_ERR != EINVAL) {
+ tst_res(TFAIL | TTERRNO,
+ "fsconfig() failed with unexpected error");
+ }
}
if (fd != -1)
@@ -63,9 +73,16 @@ static void run(void)
tst_device->fs_type);
}
+static void cleanup(void)
+{
+ if (fd >= 0)
+ SAFE_CLOSE(fd);
+}
+
static struct tst_test test = {
.test_all = run,
.setup = setup,
+ .cleanup = cleanup,
.needs_root = 1,
.format_device = 1,
.mntpoint = MNTPOINT,
--
2.39.0
--
Mailing list info: https://lists.linux.it/listinfo/ltp
^ permalink raw reply related [flat|nested] 2+ messages in thread
* Re: [LTP] [PATCH] fsconfig03: Fix return value validation on older kernels
2023-03-02 10:35 [LTP] [PATCH] fsconfig03: Fix return value validation on older kernels Martin Doucha
@ 2023-03-02 10:47 ` Petr Vorel
0 siblings, 0 replies; 2+ messages in thread
From: Petr Vorel @ 2023-03-02 10:47 UTC (permalink / raw)
To: Martin Doucha; +Cc: ltp
Hi Martin,
> On older kernels, Btrfs is not the only filesystem using the legacy
> fsconfig() handlers. Assume that fsconfig() is using legacy_parse_param()
> and allow it to return success regardless of filesystem up until the point
> where the legacy buffer would get full.
LGTM, thanks!
Reviewed-by: Petr Vorel <pvorel@suse.cz>
> Signed-off-by: Martin Doucha <mdoucha@suse.cz>
> ---
> Tested on kernel 5.3 both with and without the CVE fix.
Obviously still works on new kernel as well (tested on 6.1.x).
Kind regards,
Petr
--
Mailing list info: https://lists.linux.it/listinfo/ltp
^ permalink raw reply [flat|nested] 2+ messages in thread
end of thread, other threads:[~2023-03-02 10:47 UTC | newest]
Thread overview: 2+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2023-03-02 10:35 [LTP] [PATCH] fsconfig03: Fix return value validation on older kernels Martin Doucha
2023-03-02 10:47 ` Petr Vorel
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox