From patchwork Fri Aug 11 11:56:41 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Cyril Hrubis X-Patchwork-Id: 1820249 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=213.254.12.146; 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=W+zCoZcv; dkim=fail reason="signature verification failed" header.d=suse.cz header.i=@suse.cz header.a=ed25519-sha256 header.s=susede2_ed25519 header.b=2Stua3QB; dkim-atps=neutral Received: from picard.linux.it (picard.linux.it [213.254.12.146]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (P-384)) (No client certificate requested) by legolas.ozlabs.org (Postfix) with ESMTPS id 4RMj1q1dmkz1yf7 for ; Fri, 11 Aug 2023 21:56:31 +1000 (AEST) Received: from picard.linux.it (localhost [IPv6:::1]) by picard.linux.it (Postfix) with ESMTP id 315DE3CD061 for ; Fri, 11 Aug 2023 13:56:29 +0200 (CEST) X-Original-To: ltp@lists.linux.it Delivered-To: ltp@picard.linux.it Received: from in-6.smtp.seeweb.it (in-6.smtp.seeweb.it [IPv6:2001:4b78:1:20::6]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (P-384)) (No client certificate requested) by picard.linux.it (Postfix) with ESMTPS id 09C853CC82C for ; Fri, 11 Aug 2023 13:55:50 +0200 (CEST) Received: from smtp-out1.suse.de (smtp-out1.suse.de [IPv6:2001:67c:2178:6::1c]) (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-6.smtp.seeweb.it (Postfix) with ESMTPS id 7D3E7140096C for ; Fri, 11 Aug 2023 13:55:48 +0200 (CEST) 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-out1.suse.de (Postfix) with ESMTPS id DA49021857 for ; Fri, 11 Aug 2023 11:55:46 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=suse.cz; s=susede2_rsa; t=1691754946; h=from:from:reply-to:date:date:message-id:message-id:to:to:cc: mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=EcnkJcVZ7awYt0eaJouCrcrHhWdyxEhyjzbZ5sRu3qU=; b=W+zCoZcvvIrAx996e8L1Q2F6Wl5mRHD22hyybyLa7F3jN3p66YF55kW5Bn1JitJCjdLI6n unnTD4Z1BIhb2Hh7UarWFJa4WPT2xvA4BYBXIJ2fkWT7ozslK5kvb7RpFUkrb+XeTro0q2 nR9dO0VDAIC+zs5vxT7PH4LavUB9arw= DKIM-Signature: v=1; a=ed25519-sha256; c=relaxed/relaxed; d=suse.cz; s=susede2_ed25519; t=1691754946; h=from:from:reply-to:date:date:message-id:message-id:to:to:cc: mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=EcnkJcVZ7awYt0eaJouCrcrHhWdyxEhyjzbZ5sRu3qU=; b=2Stua3QBnPluI8B4fAQdWqf6hC9u0zBPFM1OE1Su5bKpBf515sRVEVKU3wvOil0+Wka7yR Q3LA5lYH7sCeYYBA== 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 C83BB138E2 for ; Fri, 11 Aug 2023 11:55:46 +0000 (UTC) Received: from dovecot-director2.suse.de ([192.168.254.65]) by imap2.suse-dmz.suse.de with ESMTPSA id IRvBL8Ih1mT9WgAAMHmgww (envelope-from ) for ; Fri, 11 Aug 2023 11:55:46 +0000 From: Cyril Hrubis To: ltp@lists.linux.it Date: Fri, 11 Aug 2023 13:56:41 +0200 Message-ID: <20230811115647.32387-2-chrubis@suse.cz> X-Mailer: git-send-email 2.41.0 In-Reply-To: <20230811115647.32387-1-chrubis@suse.cz> References: <20230811115647.32387-1-chrubis@suse.cz> MIME-Version: 1.0 X-Virus-Scanned: clamav-milter 1.0.1 at in-6.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 shortcircuit=no autolearn=disabled version=4.0.0 X-Spam-Checker-Version: SpamAssassin 4.0.0 (2022-12-13) on in-6.smtp.seeweb.it Subject: [LTP] [PATCH 1/6] lib: tst_buffers: Add bufs .str and tst_aprintf() 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" Signed-off-by: Cyril Hrubis Reviewed-by: Li Wang --- include/tst_buffers.h | 11 +++++++++++ lib/tst_buffers.c | 28 +++++++++++++++++++++++++--- 2 files changed, 36 insertions(+), 3 deletions(-) diff --git a/include/tst_buffers.h b/include/tst_buffers.h index d19ac8cf0..b5f355f0f 100644 --- a/include/tst_buffers.h +++ b/include/tst_buffers.h @@ -25,6 +25,11 @@ struct tst_buffers { * Array of iov buffer sizes terminated by -1. */ int *iov_sizes; + /* + * If size and iov_sizes is NULL this is the string we want to strdup() + * into the buffer. + */ + char *str; }; /* @@ -46,6 +51,12 @@ char *tst_strdup(const char *str); */ void *tst_alloc(size_t size); +/* + * Printf into a guarded buffer. + */ +char *tst_aprintf(const char *fmt, ...) + __attribute__((format (printf, 1, 2))); + /* * Allocates iovec structure including the buffers. * diff --git a/lib/tst_buffers.c b/lib/tst_buffers.c index b8b597a12..b0bd359eb 100644 --- a/lib/tst_buffers.c +++ b/lib/tst_buffers.c @@ -5,6 +5,7 @@ #include #include +#include #define TST_NO_DEFAULT_MAIN #include "tst_test.h" @@ -76,6 +77,25 @@ void *tst_alloc(size_t size) return ret + map->buf_shift; } +char *tst_aprintf(const char *fmt, ...) +{ + va_list va; + int len; + char *ret; + + va_start(va, fmt); + len = vsnprintf(NULL, 0, fmt, va)+1; + va_end(va); + + ret = tst_alloc(len); + + va_start(va, fmt); + vsprintf(ret, fmt, va); + va_end(va); + + return ret; +} + static int count_iovec(int *sizes) { int ret = 0; @@ -115,15 +135,17 @@ void tst_buffers_alloc(struct tst_buffers bufs[]) for (i = 0; bufs[i].ptr; i++) { if (bufs[i].size) *((void**)bufs[i].ptr) = tst_alloc(bufs[i].size); - else + else if (bufs[i].iov_sizes) *((void**)bufs[i].ptr) = tst_iovec_alloc(bufs[i].iov_sizes); + else + *((void**)bufs[i].ptr) = tst_strdup(bufs[i].str); } } char *tst_strdup(const char *str) { - size_t len = strlen(str); - char *ret = tst_alloc(len + 1); + char *ret = tst_alloc(strlen(str) + 1); + return strcpy(ret, str); } From patchwork Fri Aug 11 11:56:43 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Cyril Hrubis X-Patchwork-Id: 1820246 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=VnOI96o1; dkim=fail reason="signature verification failed" header.d=suse.cz header.i=@suse.cz header.a=ed25519-sha256 header.s=susede2_ed25519 header.b=w15TK23G; 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 4RMj1D6JbLz1yfH for ; Fri, 11 Aug 2023 21:55:59 +1000 (AEST) Received: from picard.linux.it (localhost [IPv6:::1]) by picard.linux.it (Postfix) with ESMTP id 0AC223CD057 for ; Fri, 11 Aug 2023 13:55:51 +0200 (CEST) X-Original-To: ltp@lists.linux.it Delivered-To: ltp@picard.linux.it Received: from in-6.smtp.seeweb.it (in-6.smtp.seeweb.it [IPv6:2001:4b78:1:20::6]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (P-384)) (No client certificate requested) by picard.linux.it (Postfix) with ESMTPS id A790E3C89B6 for ; Fri, 11 Aug 2023 13:55:48 +0200 (CEST) Received: from smtp-out2.suse.de (smtp-out2.suse.de [195.135.220.29]) (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-6.smtp.seeweb.it (Postfix) with ESMTPS id 1C9421400452 for ; Fri, 11 Aug 2023 13:55:48 +0200 (CEST) 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 DC4A81F459 for ; Fri, 11 Aug 2023 11:55:47 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=suse.cz; s=susede2_rsa; t=1691754947; h=from:from:reply-to:date:date:message-id:message-id:to:to:cc: mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=KQS8Uzww3HQ0/XobznIZGyRe79qMWJo2hX3T+geqwY4=; b=VnOI96o1FmpWezyTgDn7yGuYpBzX3fLjwi46a3aVN4xKpows413c8qzjmZFrhUDDH8XV9R s3fYTsoqo+MiYwQ99yf8dEM2RIRVffwM+X14tncbGA/EBTRUaDnDBem8u1I9lB5FFhYkxq Ja1prbFsIWgqWWITGSxjWEASAjNdX68= DKIM-Signature: v=1; a=ed25519-sha256; c=relaxed/relaxed; d=suse.cz; s=susede2_ed25519; t=1691754947; h=from:from:reply-to:date:date:message-id:message-id:to:to:cc: mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=KQS8Uzww3HQ0/XobznIZGyRe79qMWJo2hX3T+geqwY4=; b=w15TK23G0p8ab063qTujGzme31RYmjTzNosRTdiinroYyOn8/oCRksXVy1LPegaRgpTQaf 3MlL5jAI+delryBA== 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 C8179138E2 for ; Fri, 11 Aug 2023 11:55:47 +0000 (UTC) Received: from dovecot-director2.suse.de ([192.168.254.65]) by imap2.suse-dmz.suse.de with ESMTPSA id NaOeL8Mh1mQFWwAAMHmgww (envelope-from ) for ; Fri, 11 Aug 2023 11:55:47 +0000 From: Cyril Hrubis To: ltp@lists.linux.it Date: Fri, 11 Aug 2023 13:56:43 +0200 Message-ID: <20230811115647.32387-4-chrubis@suse.cz> X-Mailer: git-send-email 2.41.0 In-Reply-To: <20230811115647.32387-1-chrubis@suse.cz> References: <20230811115647.32387-1-chrubis@suse.cz> MIME-Version: 1.0 X-Virus-Scanned: clamav-milter 1.0.1 at in-6.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_PASS shortcircuit=no autolearn=disabled version=4.0.0 X-Spam-Checker-Version: SpamAssassin 4.0.0 (2022-12-13) on in-6.smtp.seeweb.it Subject: [LTP] [PATCH 2/6] syscalls/access04: Make use of guarded buffers 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" Signed-off-by: Cyril Hrubis --- testcases/kernel/syscalls/access/access04.c | 36 +++++++++++++++------ 1 file changed, 26 insertions(+), 10 deletions(-) diff --git a/testcases/kernel/syscalls/access/access04.c b/testcases/kernel/syscalls/access/access04.c index 424fe6f10..b5764a5dd 100644 --- a/testcases/kernel/syscalls/access/access04.c +++ b/testcases/kernel/syscalls/access/access04.c @@ -40,26 +40,32 @@ #define SNAME1 "symlink1" #define SNAME2 "symlink2" #define MNT_POINT "mntpoint" +#define LONGPATHSIZE (PATH_MAX + 2) static uid_t uid; -static char longpathname[PATH_MAX + 2]; +static char *longpathname; +static char *fname1; +static char *fname2; +static char *sname1; +static char *empty_fname; +static char *mnt_point; static struct tcase { - const char *pathname; + char **pathname; int mode; int exp_errno; } tcases[] = { - {FNAME1, -1, EINVAL}, - {"", W_OK, ENOENT}, - {longpathname, R_OK, ENAMETOOLONG}, - {FNAME2, R_OK, ENOTDIR}, - {SNAME1, R_OK, ELOOP}, - {MNT_POINT, W_OK, EROFS} + {&fname1, -1, EINVAL}, + {&empty_fname, W_OK, ENOENT}, + {&longpathname, R_OK, ENAMETOOLONG}, + {&fname2, R_OK, ENOTDIR}, + {&sname1, R_OK, ELOOP}, + {&mnt_point, W_OK, EROFS} }; static void access_test(struct tcase *tc, const char *user) { - TST_EXP_FAIL(access(tc->pathname, tc->mode), tc->exp_errno, + TST_EXP_FAIL(access(*tc->pathname, tc->mode), tc->exp_errno, "access as %s", user); } @@ -87,7 +93,8 @@ static void setup(void) uid = pw->pw_uid; - memset(longpathname, 'a', sizeof(longpathname) - 1); + memset(longpathname, 'a', LONGPATHSIZE - 1); + longpathname[LONGPATHSIZE-1] = 0; SAFE_TOUCH(FNAME1, 0333, NULL); SAFE_TOUCH(DNAME, 0644, NULL); @@ -104,4 +111,13 @@ static struct tst_test test = { .mntpoint = MNT_POINT, .setup = setup, .test = verify_access, + .bufs = (struct tst_buffers []) { + {&fname1, .str = FNAME1}, + {&fname2, .str = FNAME2}, + {&sname1, .str = SNAME1}, + {&empty_fname, .str = ""}, + {&longpathname, .size = LONGPATHSIZE}, + {&mnt_point, .str = MNT_POINT}, + {} + } }; From patchwork Fri Aug 11 11:56:44 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Cyril Hrubis X-Patchwork-Id: 1820248 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=213.254.12.146; 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=ibiLFM7q; dkim=fail reason="signature verification failed" header.d=suse.cz header.i=@suse.cz header.a=ed25519-sha256 header.s=susede2_ed25519 header.b=fhtm3Gz2; dkim-atps=neutral Received: from picard.linux.it (picard.linux.it [213.254.12.146]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (P-384)) (No client certificate requested) by legolas.ozlabs.org (Postfix) with ESMTPS id 4RMj1b08fSz1yf7 for ; Fri, 11 Aug 2023 21:56:19 +1000 (AEST) Received: from picard.linux.it (localhost [IPv6:::1]) by picard.linux.it (Postfix) with ESMTP id 047BE3CD07D for ; Fri, 11 Aug 2023 13:56:17 +0200 (CEST) X-Original-To: ltp@lists.linux.it Delivered-To: ltp@picard.linux.it Received: from in-3.smtp.seeweb.it (in-3.smtp.seeweb.it [217.194.8.3]) (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 EEDD43C89B6 for ; Fri, 11 Aug 2023 13:55:49 +0200 (CEST) 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-3.smtp.seeweb.it (Postfix) with ESMTPS id 61D7E1A006B7 for ; Fri, 11 Aug 2023 13:55:49 +0200 (CEST) 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 9DC981F459 for ; Fri, 11 Aug 2023 11:55:48 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=suse.cz; s=susede2_rsa; t=1691754948; h=from:from:reply-to:date:date:message-id:message-id:to:to:cc: mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=N61fDO53vtww7oFpWb5zcjRXI3K5Mf7PJi69nM/vqIU=; b=ibiLFM7q06MBii+z9QoJOMtMHg/VDSm7rjFBmXuUgmFXydtyiWcnkeYEk97yg5LGZdLwHl ZHWiOh8KXf8VbraojYH3LOlzcQcFm9JWw9MzuHl2llMe/tHtIL3fUTnuuXCnry5kbsIJ1W qH+T3vY7lsgkW/29160v50sr+MR6pQ8= DKIM-Signature: v=1; a=ed25519-sha256; c=relaxed/relaxed; d=suse.cz; s=susede2_ed25519; t=1691754948; h=from:from:reply-to:date:date:message-id:message-id:to:to:cc: mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=N61fDO53vtww7oFpWb5zcjRXI3K5Mf7PJi69nM/vqIU=; b=fhtm3Gz2B9/LQfJ5ZoguDDO5V9ZPefhR01xqyB3TWnol3N/jTdfFS3H8TaxspM8t9D8XdC UbSzvGjd7HJl0aDA== 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 7ED81138E2 for ; Fri, 11 Aug 2023 11:55:48 +0000 (UTC) Received: from dovecot-director2.suse.de ([192.168.254.65]) by imap2.suse-dmz.suse.de with ESMTPSA id qP24HcQh1mQHWwAAMHmgww (envelope-from ) for ; Fri, 11 Aug 2023 11:55:48 +0000 From: Cyril Hrubis To: ltp@lists.linux.it Date: Fri, 11 Aug 2023 13:56:44 +0200 Message-ID: <20230811115647.32387-5-chrubis@suse.cz> X-Mailer: git-send-email 2.41.0 In-Reply-To: <20230811115647.32387-1-chrubis@suse.cz> References: <20230811115647.32387-1-chrubis@suse.cz> MIME-Version: 1.0 X-Virus-Scanned: clamav-milter 1.0.1 at in-3.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 shortcircuit=no autolearn=disabled version=4.0.0 X-Spam-Checker-Version: SpamAssassin 4.0.0 (2022-12-13) on in-3.smtp.seeweb.it Subject: [LTP] [PATCH 3/6] syscalls/acct01: Make use of guarded buffers 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" Signed-off-by: Cyril Hrubis --- testcases/kernel/syscalls/acct/acct01.c | 84 +++++++++++++------------ 1 file changed, 45 insertions(+), 39 deletions(-) diff --git a/testcases/kernel/syscalls/acct/acct01.c b/testcases/kernel/syscalls/acct/acct01.c index 254d7b503..52c4d41da 100644 --- a/testcases/kernel/syscalls/acct/acct01.c +++ b/testcases/kernel/syscalls/acct/acct01.c @@ -27,17 +27,25 @@ #define DIR_MODE (S_IRUSR|S_IWUSR|S_IXUSR|S_IRGRP| \ S_IXGRP|S_IROTH|S_IXOTH) #define FILE_EISDIR "." -#define FILE_EACCES "/dev/null" +#define FILE_EACCESS "/dev/null" #define FILE_ENOENT "/tmp/does/not/exist" #define FILE_ENOTDIR "./tmpfile/" -#define TEST_TMPFILE "./tmpfile" -#define TEST_ELOOP "test_file_eloop1" -#define TEST_ENAMETOOLONG nametoolong -#define TEST_EROFS "mntpoint/file" +#define FILE_TMPFILE "./tmpfile" +#define FILE_ELOOP "test_file_eloop1" +#define FILE_EROFS "ro_mntpoint/file" -static char nametoolong[PATH_MAX+2]; static struct passwd *ltpuser; +static char *file_eisdir; +static char *file_eaccess; +static char *file_enoent; +static char *file_enotdir; +static char *file_tmpfile; +static char *file_eloop; +static char *file_enametoolong; +static char *file_erofs; +static char *file_null; + static void setup_euid(void) { SAFE_SETEUID(ltpuser->pw_uid); @@ -49,21 +57,21 @@ static void cleanup_euid(void) } static struct test_case { - char *filename; - char *exp_errval; + char **filename; + char *desc; int exp_errno; void (*setupfunc) (); void (*cleanfunc) (); } tcases[] = { - {FILE_EISDIR, "EISDIR", EISDIR, NULL, NULL}, - {FILE_EACCES, "EACCES", EACCES, NULL, NULL}, - {FILE_ENOENT, "ENOENT", ENOENT, NULL, NULL}, - {FILE_ENOTDIR, "ENOTDIR", ENOTDIR, NULL, NULL}, - {TEST_TMPFILE, "EPERM", EPERM, setup_euid, cleanup_euid}, - {NULL, "EPERM", EPERM, setup_euid, cleanup_euid}, - {TEST_ELOOP, "ELOOP", ELOOP, NULL, NULL}, - {TEST_ENAMETOOLONG, "ENAMETOOLONG", ENAMETOOLONG, NULL, NULL}, - {TEST_EROFS, "EROFS", EROFS, NULL, NULL}, + {&file_eisdir, FILE_EISDIR, EISDIR, NULL, NULL}, + {&file_eaccess, FILE_EACCESS, EACCES, NULL, NULL}, + {&file_enoent, FILE_ENOENT, ENOENT, NULL, NULL}, + {&file_enotdir, FILE_ENOTDIR, ENOTDIR, NULL, NULL}, + {&file_tmpfile, FILE_TMPFILE, EPERM, setup_euid, cleanup_euid}, + {&file_null, "NULL", EPERM, setup_euid, cleanup_euid}, + {&file_eloop, FILE_ELOOP, ELOOP, NULL, NULL}, + {&file_enametoolong, "aaaa...", ENAMETOOLONG, NULL, NULL}, + {&file_erofs, FILE_EROFS, EROFS, NULL, NULL}, }; static void setup(void) @@ -76,10 +84,10 @@ static void setup(void) ltpuser = SAFE_GETPWNAM("nobody"); - fd = SAFE_CREAT(TEST_TMPFILE, 0777); + fd = SAFE_CREAT(FILE_TMPFILE, 0777); SAFE_CLOSE(fd); - TEST(acct(TEST_TMPFILE)); + TEST(acct(FILE_TMPFILE)); if (TST_RET == -1) tst_brk(TBROK | TTERRNO, "acct failed unexpectedly"); @@ -89,11 +97,11 @@ static void setup(void) tst_brk(TBROK | TTERRNO, "acct(NULL) failed"); /* ELOOP SETTING */ - SAFE_SYMLINK(TEST_ELOOP, "test_file_eloop2"); - SAFE_SYMLINK("test_file_eloop2", TEST_ELOOP); + SAFE_SYMLINK(FILE_ELOOP, "test_file_eloop2"); + SAFE_SYMLINK("test_file_eloop2", FILE_ELOOP); - /* ENAMETOOLONG SETTING */ - memset(nametoolong, 'a', PATH_MAX+1); + memset(file_enametoolong, 'a', PATH_MAX+1); + file_enametoolong[PATH_MAX+1] = 0; } static void verify_acct(unsigned int nr) @@ -103,31 +111,29 @@ static void verify_acct(unsigned int nr) if (tcase->setupfunc) tcase->setupfunc(); - TEST(acct(tcase->filename)); + TST_EXP_FAIL(acct(*tcase->filename), tcase->exp_errno, + "acct(%s)", tcase->desc); if (tcase->cleanfunc) tcase->cleanfunc(); - - if (TST_RET != -1) { - tst_res(TFAIL, "acct(%s) succeeded unexpectedly", - tcase->filename); - return; - } - - if (TST_ERR == tcase->exp_errno) { - tst_res(TPASS | TTERRNO, "acct() failed as expected"); - } else { - tst_res(TFAIL | TTERRNO, - "acct() failed, expected: %s", - tst_strerrno(tcase->exp_errno)); - } } static struct tst_test test = { .needs_root = 1, - .mntpoint = "mntpoint", + .mntpoint = "ro_mntpoint", .needs_rofs = 1, .tcnt = ARRAY_SIZE(tcases), .setup = setup, .test = verify_acct, + .bufs = (struct tst_buffers []) { + {&file_eisdir, .str = FILE_EISDIR}, + {&file_eaccess, .str = FILE_EACCESS}, + {&file_enoent, .str = FILE_ENOENT}, + {&file_enotdir, .str = FILE_ENOTDIR}, + {&file_tmpfile, .str = FILE_TMPFILE}, + {&file_eloop, .str = FILE_ELOOP}, + {&file_enametoolong, .size = PATH_MAX+2}, + {&file_erofs, .str = FILE_EROFS}, + {} + } }; From patchwork Fri Aug 11 11:56:45 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Cyril Hrubis X-Patchwork-Id: 1820250 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=BZjWCI2M; dkim=fail reason="signature verification failed" header.d=suse.cz header.i=@suse.cz header.a=ed25519-sha256 header.s=susede2_ed25519 header.b=e6vRRSQ+; 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 4RMj244FCBz1yf7 for ; Fri, 11 Aug 2023 21:56:44 +1000 (AEST) Received: from picard.linux.it (localhost [IPv6:::1]) by picard.linux.it (Postfix) with ESMTP id 61E123CD1B8 for ; Fri, 11 Aug 2023 13:56:41 +0200 (CEST) X-Original-To: ltp@lists.linux.it Delivered-To: ltp@picard.linux.it Received: from in-5.smtp.seeweb.it (in-5.smtp.seeweb.it [217.194.8.5]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (P-384)) (No client certificate requested) by picard.linux.it (Postfix) with ESMTPS id 2A0F63C89B6 for ; Fri, 11 Aug 2023 13:55:50 +0200 (CEST) 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-5.smtp.seeweb.it (Postfix) with ESMTPS id 6EEAB6008C1 for ; Fri, 11 Aug 2023 13:55:49 +0200 (CEST) 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 149CD1F88C for ; Fri, 11 Aug 2023 11:55:49 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=suse.cz; s=susede2_rsa; t=1691754949; h=from:from:reply-to:date:date:message-id:message-id:to:to:cc: mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=VUrZgmFPDGTXQputdMxfXVGV3vYAi++YOW+ukJlAxIE=; b=BZjWCI2Mvnvced4yOOyd7ALKpxO6XVSs1PeznFFmPVB6ze1dlqT3/FgdRX65JKQ/eghYA/ 3ZCu871XY8jUN/OL2hmPYHfNqrpLuLFokHadf8K/pXJ13nn2I0h7sKLHq7L49v97hDjbfw ezmhWpGSBHVcJIkzCxP3TtZ1OwMOjsI= DKIM-Signature: v=1; a=ed25519-sha256; c=relaxed/relaxed; d=suse.cz; s=susede2_ed25519; t=1691754949; h=from:from:reply-to:date:date:message-id:message-id:to:to:cc: mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=VUrZgmFPDGTXQputdMxfXVGV3vYAi++YOW+ukJlAxIE=; b=e6vRRSQ+67Qj13laE0O5FLx5mGyr7RnGgtRDxPq9N62DeyXQ19IMN8K6x47fcWTvV+bPHR SoalOOryCxA5FvAQ== 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 025D1138E2 for ; Fri, 11 Aug 2023 11:55:48 +0000 (UTC) Received: from dovecot-director2.suse.de ([192.168.254.65]) by imap2.suse-dmz.suse.de with ESMTPSA id PHEEO8Qh1mQLWwAAMHmgww (envelope-from ) for ; Fri, 11 Aug 2023 11:55:48 +0000 From: Cyril Hrubis To: ltp@lists.linux.it Date: Fri, 11 Aug 2023 13:56:45 +0200 Message-ID: <20230811115647.32387-6-chrubis@suse.cz> X-Mailer: git-send-email 2.41.0 In-Reply-To: <20230811115647.32387-1-chrubis@suse.cz> References: <20230811115647.32387-1-chrubis@suse.cz> MIME-Version: 1.0 X-Virus-Scanned: clamav-milter 1.0.1 at in-5.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 shortcircuit=no autolearn=disabled version=4.0.0 X-Spam-Checker-Version: SpamAssassin 4.0.0 (2022-12-13) on in-5.smtp.seeweb.it Subject: [LTP] [PATCH 4/6] syscalls/chdir01: Make use use of guarded buffers 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" Signed-off-by: Cyril Hrubis --- testcases/kernel/syscalls/chdir/chdir01.c | 55 +++++++++++++++-------- 1 file changed, 36 insertions(+), 19 deletions(-) diff --git a/testcases/kernel/syscalls/chdir/chdir01.c b/testcases/kernel/syscalls/chdir/chdir01.c index e4080e3f4..d50a8f50c 100644 --- a/testcases/kernel/syscalls/chdir/chdir01.c +++ b/testcases/kernel/syscalls/chdir/chdir01.c @@ -31,18 +31,27 @@ static char *workdir; static int skip_symlinks, skip_blocked; static struct passwd *ltpuser; +static char *file_name; +static char *blocked_name; +static char *dir_name; +static char *cwd_name; +static char *parent_name; +static char *root_name; +static char *missing_name; +static char *link_name; + static struct test_case { - const char *name; + char **name; int root_ret, root_err, nobody_ret, nobody_err; } testcase_list[] = { - {FILE_NAME, -1, ENOTDIR, -1, ENOTDIR}, - {BLOCKED_NAME, 0, 0, -1, EACCES}, - {DIR_NAME, 0, 0, 0, 0}, - {".", 0, 0, 0, 0}, - {"..", 0, 0, 0, 0}, - {"/", 0, 0, 0, 0}, - {"missing", -1, ENOENT, -1, ENOENT}, - {LINK_NAME1, -1, ELOOP, -1, ELOOP}, + {&file_name, -1, ENOTDIR, -1, ENOTDIR}, + {&blocked_name, 0, 0, -1, EACCES}, + {&dir_name, 0, 0, 0, 0}, + {&cwd_name, 0, 0, 0, 0}, + {&parent_name, 0, 0, 0, 0}, + {&root_name, 0, 0, 0, 0}, + {&missing_name, -1, ENOENT, -1, ENOENT}, + {&link_name, -1, ELOOP, -1, ELOOP}, }; static void setup(void) @@ -53,8 +62,6 @@ static void setup(void) umask(0); - SAFE_MOUNT(tst_device->dev, MNTPOINT, tst_device->fs_type, 0, NULL); - cwd = SAFE_GETCWD(NULL, 0); workdir = SAFE_MALLOC(strlen(cwd) + strlen(MNTPOINT) + 2); sprintf(workdir, "%s/%s", cwd, MNTPOINT); @@ -109,7 +116,7 @@ static void run(unsigned int n) { struct test_case *tc = testcase_list + n; - tst_res(TINFO, "Testing '%s'", tc->name); + tst_res(TINFO, "Testing '%s'", *tc->name); if (tc->root_err == ELOOP && skip_symlinks) { tst_res(TCONF, "Skipping symlink loop test, not supported"); @@ -119,8 +126,8 @@ static void run(unsigned int n) /* Reset current directory to mountpoint */ SAFE_CHDIR(workdir); - TEST(chdir(tc->name)); - check_result("root", tc->name, tc->root_ret, tc->root_err); + TEST(chdir(*tc->name)); + check_result("root", *tc->name, tc->root_ret, tc->root_err); if (tc->nobody_err == EACCES && skip_blocked) { tst_res(TCONF, "Skipping unprivileged permission test, " @@ -130,25 +137,35 @@ static void run(unsigned int n) SAFE_CHDIR(workdir); SAFE_SETEUID(ltpuser->pw_uid); - TEST(chdir(tc->name)); + TEST(chdir(*tc->name)); SAFE_SETEUID(0); - check_result(TESTUSER, tc->name, tc->nobody_ret, tc->nobody_err); + check_result(TESTUSER, *tc->name, tc->nobody_ret, tc->nobody_err); } static void cleanup(void) { SAFE_CHDIR(".."); - tst_umount(workdir); free(workdir); } static struct tst_test test = { .needs_root = 1, - .format_device = 1, + .mount_device = 1, .mntpoint = MNTPOINT, .all_filesystems = 1, .test = run, .tcnt = ARRAY_SIZE(testcase_list), .setup = setup, - .cleanup = cleanup + .cleanup = cleanup, + .bufs = (struct tst_buffers []) { + {&file_name, .str = FILE_NAME}, + {&blocked_name, .str = BLOCKED_NAME}, + {&dir_name, .str = DIR_NAME}, + {&cwd_name, .str = "."}, + {&parent_name, .str = ".."}, + {&root_name, .str = "/"}, + {&missing_name, .str = "does_not_exist"}, + {&link_name, .str = LINK_NAME1}, + {} + } }; From patchwork Fri Aug 11 11:56:46 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Cyril Hrubis X-Patchwork-Id: 1820253 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=oL7ZbsxX; dkim=fail reason="signature verification failed" header.d=suse.cz header.i=@suse.cz header.a=ed25519-sha256 header.s=susede2_ed25519 header.b=vw5LOE+U; 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)) (No client certificate requested) by legolas.ozlabs.org (Postfix) with ESMTPS id 4RMj2k2N4yz1yf7 for ; Fri, 11 Aug 2023 21:57:18 +1000 (AEST) Received: from picard.linux.it (localhost [IPv6:::1]) by picard.linux.it (Postfix) with ESMTP id 0CD943CDA4B for ; Fri, 11 Aug 2023 13:57:15 +0200 (CEST) X-Original-To: ltp@lists.linux.it Delivered-To: ltp@picard.linux.it Received: from in-5.smtp.seeweb.it (in-5.smtp.seeweb.it [IPv6:2001:4b78:1:20::5]) (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 EC54D3CD065 for ; Fri, 11 Aug 2023 13:55:50 +0200 (CEST) Received: from smtp-out1.suse.de (smtp-out1.suse.de [195.135.220.28]) (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-5.smtp.seeweb.it (Postfix) with ESMTPS id E78126008DD for ; Fri, 11 Aug 2023 13:55:49 +0200 (CEST) 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-out1.suse.de (Postfix) with ESMTPS id 9268D2187C for ; Fri, 11 Aug 2023 11:55:49 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=suse.cz; s=susede2_rsa; t=1691754949; h=from:from:reply-to:date:date:message-id:message-id:to:to:cc: mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=wyb3sqYfC6xXJfBB6KvyeVubd/PSZvqJjM4R7KcdSPA=; b=oL7ZbsxXnwQR3ya4zCObKSoBr5KNxFKFW7kJdFuUbT6tOHuDqq9cIE1WqIqbELeUGzib0j FUa1RASF4wn0DWbW1O2SyAydGHbMmD1OBDjmWTEGs3yTt1K7wBJHKhjsiBjW70qkWKriKd TF3i43ViQQ8vf4NPV1xq8B05dEiuKag= DKIM-Signature: v=1; a=ed25519-sha256; c=relaxed/relaxed; d=suse.cz; s=susede2_ed25519; t=1691754949; h=from:from:reply-to:date:date:message-id:message-id:to:to:cc: mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=wyb3sqYfC6xXJfBB6KvyeVubd/PSZvqJjM4R7KcdSPA=; b=vw5LOE+U2ALUIFLgFQJt5dlrPwNHIyf/N7xpvzg/iFAfNjffq6bw1x/B+LiBO3NVpQE7IF F2PEPlWno44JNoAQ== 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 7BC9E138E2 for ; Fri, 11 Aug 2023 11:55:49 +0000 (UTC) Received: from dovecot-director2.suse.de ([192.168.254.65]) by imap2.suse-dmz.suse.de with ESMTPSA id ASPzHMUh1mQNWwAAMHmgww (envelope-from ) for ; Fri, 11 Aug 2023 11:55:49 +0000 From: Cyril Hrubis To: ltp@lists.linux.it Date: Fri, 11 Aug 2023 13:56:46 +0200 Message-ID: <20230811115647.32387-7-chrubis@suse.cz> X-Mailer: git-send-email 2.41.0 In-Reply-To: <20230811115647.32387-1-chrubis@suse.cz> References: <20230811115647.32387-1-chrubis@suse.cz> MIME-Version: 1.0 X-Virus-Scanned: clamav-milter 1.0.1 at in-5.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_PASS shortcircuit=no autolearn=disabled version=4.0.0 X-Spam-Checker-Version: SpamAssassin 4.0.0 (2022-12-13) on in-5.smtp.seeweb.it Subject: [LTP] [PATCH 5/6] syscalls/chmod01: Make use of guarded buffers 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" Signed-off-by: Cyril Hrubis --- testcases/kernel/syscalls/chmod/chmod01.c | 28 +++++++++++++++-------- 1 file changed, 18 insertions(+), 10 deletions(-) diff --git a/testcases/kernel/syscalls/chmod/chmod01.c b/testcases/kernel/syscalls/chmod/chmod01.c index 9f5ec4c67..b3b828ac3 100644 --- a/testcases/kernel/syscalls/chmod/chmod01.c +++ b/testcases/kernel/syscalls/chmod/chmod01.c @@ -19,13 +19,16 @@ static int modes[] = {0, 07, 070, 0700, 0777, 02777, 04777, 06777}; +static char *test_dir; +static char *test_file; + static struct variant { - char *name; + char **name; unsigned int mode_mask; char *desc; } variants[] = { - {TESTFILE, S_IFREG, "verify permissions of file"}, - {TESTDIR, S_IFDIR, "verify permissions of directory"}, + {&test_file, S_IFREG, "verify permissions of file"}, + {&test_dir, S_IFDIR, "verify permissions of directory"}, }; static void verify_chmod(unsigned int n) @@ -34,21 +37,21 @@ static void verify_chmod(unsigned int n) int mode = modes[n]; struct variant *tc = &variants[tst_variant]; - TST_EXP_PASS(chmod(tc->name, mode), "chmod(%s, %04o)", - tc->name, mode); + TST_EXP_PASS(chmod(*tc->name, mode), "chmod(%s, %04o)", + *tc->name, mode); if (!TST_PASS) return; - SAFE_STAT(tc->name, &stat_buf); + SAFE_STAT(*tc->name, &stat_buf); stat_buf.st_mode &= ~tc->mode_mask; if (stat_buf.st_mode == (unsigned int)mode) { tst_res(TPASS, "stat(%s) mode=%04o", - tc->name, stat_buf.st_mode); + *tc->name, stat_buf.st_mode); } else { tst_res(TFAIL, "stat(%s) mode=%04o", - tc->name, stat_buf.st_mode); + *tc->name, stat_buf.st_mode); } } @@ -57,9 +60,9 @@ static void setup(void) tst_res(TINFO, "Testing variant: %s", variants[tst_variant].desc); if (tst_variant) - SAFE_MKDIR(variants[tst_variant].name, MODE); + SAFE_MKDIR(*variants[tst_variant].name, MODE); else - SAFE_TOUCH(variants[tst_variant].name, MODE, NULL); + SAFE_TOUCH(*variants[tst_variant].name, MODE, NULL); } static struct tst_test test = { @@ -68,4 +71,9 @@ static struct tst_test test = { .tcnt = ARRAY_SIZE(modes), .test = verify_chmod, .needs_tmpdir = 1, + .bufs = (struct tst_buffers []) { + {&test_file, .str = TESTFILE}, + {&test_dir, .str = TESTDIR}, + {} + } }; From patchwork Fri Aug 11 11:56:47 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Cyril Hrubis X-Patchwork-Id: 1820252 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=213.254.12.146; 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=IyWhZHCx; dkim=fail reason="signature verification failed" header.d=suse.cz header.i=@suse.cz header.a=ed25519-sha256 header.s=susede2_ed25519 header.b=Uax4m9ML; dkim-atps=neutral Received: from picard.linux.it (picard.linux.it [213.254.12.146]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (P-384)) (No client certificate requested) by legolas.ozlabs.org (Postfix) with ESMTPS id 4RMj2V5fnjz1yf7 for ; Fri, 11 Aug 2023 21:57:06 +1000 (AEST) Received: from picard.linux.it (localhost [IPv6:::1]) by picard.linux.it (Postfix) with ESMTP id BD72C3CDA4D for ; Fri, 11 Aug 2023 13:57:04 +0200 (CEST) X-Original-To: ltp@lists.linux.it Delivered-To: ltp@picard.linux.it Received: from in-3.smtp.seeweb.it (in-3.smtp.seeweb.it [IPv6:2001:4b78:1:20::3]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (P-384)) (No client certificate requested) by picard.linux.it (Postfix) with ESMTPS id 58D303CD0C4 for ; Fri, 11 Aug 2023 13:55:52 +0200 (CEST) Received: from smtp-out1.suse.de (smtp-out1.suse.de [IPv6:2001:67c:2178:6::1c]) (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-3.smtp.seeweb.it (Postfix) with ESMTPS id 4A2D01A00691 for ; Fri, 11 Aug 2023 13:55:51 +0200 (CEST) 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-out1.suse.de (Postfix) with ESMTPS id B9ADF21857 for ; Fri, 11 Aug 2023 11:55:50 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=suse.cz; s=susede2_rsa; t=1691754950; h=from:from:reply-to:date:date:message-id:message-id:to:to:cc: mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=wC3ZUdZh0vVGXLdWguBL5fCPThnlVJF06DZ1YqPjWX4=; b=IyWhZHCx0yO22pTQCyKkGAMNSUebdASN2n+Q8yYpSCsACxH2RomUwlGo3zDRVUuLJNCDfr c10IRjuJxITZaJeTuR92Mgqo9mDukfUGqfwDjeszi1R2jxPdaVpzXb1s43p6HRko2obZx9 kEv6EjHTBc0QFhNkGjdHbQgQ0ZtOj48= DKIM-Signature: v=1; a=ed25519-sha256; c=relaxed/relaxed; d=suse.cz; s=susede2_ed25519; t=1691754950; h=from:from:reply-to:date:date:message-id:message-id:to:to:cc: mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=wC3ZUdZh0vVGXLdWguBL5fCPThnlVJF06DZ1YqPjWX4=; b=Uax4m9MLgpBobzLR3k4vfV8vMAcXDMHPDTKwUk9rh5IilkfftEufNXzecAGfFgk+IxCuys Kmc+0EFGhcut3AAw== 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 55024138E2 for ; Fri, 11 Aug 2023 11:55:50 +0000 (UTC) Received: from dovecot-director2.suse.de ([192.168.254.65]) by imap2.suse-dmz.suse.de with ESMTPSA id NoNjCcYh1mQRWwAAMHmgww (envelope-from ) for ; Fri, 11 Aug 2023 11:55:50 +0000 From: Cyril Hrubis To: ltp@lists.linux.it Date: Fri, 11 Aug 2023 13:56:47 +0200 Message-ID: <20230811115647.32387-8-chrubis@suse.cz> X-Mailer: git-send-email 2.41.0 In-Reply-To: <20230811115647.32387-1-chrubis@suse.cz> References: <20230811115647.32387-1-chrubis@suse.cz> MIME-Version: 1.0 X-Virus-Scanned: clamav-milter 1.0.1 at in-3.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 shortcircuit=no autolearn=disabled version=4.0.0 X-Spam-Checker-Version: SpamAssassin 4.0.0 (2022-12-13) on in-3.smtp.seeweb.it Subject: [LTP] [PATCH 6/6] syscalls/chroot03: Make use of guarded buffers 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" Signed-off-by: Cyril Hrubis --- testcases/kernel/syscalls/chroot/chroot03.c | 46 ++++++++++++--------- 1 file changed, 27 insertions(+), 19 deletions(-) diff --git a/testcases/kernel/syscalls/chroot/chroot03.c b/testcases/kernel/syscalls/chroot/chroot03.c index ba8c1e9ac..87faec316 100644 --- a/testcases/kernel/syscalls/chroot/chroot03.c +++ b/testcases/kernel/syscalls/chroot/chroot03.c @@ -25,41 +25,42 @@ #include #include "tst_test.h" -static char fname[255]; -static char nonexistent_dir[100] = "testdir"; -static char bad_dir[] = "abcdefghijklmnopqrstmnopqrstuvwxyzabcdefghijklmnopqrstmnopqrstuvwxyzabcdefghijklmnopqrstmnopqrstuvwxyzabcdefghijklmnopqrstmnopqrstuvwxyzabcdefghijklmnopqrstmnopqrstuvwxyzabcdefghijklmnopqrstmnopqrstuvwxyzabcdefghijklmnopqrstmnopqrstuvwxyzabcdefghijklmnopqrstmnopqrstuvwxyz"; -static char symbolic_dir[] = "sym_dir1"; +#define FILE_NAME "test_file" +#define LOOP_DIR "sym_dir1" +#define NONEXISTENT_DIR "does_not_exist" + +static char *longname_dir; +static char *file_name; +static char *nonexistent_dir; +static char *bad_ptr; +static char *loop_dir; static struct tcase { - char *dir; + char **dir; int error; char *desc; } tcases[] = { - {bad_dir, ENAMETOOLONG, "chroot(longer than VFS_MAXNAMELEN)"}, - {fname, ENOTDIR, "chroot(not a directory)"}, - {nonexistent_dir, ENOENT, "chroot(does not exists)"}, - {(char *)-1, EFAULT, "chroot(an invalid address)"}, - {symbolic_dir, ELOOP, "chroot(symlink loop)"} + {&longname_dir, ENAMETOOLONG, "chroot(longer than VFS_MAXNAMELEN)"}, + {&file_name, ENOTDIR, "chroot(not a directory)"}, + {&nonexistent_dir, ENOENT, "chroot(does not exists)"}, + {&bad_ptr, EFAULT, "chroot(an invalid address)"}, + {&loop_dir, ELOOP, "chroot(symlink loop)"} }; static void verify_chroot(unsigned int n) { struct tcase *tc = &tcases[n]; - TST_EXP_FAIL(chroot(tc->dir), tc->error, "%s", tc->desc); + TST_EXP_FAIL(chroot(*tc->dir), tc->error, "%s", tc->desc); } static void setup(void) { - unsigned int i; - - (void)sprintf(fname, "tfile_%d", getpid()); - SAFE_TOUCH(fname, 0666, NULL); + SAFE_TOUCH(FILE_NAME, 0666, NULL); + bad_ptr = tst_get_bad_addr(NULL); - for (i = 0; i < ARRAY_SIZE(tcases); i++) { - if (tcases[i].error == EFAULT) - tcases[3].dir = tst_get_bad_addr(NULL); - } + memset(longname_dir, 'a', PATH_MAX + 1); + longname_dir[PATH_MAX+1] = 0; SAFE_SYMLINK("sym_dir1/", "sym_dir2"); SAFE_SYMLINK("sym_dir2/", "sym_dir1"); @@ -70,4 +71,11 @@ static struct tst_test test = { .tcnt = ARRAY_SIZE(tcases), .test = verify_chroot, .needs_tmpdir = 1, + .bufs = (struct tst_buffers []) { + {&file_name, .str = FILE_NAME}, + {&nonexistent_dir, .str = NONEXISTENT_DIR}, + {&loop_dir, .str = LOOP_DIR}, + {&longname_dir, .size = PATH_MAX+2}, + {} + } };