From patchwork Thu Mar 2 10:35:52 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Martin Doucha X-Patchwork-Id: 1750618 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@legolas.ozlabs.org Authentication-Results: legolas.ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=lists.linux.it (client-ip=2001:1418:10:5::2; helo=picard.linux.it; envelope-from=ltp-bounces+incoming=patchwork.ozlabs.org@lists.linux.it; receiver=) Authentication-Results: legolas.ozlabs.org; dkim=fail reason="signature verification failed" (1024-bit key; unprotected) header.d=suse.cz header.i=@suse.cz header.a=rsa-sha256 header.s=susede2_rsa header.b=OGafIo6k; dkim=fail reason="signature verification failed" header.d=suse.cz header.i=@suse.cz header.a=ed25519-sha256 header.s=susede2_ed25519 header.b=bZNeN/M+; dkim-atps=neutral Received: from picard.linux.it (picard.linux.it [IPv6:2001:1418:10:5::2]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (P-384) server-digest SHA384) (No client certificate requested) by legolas.ozlabs.org (Postfix) with ESMTPS id 4PS6wV4lqrz1yWx for ; Thu, 2 Mar 2023 21:36:42 +1100 (AEDT) Received: from picard.linux.it (localhost [IPv6:::1]) by picard.linux.it (Postfix) with ESMTP id 428103CBA2E for ; Thu, 2 Mar 2023 11:36:40 +0100 (CET) X-Original-To: ltp@lists.linux.it Delivered-To: ltp@picard.linux.it Received: from in-2.smtp.seeweb.it (in-2.smtp.seeweb.it [IPv6:2001:4b78:1:20::2]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (P-384) server-digest SHA384) (No client certificate requested) by picard.linux.it (Postfix) with ESMTPS id BB3F23CB9C9 for ; Thu, 2 Mar 2023 11:36:36 +0100 (CET) Received: from smtp-out2.suse.de (smtp-out2.suse.de [IPv6:2001:67c:2178:6::1d]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits) server-digest SHA256) (No client certificate requested) by in-2.smtp.seeweb.it (Postfix) with ESMTPS id 4D8D060085E for ; Thu, 2 Mar 2023 11:36:35 +0100 (CET) Received: from imap2.suse-dmz.suse.de (imap2.suse-dmz.suse.de [192.168.254.74]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (P-521) server-digest SHA512) (No client certificate requested) by smtp-out2.suse.de (Postfix) with ESMTPS id 2F0171FE65 for ; Thu, 2 Mar 2023 10:36:35 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=suse.cz; s=susede2_rsa; t=1677753395; h=from:from:reply-to:date:date:message-id:message-id:to:to:cc: mime-version:mime-version: content-transfer-encoding:content-transfer-encoding; bh=9f7fRcoy++uWfQbtJ29ahHo3uaSY70x73p3VE5tPYGU=; b=OGafIo6kEw/++n4x23mhG/Ly1z5vPIocOzFq0tRilQId3PVpxuAud9wKCe796Q44K5QwJd nRCdpEiSc5fKDtsucQBfAcOsZCo21O8iA1owlkDuBj5UpocCx5hZ7C7KKXvY1CmpVmRYQ/ kwMmDQR2XQWYeArai6vH4UwqVoeIt0g= DKIM-Signature: v=1; a=ed25519-sha256; c=relaxed/relaxed; d=suse.cz; s=susede2_ed25519; t=1677753395; h=from:from:reply-to:date:date:message-id:message-id:to:to:cc: mime-version:mime-version: content-transfer-encoding:content-transfer-encoding; bh=9f7fRcoy++uWfQbtJ29ahHo3uaSY70x73p3VE5tPYGU=; b=bZNeN/M+JwFuxC+6HN+6K28/uvIOrzWGah8Lt6plLXXKLQ9NuneyCiWjJG7g+1GL2NUQXK JAHOwhWpnWdYS5Dg== Received: from imap2.suse-dmz.suse.de (imap2.suse-dmz.suse.de [192.168.254.74]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (P-521) server-digest SHA512) (No client certificate requested) by imap2.suse-dmz.suse.de (Postfix) with ESMTPS id 2068813349 for ; Thu, 2 Mar 2023 10:36:35 +0000 (UTC) Received: from dovecot-director2.suse.de ([192.168.254.65]) by imap2.suse-dmz.suse.de with ESMTPSA id ynIxBzN8AGR3YAAAMHmgww (envelope-from ) for ; Thu, 02 Mar 2023 10:36:35 +0000 From: Martin Doucha To: ltp@lists.linux.it Date: Thu, 2 Mar 2023 11:35:52 +0100 Message-Id: <20230302103552.10800-1-mdoucha@suse.cz> X-Mailer: git-send-email 2.39.0 MIME-Version: 1.0 X-Virus-Scanned: clamav-milter 0.102.4 at in-2.smtp.seeweb.it X-Virus-Status: Clean X-Spam-Status: No, score=0.1 required=7.0 tests=DKIM_SIGNED,DKIM_VALID, DKIM_VALID_AU,DKIM_VALID_EF,SPF_HELO_NONE,SPF_SOFTFAIL autolearn=disabled version=3.4.4 X-Spam-Checker-Version: SpamAssassin 3.4.4 (2020-01-24) on in-2.smtp.seeweb.it Subject: [LTP] [PATCH] fsconfig03: Fix return value validation on older kernels X-BeenThere: ltp@lists.linux.it X-Mailman-Version: 2.1.29 Precedence: list List-Id: Linux Test Project List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: ltp-bounces+incoming=patchwork.ozlabs.org@lists.linux.it Sender: "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 Reviewed-by: Petr Vorel --- 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,