From patchwork Fri Apr 25 18:06:01 2025 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: =?utf-8?q?Ricardo_B=2E_Marli=C3=A8re?= X-Patchwork-Id: 2077444 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@legolas.ozlabs.org Authentication-Results: legolas.ozlabs.org; dkim=pass (1024-bit key; unprotected) header.d=lists.linux.it header.i=@lists.linux.it header.a=rsa-sha256 header.s=picard header.b=A4Gnfqgi; dkim=fail reason="signature verification failed" (2048-bit key; unprotected) header.d=suse.com header.i=@suse.com header.a=rsa-sha256 header.s=google header.b=eP/CQPgQ; dkim-atps=neutral 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=patchwork.ozlabs.org) 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 (secp384r1) server-digest SHA384) (No client certificate requested) by legolas.ozlabs.org (Postfix) with ESMTPS id 4ZkglD36qcz1yMm for ; Sat, 26 Apr 2025 04:06:32 +1000 (AEST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=lists.linux.it; i=@lists.linux.it; q=dns/txt; s=picard; t=1745604407; h=date : mime-version : message-id : references : in-reply-to : to : subject : list-id : list-unsubscribe : list-archive : list-post : list-help : list-subscribe : from : reply-to : cc : content-type : content-transfer-encoding : sender : from; bh=D4jorgsASwUnem84iCFdlYyE0ww6nfTaJw3Gliia7cM=; b=A4GnfqgiRdNw45XHp7zbqnS4jy7rFyk/a4mxj2iGrlF/0qJdMuoehV/WIelksMfAYDFmm F476jqAXEzE4KOkXvQaU7FsMKECnBk0KNus9w6KhPKYYO22v0eDMc9LT9PALY9x6J+dAeZn vWB4y3rV0m9JSyZVtvcFxcrWD55V9Pw= Received: from picard.linux.it (localhost [IPv6:::1]) by picard.linux.it (Postfix) with ESMTP id A5AA93CBA3F for ; Fri, 25 Apr 2025 20:06:47 +0200 (CEST) X-Original-To: ltp@lists.linux.it Delivered-To: ltp@picard.linux.it Received: from in-7.smtp.seeweb.it (in-7.smtp.seeweb.it [217.194.8.7]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (secp384r1) server-digest SHA384) (No client certificate requested) by picard.linux.it (Postfix) with ESMTPS id AE83F3CBA3F for ; Fri, 25 Apr 2025 20:06:15 +0200 (CEST) Received: from mail-wm1-x32b.google.com (mail-wm1-x32b.google.com [IPv6:2a00:1450:4864:20::32b]) (using TLSv1.3 with cipher TLS_AES_128_GCM_SHA256 (128/128 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits) server-digest SHA256) (No client certificate requested) by in-7.smtp.seeweb.it (Postfix) with ESMTPS id 208F7200A04 for ; Fri, 25 Apr 2025 20:06:15 +0200 (CEST) Received: by mail-wm1-x32b.google.com with SMTP id 5b1f17b1804b1-43690d4605dso19064215e9.0 for ; Fri, 25 Apr 2025 11:06:15 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=suse.com; s=google; t=1745604374; x=1746209174; darn=lists.linux.it; h=cc:to:in-reply-to:references:message-id:content-transfer-encoding :mime-version:subject:date:from:from:to:cc:subject:date:message-id :reply-to; bh=udh7WQisxb76qYjtANbysaZCZCcCybHWMLZqzW5NUac=; b=eP/CQPgQhgfDtYQApYX5OYwMG6Pl05TfGqWlrDeyJn8WykoC6OUlSzcEZmfUKsoN6H oXSJYUaBLVVhKyoz/q/5T10aApeQVmA09cDAeYvfNOo+44s5HYqXiRcNUvWTGKv6+JdG K6u/dsqK7qXd5XiXfpqVuSeRm+ftN2N+GPaTOeE5/HBoZ9Cib/ndzvT37HxgR+m2lq4P 0aHrhTl4qIbSSnBYony7GMuSrIJoiuFKhQ0zqcnKaumECnhMYqqHuDToeCqrxlFKh1Fn 6Q4VrbzNS2m+ValfEJwmEuAEBkxMhBtUuitwI/w8sjO9gub/Y/qrpB7fMqS12zmuGuVK DJ3A== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1745604374; x=1746209174; h=cc:to:in-reply-to:references:message-id:content-transfer-encoding :mime-version:subject:date:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=udh7WQisxb76qYjtANbysaZCZCcCybHWMLZqzW5NUac=; b=r6ti31Pakdzs72jAZ5D+vry+Vmlio3PldRwtsr+cKbvzoF9LNNYF3Bmkn9f6fri/QA AOz7dLtg3PJtURoxSkyxTVkgmsDYn3/QKmrDR3M5alZUobbQStGQG3i0P8DL37jTeZiw OMmo5cpq+sIyz6Mrt34e8jE4kNVrzZQrmXS/jE/Y/tMCiBCzSv3zqvoiyVFBvI4IefQQ ktH9xfoYiqqMa5PeZCZDVGmP/iXVHlbnsqUpk9nh0pwAr/iTlIIRlyFJpLfY5wsMLTc3 W2nC4ttMHRQa//eG/mj1gCa9BqXij44WD/GRSPKTHiwVtld2ZM4izH5L7wR8942rKWaA aULA== X-Gm-Message-State: AOJu0Yxliy4lu08g8Y0qI6uZDADKYrv6YQwF5+4hAQCtZHUq3LIvrlkT ehIxZRR30rIj5U2JbroPsGzvHG0YisUGSc7CwlXuNNX7Qnuj4ISABtmt34Rb4NqTf39B+zEd7KA q X-Gm-Gg: ASbGncsm/J3QdZdYJRMIenTJdVZ96rUMUDkC5sLixZ2Ndwt6qKwjNTI7zCLnfq4Sg7j sDtOrW1yDF/EZFCs0NEe9FScyR6UKwKpxCVslGdYbkM5C200vmji0zU059n0gL5mSsw+R7g1L4K CEuBBuH0806wi/gZjDYcbw6ewLRZZXQDiRpfaCQsh0ibmC3JCF6pnONkEmVtvIR3A9WzBQTDvE0 qGCzXkGid0c3EgLAXV4aAfVtC73TzVbx4CSWVT2tWrXF4gSzQzDMEldWZ0LhXyESlCStLNmVgis 5KVkukJEEFnNp9ZOtZJblssyMBEvrw== X-Google-Smtp-Source: AGHT+IHSF6L+D4IJUv6P1hIyqeDf+mj5ZmdA3y7o2AlCa1HgzWkug50B25ldjREu08ZQxKt42F6/GQ== X-Received: by 2002:a5d:5f4d:0:b0:391:1222:b444 with SMTP id ffacd0b85a97d-3a07aa666fdmr246723f8f.20.1745604373742; Fri, 25 Apr 2025 11:06:13 -0700 (PDT) Received: from localhost ([179.228.213.210]) by smtp.gmail.com with UTF8SMTPSA id d9443c01a7336-22db4d77ab1sm35620485ad.23.2025.04.25.11.06.12 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 25 Apr 2025 11:06:13 -0700 (PDT) Date: Fri, 25 Apr 2025 15:06:01 -0300 MIME-Version: 1.0 Message-Id: <20250425-conversions-mknod-v4-1-222e0d2e7ef1@suse.com> References: <20250425-conversions-mknod-v4-0-222e0d2e7ef1@suse.com> In-Reply-To: <20250425-conversions-mknod-v4-0-222e0d2e7ef1@suse.com> To: Linux Test Project X-Mailer: b4 0.14.2 X-Developer-Signature: v=1; a=openpgp-sha256; l=1317; i=rbm@suse.com; h=from:subject:message-id; bh=twnhIB7eH/7VIf0ZM2yDntmIXI8tRqpOsH1ZMc3AuQc=; b=owEBbQKS/ZANAwAIAckLinxjhlimAcsmYgBoC88NtE6lgtsCVNbDmktdG4s9tqvVN/DsJPREZ bYTFWMI2yqJAjMEAAEIAB0WIQQDCo6eQk7jwGVXh+HJC4p8Y4ZYpgUCaAvPDQAKCRDJC4p8Y4ZY pubND/9IgPvVz+q5k0w4Z7SZNaTh/DKngban2MxJMN25sROmkK/oayappEdH2oPBr0soJdWxrlY 0w5hUqTkGw39jkdz8GEeZTDyR1LcCfcOgbFxzTyZkKu1aP8b3NEwNznGWtdpGavpW0XpqzwfV6J 9J+fkBMQoEJkwBovaRc2WXLUtEoWL3DqlP0/TwLQuTQlTN9NlBQ1jtnORYAIOYuF0fVIx5HEUi3 al8Q/njeAQ5fzFnjVsse936tLhN3sawQfQqU0afXQfEk8XJBShN4/3tcUNwIAqETl2+CD7MpqFV 52bmtaVPW0AZOHOPUsG9rr+iYtHzJ5ml9WhSCm9zGim0ZcTxpfAJJK6zPuykO5oqY4S9ON6RkWj gB+mrUO4LSp6cAxUwSt0nTWw5sL3mUFXnlsVbgOio/3YSwiAJMDvkSWKB/isF1tw0IQ2MSTXNeV B4m36U0z/X/CFoZnCTt4C6JPPH/LDANhAw9jcHwBSFSuysQoIL03ZRBH4re4yNBsV1Ff14JQddi i2VJiCNiqYEJtF+eaioWDeG5HDCglHFMXcUFRNX8ld59pS2qdYfIUamM0jLENl3VrdMKri7Ler7 /pMxCojUxyw0AITJ0qLSTs8BP+qvc1Sx6mDZHtZX2BNlJ64BMmVsZ6EibtqcQGgyG553dH54/aD FhSwIJynQp0MTog== X-Developer-Key: i=rbm@suse.com; a=openpgp; fpr=030A8E9E424EE3C0655787E1C90B8A7C638658A6 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.1 X-Spam-Checker-Version: SpamAssassin 4.0.1 (2024-03-25) on in-7.smtp.seeweb.it X-Virus-Scanned: clamav-milter 1.0.7 at in-7.smtp.seeweb.it X-Virus-Status: Clean Subject: [LTP] [PATCH v4 1/8] syscalls/mknod01: Fix checkpatch.pl warnings 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: , X-Patchwork-Original-From: =?utf-8?q?Ricardo_B=2E_Marli=C3=A8re_via_ltp?= From: =?utf-8?q?Ricardo_B=2E_Marli=C3=A8re?= Reply-To: =?utf-8?q?Ricardo_B=2E_Marli=C3=A8re?= Cc: =?utf-8?q?Ricardo_B=2E_Marli=C3=A8re?= Errors-To: ltp-bounces+incoming=patchwork.ozlabs.org@lists.linux.it Sender: "ltp" From: Ricardo B. Marlière Fix the following warnings: Alignment should match open parenthesis Please don't use multiple blank lines Also, fix 32b compat mode warning: mknod01.c:37:22: warning: format ‘%ld’ expects argument of type ‘long int’, but argument 6 has type ‘dev_t’ Signed-off-by: Ricardo B. Marlière Reviewed-by: Andrea Cervesato Reviewed-by: Petr Vorel --- testcases/kernel/syscalls/mknod/mknod01.c | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/testcases/kernel/syscalls/mknod/mknod01.c b/testcases/kernel/syscalls/mknod/mknod01.c index fe0a1cfa6a473f9c2b2a55493f830f13b86560a8..0f0c17a5fd157e58359a586be2e268e42fa0eb0b 100644 --- a/testcases/kernel/syscalls/mknod/mknod01.c +++ b/testcases/kernel/syscalls/mknod/mknod01.c @@ -10,6 +10,8 @@ * various modes. */ +#include +#include #include #include "tst_test.h" @@ -26,7 +28,6 @@ static int tcases[] = { S_IFREG | 06700, }; - static void run(unsigned int i) { dev_t dev = 0; @@ -35,8 +36,8 @@ static void run(unsigned int i) dev = makedev(1, 3); TST_EXP_PASS(mknod(PATH, tcases[i], dev), - "mknod(PATH, %o, %ld)", - tcases[i], dev); + "mknod(PATH, %o, %" PRIuMAX ")", + tcases[i], (uintmax_t)dev); SAFE_UNLINK(PATH); } From patchwork Fri Apr 25 18:06:02 2025 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: =?utf-8?q?Ricardo_B=2E_Marli=C3=A8re?= X-Patchwork-Id: 2077445 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@legolas.ozlabs.org Authentication-Results: legolas.ozlabs.org; dkim=pass (1024-bit key; unprotected) header.d=lists.linux.it header.i=@lists.linux.it header.a=rsa-sha256 header.s=picard header.b=ifWDnvi5; dkim=fail reason="signature verification failed" (2048-bit key; unprotected) header.d=suse.com header.i=@suse.com header.a=rsa-sha256 header.s=google header.b=AEjLr0Vb; dkim-atps=neutral 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=patchwork.ozlabs.org) 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 (secp384r1) server-digest SHA384) (No client certificate requested) by legolas.ozlabs.org (Postfix) with ESMTPS id 4Zkglh3kXJz1yMm for ; Sat, 26 Apr 2025 04:06:56 +1000 (AEST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=lists.linux.it; i=@lists.linux.it; q=dns/txt; s=picard; t=1745604431; h=date : mime-version : message-id : references : in-reply-to : to : subject : list-id : list-unsubscribe : list-archive : list-post : list-help : list-subscribe : from : reply-to : cc : content-type : content-transfer-encoding : sender : from; bh=QABWMDrsW1y9FPHjVDYHMUqwpquRTZwI2cUlyDf3UuY=; b=ifWDnvi5F4DPmJvwA9TcuIk2KPn7HH7lqg0k3txBDHCBREXg+obxjTnjJSlsMf5w7eCBw wH1n8iGKqVRQr03Nmt5R3vNT6yl3NQZw1QxupnUxnCrHm71fKFsXNGyHItx8KOzGurEh+VT 6/AzSkzP1DbFFeLhMceelA4eNlXBY/Y= Received: from picard.linux.it (localhost [IPv6:::1]) by picard.linux.it (Postfix) with ESMTP id DE59E3CBA4F for ; Fri, 25 Apr 2025 20:07:11 +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 [217.194.8.6]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (secp384r1)) (No client certificate requested) by picard.linux.it (Postfix) with ESMTPS id 80DEE3CBA39 for ; Fri, 25 Apr 2025 20:06:18 +0200 (CEST) Received: from mail-wr1-x429.google.com (mail-wr1-x429.google.com [IPv6:2a00:1450:4864:20::429]) (using TLSv1.3 with cipher TLS_AES_128_GCM_SHA256 (128/128 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 D9A251400527 for ; Fri, 25 Apr 2025 20:06:17 +0200 (CEST) Received: by mail-wr1-x429.google.com with SMTP id ffacd0b85a97d-39ac56756f6so2500197f8f.2 for ; Fri, 25 Apr 2025 11:06:17 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=suse.com; s=google; t=1745604376; x=1746209176; darn=lists.linux.it; h=cc:to:in-reply-to:references:message-id:content-transfer-encoding :mime-version:subject:date:from:from:to:cc:subject:date:message-id :reply-to; bh=uqOnhmICvJNwWlaGvCLaLbzPDHfHBSeup2FG4GGDIwI=; b=AEjLr0Vb6sXNW5XeQmFkJLqLD+9bKgZUdDjgNwmloRBBP9nK9NvWNmqI6XDcetRB0O NVrmu+86wOBjHGXkfRIIgz9Z0XqT6pXEDKERTVYOs1vWr4iQ0p+H6VB1RUXjUjxpZO52 G2wYmoxbrntYPc8SQFHDpE4vvV2oLScyHSy4SkGa6yo2vUR+/De2a6gy/uuG8orUMGn8 Yg2WFbbm31o9cpUl+Fr2BosKIm2u1KgZR/sumq6QOZ1I0xGD/qE1dKKcug/o+C6t/64T 6DwddyL0Pnq/prJrEwhym1KWOz6oES3igxKYqRR6hTpz4xQv5BaX1TXcEUO7Kk/BjhXQ +iAw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1745604376; x=1746209176; h=cc:to:in-reply-to:references:message-id:content-transfer-encoding :mime-version:subject:date:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=uqOnhmICvJNwWlaGvCLaLbzPDHfHBSeup2FG4GGDIwI=; b=T4mhBG51m3qrbjd1N+RhEcjjwmrzzEXEnU6lNrJO0OOrdi1ij1W2E73AM4mav081yJ An6/16V0GMO4TM7SByymI0FwzMicVn5wkqG0Ys5YvAGPlTb7xKG31r+SOdPyJ6fwqYQT JuZ5dhLZf5DwWQhY/Jg6ZSbzvcOj7QyXOzx8SvpgN5LKuAGr2Q8JnawAI2Qs9M6PcOLA NDOL/nK4MCsuXNHJRr18izGUsjrV1t1qTpiCsBG1vuSj4mX3yFa/0w9xrCNC+Y4zewP0 U8eCuYZ+hggIJ/E4Fbc0ZxLWleJdYfCkfl9zQs2Er8+17EkvkV3nVX7Q3cA4KY4cRNN7 CGxQ== X-Gm-Message-State: AOJu0YyHIisiibtMagK26EYPXaWZVpu/eC4Ql6kuFrffJ/izpWWbIrv7 fzbGuno212R5ZrAjx8SATy2qQVfm4rtmEfW/k6wcuuWCHOErb06Dx7stAgI3aOO+xC2dkjzT0GC c X-Gm-Gg: ASbGnctJshU5hnLJVC/dL0fuseYQWLTqzrqDuGJeyZ+tdQEyx5i922Whu3Arl0wc2Er IYR863K3gjKG22m6uMnNnCcO4uc/xvkftkSKpSUlm3lxW/RkZsjCupC7xnqMkg6zTDUVnDZEj2b 8osQygcKQpcbHkvY36gHnqpbjHXij1W95mklW5+h81HGhattLFQJFGzE7KWlNmc2be/4CaxKiGQ 570zS4G4swBEY2YuBr/32uZFM/qE3xjSj5xipqZUllSTUVwmYkbsDQyyew17HvkqSBiuJrI0jfd idfgWJBl+sF6BZQO23DOZkA9MGkVUA== X-Google-Smtp-Source: AGHT+IFDBxdcMiHuO7gvYg+0co2LRukbnBPdpo/HxIU1hVZ4Gkvp+TJE2L+ONtbw72EMRN4lv+53LQ== X-Received: by 2002:a5d:5f96:0:b0:39c:30cd:352c with SMTP id ffacd0b85a97d-3a07aa5fdf7mr222075f8f.8.1745604376533; Fri, 25 Apr 2025 11:06:16 -0700 (PDT) Received: from localhost ([179.228.213.210]) by smtp.gmail.com with UTF8SMTPSA id d9443c01a7336-22db5100aa7sm35448915ad.161.2025.04.25.11.06.15 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 25 Apr 2025 11:06:16 -0700 (PDT) Date: Fri, 25 Apr 2025 15:06:02 -0300 MIME-Version: 1.0 Message-Id: <20250425-conversions-mknod-v4-2-222e0d2e7ef1@suse.com> References: <20250425-conversions-mknod-v4-0-222e0d2e7ef1@suse.com> In-Reply-To: <20250425-conversions-mknod-v4-0-222e0d2e7ef1@suse.com> To: Linux Test Project X-Mailer: b4 0.14.2 X-Developer-Signature: v=1; a=openpgp-sha256; l=1071; i=rbm@suse.com; h=from:subject:message-id; bh=X5h5mk+IgbMJdWQ6bkAL3Wf14QQb+iicBskD93XmEJM=; b=owEBbQKS/ZANAwAIAckLinxjhlimAcsmYgBoC88NOV6GwffyC1aSdTuYiuRSPhpGliS6sQzW1 Xi7GbVM1umJAjMEAAEIAB0WIQQDCo6eQk7jwGVXh+HJC4p8Y4ZYpgUCaAvPDQAKCRDJC4p8Y4ZY pi1HEACZjmBa4EQ9D4CL1jtOzxbO70rQ7fMsoWfM0r+/Icn8orhmwVMuGgJTZLgeb4EZNbq424g JAY6QbqzyaH3Kua21o25hxaGddV2JxXgAVFE2zJZxnK16g6i2xFIPIqejSmcLaaI+Ht9IKlOBu3 UFHU+cte7QB6uTdaBEl+vcJpvsUPGEFGFHub8wpvcNoV5tQhzxJwa5iqZTiYKJMM09lX07AvQ7c 0CmQTNQ985VmEhOGZyF1C1pK8y6eDgI9ZQXWudsgHvOsB0rlmzAoU9bru/nqRZzus1tGs4ntbsC BGrUCP/jgwDznpyvtCjmdCYm31WrSfIOsGYX7rLceyHNrEat0g5hbNTLVYjZI1ITx5AmSrYLoyq YjRCEa7eyzS0qCmhXCaH+zAXencOL5JQ4pbPObvLTIkTDuWhsJwEtGakFd003+/ThhDh0Io48y7 QaeRI769mJg5+AFRwVHQ6rucFm4lVYGeNho3FFd1XXgA7bso/JP3X1PBepcl9IL8ICxZknqLeuu Co/kE+q9oYJjw8VY6zZifudFyI/gkjinBLH3GPnn4z4/9cvRGYgTgzAIQxPi3R0XjmfgkMOHXGl 71A9uql3HGEGLBgVUya5YGSmyycWmK+dNPOqKF5wQ0PJGVfY9sV7sE5F7OdlePzzkEC7keQFhTC DQPDzab8OrgwAsA== X-Developer-Key: i=rbm@suse.com; a=openpgp; fpr=030A8E9E424EE3C0655787E1C90B8A7C638658A6 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.1 X-Spam-Checker-Version: SpamAssassin 4.0.1 (2024-03-25) on in-6.smtp.seeweb.it X-Virus-Scanned: clamav-milter 1.0.7 at in-6.smtp.seeweb.it X-Virus-Status: Clean Subject: [LTP] [PATCH v4 2/8] syscalls/mknod02: Use relative path to avoid use of SAFE_CHDIR 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: , X-Patchwork-Original-From: =?utf-8?q?Ricardo_B=2E_Marli=C3=A8re_via_ltp?= From: =?utf-8?q?Ricardo_B=2E_Marli=C3=A8re?= Reply-To: =?utf-8?q?Ricardo_B=2E_Marli=C3=A8re?= Cc: =?utf-8?q?Ricardo_B=2E_Marli=C3=A8re?= Errors-To: ltp-bounces+incoming=patchwork.ozlabs.org@lists.linux.it Sender: "ltp" From: Ricardo B. Marlière Reviewed-by: Petr Vorel Signed-off-by: Ricardo B. Marlière Reviewed-by: Andrea Cervesato --- testcases/kernel/syscalls/mknod/mknod02.c | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/testcases/kernel/syscalls/mknod/mknod02.c b/testcases/kernel/syscalls/mknod/mknod02.c index 89dd1d8740234b788554e625e693693b954440cc..bd476fff79cdde9073dd49664f6fd32031f9d966 100644 --- a/testcases/kernel/syscalls/mknod/mknod02.c +++ b/testcases/kernel/syscalls/mknod/mknod02.c @@ -20,7 +20,7 @@ #define MODE_SGID 02000 #define TEMP_DIR "testdir" -#define TEMP_NODE "testnode" +#define TEMP_NODE TEMP_DIR "/testnode" static struct stat buf; static struct passwd *user_nobody; @@ -37,14 +37,12 @@ static void setup(void) static void run(void) { - SAFE_CHDIR(TEMP_DIR); TST_EXP_PASS(mknod(TEMP_NODE, MODE1, 0), "mknod(%s, %o, 0)", TEMP_NODE, MODE1); SAFE_STAT(TEMP_NODE, &buf); TST_EXP_EQ_LI(buf.st_gid, 0); SAFE_UNLINK(TEMP_NODE); - SAFE_CHDIR(".."); } static struct tst_test test = { From patchwork Fri Apr 25 18:06:03 2025 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: =?utf-8?q?Ricardo_B=2E_Marli=C3=A8re?= X-Patchwork-Id: 2077446 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@legolas.ozlabs.org Authentication-Results: legolas.ozlabs.org; dkim=pass (1024-bit key; unprotected) header.d=lists.linux.it header.i=@lists.linux.it header.a=rsa-sha256 header.s=picard header.b=UnwFwrF1; dkim=fail reason="signature verification failed" (2048-bit key; unprotected) header.d=suse.com header.i=@suse.com header.a=rsa-sha256 header.s=google header.b=I4XDwXrN; dkim-atps=neutral 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=patchwork.ozlabs.org) 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 (secp384r1)) (No client certificate requested) by legolas.ozlabs.org (Postfix) with ESMTPS id 4Zkgm95Pyyz1yMm for ; Sat, 26 Apr 2025 04:07:21 +1000 (AEST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=lists.linux.it; i=@lists.linux.it; q=dns/txt; s=picard; t=1745604456; h=date : mime-version : message-id : references : in-reply-to : to : subject : list-id : list-unsubscribe : list-archive : list-post : list-help : list-subscribe : from : reply-to : cc : content-type : content-transfer-encoding : sender : from; bh=Yc1I6GaK8ofRM1QIGscY4p9K3ixtI5UFKjj/2O0R8lk=; b=UnwFwrF1dAOvE0V43i6qiTQlJr+ifP3hYkneMK0KKpdQtlsZFhbdDb+aszlG/ZRlEbXF0 3onirDm6PKjZlfpDCg0uGP4c3y5jnNnelbPmh/3HJWLlhuAxtrTX0Ir+Ygn30hGf8l0w2J6 +3W2I0Ob4vYF9O8eXzirLmJT4AIPa/s= Received: from picard.linux.it (localhost [IPv6:::1]) by picard.linux.it (Postfix) with ESMTP id 9A7953CBA43 for ; Fri, 25 Apr 2025 20:07:36 +0200 (CEST) X-Original-To: ltp@lists.linux.it Delivered-To: ltp@picard.linux.it Received: from in-4.smtp.seeweb.it (in-4.smtp.seeweb.it [IPv6:2001:4b78:1:20::4]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (secp384r1) server-digest SHA384) (No client certificate requested) by picard.linux.it (Postfix) with ESMTPS id AD9D63CB8FB for ; Fri, 25 Apr 2025 20:06:21 +0200 (CEST) Received: from mail-wr1-x42b.google.com (mail-wr1-x42b.google.com [IPv6:2a00:1450:4864:20::42b]) (using TLSv1.3 with cipher TLS_AES_128_GCM_SHA256 (128/128 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits) server-digest SHA256) (No client certificate requested) by in-4.smtp.seeweb.it (Postfix) with ESMTPS id 572CF1000A59 for ; Fri, 25 Apr 2025 20:06:20 +0200 (CEST) Received: by mail-wr1-x42b.google.com with SMTP id ffacd0b85a97d-39d83782ef6so2601276f8f.0 for ; Fri, 25 Apr 2025 11:06:20 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=suse.com; s=google; t=1745604379; x=1746209179; darn=lists.linux.it; h=cc:to:in-reply-to:references:message-id:content-transfer-encoding :mime-version:subject:date:from:from:to:cc:subject:date:message-id :reply-to; bh=3ansUSli5gfght6soEHV5aUr3uZctaJfncgcvT1Izls=; b=I4XDwXrNuMER87IcfPuI8I046UUAYIY/NP2B16uFfpbrGAc+W1rgBc+H+coFznzZkp wJE5jvtxCnfTdpbzt24UcuDB5od+FIaiP3GfLZOidPu4bvxepi4NuwHRQyygFMjQ3jHP 74cPKo7jwK5ZahHUW8Yu/71Vg3ZrLOW5rIZ2hHnQerX9uKwdixqLT36IYWUOGolHGGe9 g54LldaKs4TXHI6rQ7bETPMVKJVYtK46UPLVYznoFFuLb/gMZnQBGy2nTao30B8jP56K 5CMmf8BBO5ZN8Pg/bJ7Q0otDz5AvXz5SV6wHelfdVj9QXde2GZ6NsV30X+8XbqVhh758 pvEw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1745604379; x=1746209179; h=cc:to:in-reply-to:references:message-id:content-transfer-encoding :mime-version:subject:date:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=3ansUSli5gfght6soEHV5aUr3uZctaJfncgcvT1Izls=; b=l69xKcrj1CcZk1MrlrWs0A3dokhSg06naL2QLHEYyG0rIBDTazKkZx3XTUC5joWe0P Mbtqi1rHJ9tR3Lr1x0zbfMMs7LmwRfDyBhpMne+FXC5UZwMvys3G4R0YlgCHCTEygC8k teT9kI2yBVN1Oe4NIomy19cmXouO9U3KBJdE58wXT5L2njm4mZ/ny/LPKxrjvUsm4kHU m9MUAnPho6YAy+6U/xm11hBaE3oqeMzM1XA/qsifOcqsbktbAIUAuDtxrAEO3ii/bCow XEDWyq8QD4tjSS50JraimKwxaOgT49a9cxqhiUhh3AIGXHx8Vx5QQ/czZTQXJDe1HjpE oT4Q== X-Gm-Message-State: AOJu0Yy1Qn5QmCkb13Yp6Jj31ocSd/RM3DdpgshOBJk3UY9poiUJ8UUO Wk2Axv5OMvDqZvOdkABqQDMnkDxLpvWrJveSg7+VzN5/UyOI00bw0YLE1hKdLo4eBvdWoQ8ypHY 0 X-Gm-Gg: ASbGnctoC6fsxT89t4uCyfPHPBu7wzRxSJhyk93AnoO+5ATVltBZRELCkmZqHFNOzRf 03qhZxbbIgjvnZfufkcPUC/U5qV/tgpSS2pWpY2V9BTDTEg+hvKFA+r5E1pm++AHj6IoBNdiLsL 7aqhZyq1tAwrxqVTfFVo7RVTQOziwWCCdMcTGUdKG2Acd7RFe0Fw1/HuNmp1rDFT8zj/0806IZQ T0eaSbFt46VpKsTzIGIsYO3zzQmD84H6PuW0hcDYiDFAgxfk9WYk/xmNKlLY5xNAqHNeQnVheBk 3ON1csQTX4mtWc1jL7dztdQnQTD9xg== X-Google-Smtp-Source: AGHT+IGRHvMO8pOpN0v3Kj9ceHCEAoPHCIzdyGoS9ayfnOYcFOMwGyj4yfnBJbaVY9dvOw4a802btg== X-Received: by 2002:a05:6000:1ac8:b0:39c:2c0b:8db4 with SMTP id ffacd0b85a97d-3a06d64ca7dmr5977268f8f.10.1745604379305; Fri, 25 Apr 2025 11:06:19 -0700 (PDT) Received: from localhost ([179.228.213.210]) by smtp.gmail.com with UTF8SMTPSA id d2e1a72fcca58-73e25941bf7sm3595948b3a.68.2025.04.25.11.06.18 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 25 Apr 2025 11:06:18 -0700 (PDT) Date: Fri, 25 Apr 2025 15:06:03 -0300 MIME-Version: 1.0 Message-Id: <20250425-conversions-mknod-v4-3-222e0d2e7ef1@suse.com> References: <20250425-conversions-mknod-v4-0-222e0d2e7ef1@suse.com> In-Reply-To: <20250425-conversions-mknod-v4-0-222e0d2e7ef1@suse.com> To: Linux Test Project X-Mailer: b4 0.14.2 X-Developer-Signature: v=1; a=openpgp-sha256; l=10881; i=rbm@suse.com; h=from:subject:message-id; bh=dXnKlGg5BR9frEXG74BWGHZqy8tx2nJ6tmE3nO6tMNE=; b=owEBbQKS/ZANAwAIAckLinxjhlimAcsmYgBoC88N2wIiEe3rZsBCBW+qc79cdvhD8wu1OHpxM SQHhyc+P2uJAjMEAAEIAB0WIQQDCo6eQk7jwGVXh+HJC4p8Y4ZYpgUCaAvPDQAKCRDJC4p8Y4ZY pu3tEACGzA/p1LmFtzs+byns+euFZWyURZiGVCo5nsBLXi293xtR+7sxBlmTAO3EcuvmgLUwNAQ bLqXtwUtRxwDrpqmcWGJzyIXoJ7s5aF4HhlRIv8vmiV8DpaZAAvOiacL0/A8EMY48IFMCMb+Q7M GgGHkkfIpy92c1d1LhKS47HJFUw40aovFGgkbSgPosK0EVwyEuP/9SJ8HWsTP5JXx0tPZ3/IfzV U28gifKfgegxnnU50Lo38NrTMtqksUAPFcM0DyooDOIZfN2AMGFMBLz2d7weJl96tzBLS7GvxuM XsJpXam/Scs70hJXexNlZJI0aU5fHeBa0GR1QXUPGciZBit5sDHdlhtobmnmIa7O6zjR2kZ67uj PoGxiGHiqu5xLTp1qJ6txZMzW3jFiwW0WXSyJAgAciq+UHNYHnkQhebgQzcR7NrMHEXtyCc5azh aQbcSaT181rAJCRHbWJBVwKNkL0KZ0q84Bj0lmJ4CBowmNG5vZR6HWXN3ICdYBSVkCkLYumDlTL vco+0wauyO1y5/AGRssFubniqvSE1XdjWewR21kPrAj8v7yDGi9vRx3CaheTxfC8Bw86LTob8/Y 5vjbuut7RwpGzeTY6C7l+T7kj82ZqwyHloV4NKrLQFFQr/RhWD+BtxFj4EWZEEfoAbdmY2NpCmW sAJ/PamqkpxmAPA== X-Developer-Key: i=rbm@suse.com; a=openpgp; fpr=030A8E9E424EE3C0655787E1C90B8A7C638658A6 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.1 X-Spam-Checker-Version: SpamAssassin 4.0.1 (2024-03-25) on in-4.smtp.seeweb.it X-Virus-Scanned: clamav-milter 1.0.7 at in-4.smtp.seeweb.it X-Virus-Status: Clean Subject: [LTP] [PATCH v4 3/8] syscalls/mknod03: Convert to new API 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: , X-Patchwork-Original-From: =?utf-8?q?Ricardo_B=2E_Marli=C3=A8re_via_ltp?= From: =?utf-8?q?Ricardo_B=2E_Marli=C3=A8re?= Reply-To: =?utf-8?q?Ricardo_B=2E_Marli=C3=A8re?= Cc: =?utf-8?q?Ricardo_B=2E_Marli=C3=A8re?= Errors-To: ltp-bounces+incoming=patchwork.ozlabs.org@lists.linux.it Sender: "ltp" From: Ricardo B. Marlière Signed-off-by: Ricardo B. Marlière --- testcases/kernel/syscalls/mknod/mknod03.c | 313 ++++-------------------------- 1 file changed, 39 insertions(+), 274 deletions(-) diff --git a/testcases/kernel/syscalls/mknod/mknod03.c b/testcases/kernel/syscalls/mknod/mknod03.c index 7ecadb5b37c3ab7eded90aa8a6d1e27f07236b1f..125a4c4e2b1f72b52423ea18037ce9407bb216a0 100644 --- a/testcases/kernel/syscalls/mknod/mknod03.c +++ b/testcases/kernel/syscalls/mknod/mknod03.c @@ -1,296 +1,61 @@ +// SPDX-License-Identifier: GPL-2.0-only /* - * - * Copyright (c) International Business Machines Corp., 2001 - * - * This program is free software; you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation; either version 2 of the License, or - * (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See - * the GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program; if not, write to the Free Software - * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA + * Copyright (c) International Business Machines Corp., 2001 + * 07/2001 Ported by Wayne Boyer + * Copyright (c) 2025 SUSE LLC Ricardo B. Marlière */ -/* - * Test Name: mknod03 - * - * Test Description: - * Verify that mknod(2) succeeds when used to create a filesystem - * node with set group-ID bit set on a directory with set group-ID bit set. - * The node created should have set group-ID bit set and its gid should be - * equal to the effective gid of the process. - * - * Expected Result: - * mknod() should return value 0 on success and node created should have - * set group-ID bit set, its gid should be equal to the effective gid of - * the process. - * - * Algorithm: - * Setup: - * Setup signal handling. - * Create temporary directory. - * Pause for SIGUSR1 if option specified. - * - * Test: - * Loop if the proper options are given. - * Execute system call - * Check return code, if system call failed (return=-1) - * Log the errno and Issue a FAIL message. - * Otherwise, - * Verify the Functionality of system call - * if successful, - * Issue Functionality-Pass message. - * Otherwise, - * Issue Functionality-Fail message. - * Cleanup: - * Print errno log and/or timing stats if options given - * Delete the temporary directory created. - * - * Usage: - * mknod03 [-c n] [-f] [-i n] [-I x] [-P x] [-t] - * where, -c n : Run n copies concurrently. - * -f : Turn off functionality Testing. - * -i n : Execute test n times. - * -I x : Execute test for x seconds. - * -P x : Pause for x seconds between iterations. - * -t : Turn on syscall timing. - * - * HISTORY - * 07/2001 Ported by Wayne Boyer - * - * RESTRICTIONS: - * This test should be run by 'super-user' (root) only. - * +/*\ + * Verify that mknod(2) succeeds when used to create a filesystem node with + * set-group-ID bit set on a directory with set-group-ID bit set. The node + * created should have set-group-ID bit set and its gid should be equal to + * the "nobody" gid. */ -#include -#include -#include -#include -#include -#include #include -#include -#include - -#include "test.h" -#include "safe_macros.h" - -#define LTPUSER "nobody" -#define MODE_RWX S_IFIFO | S_IRWXU | S_IRWXG | S_IRWXO -#define MODE_SGID S_IFIFO | S_ISGID | S_IRWXU | S_IRWXG | S_IRWXO -#define DIR_TEMP "testdir_3" -#define TNODE "tnode_%d" +#include "tst_uid.h" +#include "tst_test.h" -struct stat buf; /* struct. to hold stat(2) o/p contents */ -struct passwd *user1; /* struct. to hold getpwnam(3) o/p contents */ +#define MODE_RWX 0777 +#define MODE_SGID (S_ISGID | 0777) -char *TCID = "mknod03"; -int TST_TOTAL = 1; -char node_name[PATH_MAX]; /* buffer to hold node name created */ +#define TEMP_DIR "testdir" +#define TEMP_NODE TEMP_DIR "/testnode" -gid_t group1_gid, group2_gid, mygid; /* user and process group id's */ -uid_t save_myuid, user1_uid; /* user and process user id's */ -pid_t mypid; /* process id */ +static uid_t nobody_uid; +static gid_t nobody_gid, free_gid; -void setup(); /* setup function for the test */ -void cleanup(); /* cleanup function for the test */ - -int main(int ac, char **av) +static void run(void) { - int lc; - int fflag; - - tst_parse_opts(ac, av, NULL, NULL); - - setup(); - - for (lc = 0; TEST_LOOPING(lc); lc++) { - - tst_count = 0; + struct stat buf; - /* - * Attempt to create a filesystem node with group id (sgid) - * bit set on a directory with group id (sgid) bit set - * such that, the node created by mknod(2) should have - * group id (sgid) bit set and node's gid should be equal - * to that of effective gid of the process. - */ - TEST(mknod(node_name, MODE_SGID, 0)); + SAFE_MKNOD(TEMP_NODE, MODE_SGID, 0); - /* Check return code from mknod(2) */ - if (TEST_RETURN == -1) { - tst_resm(TFAIL, "mknod(%s, %#o, 0) failed, errno=%d : " - "%s", node_name, MODE_SGID, TEST_ERRNO, - strerror(TEST_ERRNO)); - continue; - } - /* Set the functionality flag */ - fflag = 1; + SAFE_STAT(TEMP_NODE, &buf); + TST_EXP_EQ_LI(buf.st_gid, free_gid); - /* Check for node's creation */ - if (stat(node_name, &buf) < 0) { - tst_resm(TFAIL, "stat() of %s failed, errno:%d", - node_name, TEST_ERRNO); - /* unset functionality flag */ - fflag = 0; - } - - /* - * Skip S_ISGID check - * 0fa3ecd87848 ("Fix up non-directory creation in SGID directories") - * clears S_ISGID for files created by non-group members - */ - - /* Verify group ID */ - if (buf.st_gid != group2_gid) { - tst_resm(TFAIL, "%s: Incorrect group", - node_name); - /* unset flag as functionality fails */ - fflag = 0; - } - if (fflag) { - tst_resm(TPASS, "Functionality of mknod(%s, " - "%#o, 0) successful", - node_name, MODE_SGID); - } - - /* Remove the node for the next go `round */ - if (unlink(node_name) == -1) { - tst_resm(TWARN, "unlink(%s) failed, errno:%d %s", - node_name, errno, strerror(errno)); - } - } - - /* Change the directory back to temporary directory */ - SAFE_CHDIR(cleanup, ".."); - - /* - * Invoke cleanup() to delete the test directories created - * in the setup() and exit main(). - */ - cleanup(); - - tst_exit(); + SAFE_UNLINK(TEMP_NODE); } -/* - * setup(void) - performs all ONE TIME setup for this test. - * Exit the test program on receipt of unexpected signals. - * Create a temporary directory used to hold test directories created - * and change the directory to it. - * Verify that pid of process executing the test is root. - * Create a test directory on temporary directory and set the ownership - * of test directory to guest user and process, change mode permissions - * to set group id bit on it. - * Set the effective uid/gid of the process to that of guest user. - */ -void setup(void) +static void setup(void) { - tst_require_root(); - - /* Capture unexpected signals */ - tst_sig(NOFORK, DEF_HANDLER, cleanup); + struct passwd *ltpuser = SAFE_GETPWNAM("nobody"); - TEST_PAUSE; + nobody_uid = ltpuser->pw_uid; + nobody_gid = ltpuser->pw_gid; + free_gid = tst_get_free_gid(nobody_gid); - /* Make a temp dir and cd to it */ - tst_tmpdir(); + SAFE_MKDIR(TEMP_DIR, MODE_RWX); + SAFE_CHOWN(TEMP_DIR, nobody_uid, free_gid); + SAFE_CHMOD(TEMP_DIR, MODE_SGID); - /* fix permissions on the tmpdir */ - if (chmod(".", 0711) != 0) { - tst_brkm(TBROK, cleanup, "chmod() failed"); - } - - /* Save the real user id of the current test process */ - save_myuid = getuid(); - /* Save the process id of the current test process */ - mypid = getpid(); - - /* Get the node name to be created in the test */ - sprintf(node_name, TNODE, mypid); - - /* Get the uid/gid of ltpuser user */ - if ((user1 = getpwnam(LTPUSER)) == NULL) { - tst_brkm(TBROK, cleanup, "%s not in /etc/passwd", LTPUSER); - } - user1_uid = user1->pw_uid; - group1_gid = user1->pw_gid; - - /* Get the effective group id of the test process */ - group2_gid = getegid(); - - /* - * Create a test directory under temporary directory with the - * specified mode permissions, with uid/gid set to that of guest - * user and the test process. - */ - SAFE_MKDIR(cleanup, DIR_TEMP, MODE_RWX); - SAFE_CHOWN(cleanup, DIR_TEMP, user1_uid, group2_gid); - SAFE_CHMOD(cleanup, DIR_TEMP, MODE_SGID); - - /* - * Verify that test directory created with expected permission modes - * and ownerships. - */ - SAFE_STAT(cleanup, DIR_TEMP, &buf); - - /* Verify modes of test directory */ - if (!(buf.st_mode & S_ISGID)) { - tst_brkm(TBROK, cleanup, - "%s: Incorrect modes, setgid bit not set", DIR_TEMP); - } - - /* Verify group ID of test directory */ - if (buf.st_gid != group2_gid) { - tst_brkm(TBROK, cleanup, "%s: Incorrect group", DIR_TEMP); - } - - /* - * Set the effective group id and user id of the test process - * to that of guest user (nobody) - */ - SAFE_SETGID(cleanup, group1_gid); - if (setreuid(-1, user1_uid) < 0) { - tst_brkm(TBROK, cleanup, - "Unable to set process uid to that of ltp user"); - } - - /* Save the real group ID of the current process */ - mygid = getgid(); - - /* Change directory to DIR_TEMP */ - SAFE_CHDIR(cleanup, DIR_TEMP); + SAFE_SETGID(nobody_gid); + SAFE_SETREUID(-1, nobody_uid); } -/* - * cleanup() - Performs all ONE TIME cleanup for this test at - * completion or premature exit. - * Print test timing stats and errno log if test executed with options. - * Restore the real/effective user id of the process changed during - * setup(). - * Remove temporary directory and sub-directories/files under it - * created during setup(). - * Exit the test program with normal exit code. - */ -void cleanup(void) -{ - - /* - * Restore the effective uid of the process changed in the - * setup(). - */ - if (setreuid(-1, save_myuid) < 0) { - tst_brkm(TBROK, NULL, - "resetting process real/effective uid failed"); - } - - tst_rmdir(); - -} +static struct tst_test test = { + .setup = setup, + .test_all = run, + .needs_root = 1, + .needs_tmpdir = 1, +}; From patchwork Fri Apr 25 18:06:04 2025 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: =?utf-8?q?Ricardo_B=2E_Marli=C3=A8re?= X-Patchwork-Id: 2077447 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@legolas.ozlabs.org Authentication-Results: legolas.ozlabs.org; dkim=pass (1024-bit key; unprotected) header.d=lists.linux.it header.i=@lists.linux.it header.a=rsa-sha256 header.s=picard header.b=Ee4wja6h; dkim=fail reason="signature verification failed" (2048-bit key; unprotected) header.d=suse.com header.i=@suse.com header.a=rsa-sha256 header.s=google header.b=g+mpDsK6; dkim-atps=neutral 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=patchwork.ozlabs.org) 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 (secp384r1)) (No client certificate requested) by legolas.ozlabs.org (Postfix) with ESMTPS id 4Zkgmj4vlbz1yMm for ; Sat, 26 Apr 2025 04:07:49 +1000 (AEST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=lists.linux.it; i=@lists.linux.it; q=dns/txt; s=picard; t=1745604485; h=date : mime-version : message-id : references : in-reply-to : to : subject : list-id : list-unsubscribe : list-archive : list-post : list-help : list-subscribe : from : reply-to : cc : content-type : content-transfer-encoding : sender : from; bh=MdroALtKBD3H3ubuQMxEnDlNnSfN7aKy3AEHOdiHN+Q=; b=Ee4wja6hNU9hy9aQOTZmFBosBtstQ3YEpfN78UZltG6uOmfHZtS+r/9mkEKWSxgUuB26Y Js3zSrynNqseoKzccx3hTNbjqiPeTH8p3nkS5Qcwml2zjkw2syu6Xfn7a7rjjuL7ddt4f2c blJfexjzahe7KlI/xda7deAGHtAbn44= Received: from picard.linux.it (localhost [IPv6:::1]) by picard.linux.it (Postfix) with ESMTP id 0F5463CBA5F for ; Fri, 25 Apr 2025 20:08:05 +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 (secp384r1) server-digest SHA384) (No client certificate requested) by picard.linux.it (Postfix) with ESMTPS id EBF7C3CBAA2 for ; Fri, 25 Apr 2025 20:06:23 +0200 (CEST) Received: from mail-ej1-x62b.google.com (mail-ej1-x62b.google.com [IPv6:2a00:1450:4864:20::62b]) (using TLSv1.3 with cipher TLS_AES_128_GCM_SHA256 (128/128 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 25AA36005DC for ; Fri, 25 Apr 2025 20:06:23 +0200 (CEST) Received: by mail-ej1-x62b.google.com with SMTP id a640c23a62f3a-acacb8743a7so424612266b.1 for ; Fri, 25 Apr 2025 11:06:23 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=suse.com; s=google; t=1745604382; x=1746209182; darn=lists.linux.it; h=cc:to:in-reply-to:references:message-id:content-transfer-encoding :mime-version:subject:date:from:from:to:cc:subject:date:message-id :reply-to; bh=tho9vI9rSl2BfAV1QNFEmZLl10rX1T6Sl7trhHs5SpY=; b=g+mpDsK6EfO8OObQv7rdj14bibK5hl2OfJ/08QsJT71/e3p8DYmlcBMYBXPZDCstzu rCoc9/b5SargFeYmcuLMvuS4yBvb/299u6ZB7VX28HCOcviUbZXTL04+QSD2ijq16LS3 erF7zHVry8P837H7IXuwPaem9SctV+70P3NGvJi2xW9C9Rfk9oDAUg+ywK2ApZFMBDCT Dg6mYKV1gibPlFaoNNZ5Cm4OTjzdSkPx24WG1fF/kGmSZFz8JI7612holepSSmO9dSy4 JUualgNe1qVmGXXNfGaWOK39UgHQjmYARRJGg7es5H49g+m8ro7B0eSQ60WDnqfi03NE MrFw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1745604382; x=1746209182; h=cc:to:in-reply-to:references:message-id:content-transfer-encoding :mime-version:subject:date:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=tho9vI9rSl2BfAV1QNFEmZLl10rX1T6Sl7trhHs5SpY=; b=nVzz7gpcEb1lYDAFmD+fo9pFUZIp+2GOpHJZ2CcIKBVfiCqhYEneLR2IPtsvnfEKLq fytuhZr5M6ffr/aU5wKWlQSoK+uJrKNTZMCu7OO8S6zNtvKJE/OuE4O9iprCSxuPYzSC TV10Qc+oDzsIjZMz8wRy2ZJ8s0pSrTCoUtskO/dJXP2Hl1L17RYgFOjATa+MKY2Dtpee HSbrLWb5g3mkzHx5tvd2efQ6lFdpLnTJCGQegBHe7U0U8AXh6UER4mh+RRrnzDn+Vpy0 IZxN2i0L/8rgA3kND6uJ6eMPFz3ULachcZgnh5U+xV6Gq8NGbi2Koz1bxSPqH9cgKcbS T9cg== X-Gm-Message-State: AOJu0YwuenTkRj0O29RSUKqFjh5flHfVput9jeVzN+gHqa4WKl071S6/ w14TfDh7ni5AITMgE1IpjZBAZfgWfhN209H0FvwvU1LnC5W9VLEYdEinNxm8DevpwP3NPMU3oOA s X-Gm-Gg: ASbGnctoy936m6TIF8LtkYn5JO3boXBCg1Vi/2OyrWe2uZO+LEYlC7YHy3drSVHuwks corguwCyHsv9AcdbCMMXMqcgwwK2qhvGm3ksXGqEplOn5BMMbjYmTxDkMdMutYzfFDUWGVF24dH IW6wy4sCwxSVSI4k9zkJPJy7oqvsP03r51ir6ttvKfAByCJ16xQp+qb/c00lWBQzOBf7vWiMo26 v6gFvMpcUdzZm5Rf4+n2Brn3GyPsOIKg9fA073bDYOgrmvRoTDdQCdfJcvWIoTMCSX+Fp8R0M73 o3Nad7yPJoeURUCf2YyQSeriWELydw== X-Google-Smtp-Source: AGHT+IGSJ341vcCn7l9WsSaNqRcFYxUwSO+lxA2VRV2b/5vGw2ZKa7vr2wkUzIlemA0mwCl/+qNP0A== X-Received: by 2002:a17:907:3ea8:b0:ac6:f5b5:36e0 with SMTP id a640c23a62f3a-ace5a44935cmr659110666b.19.1745604382067; Fri, 25 Apr 2025 11:06:22 -0700 (PDT) Received: from localhost ([179.228.213.210]) by smtp.gmail.com with UTF8SMTPSA id 98e67ed59e1d1-309f77417d6sm1990750a91.4.2025.04.25.11.06.21 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 25 Apr 2025 11:06:21 -0700 (PDT) Date: Fri, 25 Apr 2025 15:06:04 -0300 MIME-Version: 1.0 Message-Id: <20250425-conversions-mknod-v4-4-222e0d2e7ef1@suse.com> References: <20250425-conversions-mknod-v4-0-222e0d2e7ef1@suse.com> In-Reply-To: <20250425-conversions-mknod-v4-0-222e0d2e7ef1@suse.com> To: Linux Test Project X-Mailer: b4 0.14.2 X-Developer-Signature: v=1; a=openpgp-sha256; l=10924; i=rbm@suse.com; h=from:subject:message-id; bh=aR0UKKMmgd71mc7C/QYNnJZHpjZ9enpbvWA955sVbiA=; b=owEBbQKS/ZANAwAIAckLinxjhlimAcsmYgBoC88N4KiizCZOMGAqj9wezQh2KdZbEB2JhFhAC 7e4jpfmcE2JAjMEAAEIAB0WIQQDCo6eQk7jwGVXh+HJC4p8Y4ZYpgUCaAvPDQAKCRDJC4p8Y4ZY pqMFEACyhUkG6LzeXuyMrHos8whf32MGQcFHho5drOa0IlYymekROE7AQD7gtqjp9lnBfRlf2zz U1BQbzLf1p5nIp/22G7p0sbK/XFCMlSauH1nHdg/zPHcYuGyhfDj2vAVM1nXR0X1e1rZtWGS7OE tKwzCtkabuHHDaQ1sCvyAmutpeY2d+Nyzft7IyHlnOLfUIsiLSmWQDt/Cyo0qIFDHJfvehTlr4e zo6jq3i7V3kemzplw97aC2cBObJIe9FXkaXA8hKg8anZaX7jFQ+aJrH8Hxc+x7ZNTnOyjbuIWFF SowlZXf6oQbdFRuXDe2cxaHrgF4LzrN6aL6YzIRdmbAlXaDFS/SsDr2jC2WSzAzNYbN1NDglTIt DQEaWSmBO87x0CUpVnpGonCnidANjYeSNTsVEiT7KiFHfkOtI86sGIyiMZI0sEbyQ9Y12Nb6b7N 5o73uHLB7ZYnfj7H3UdU1fCdjPADMBaR/pZYE26gCuuKXNyhbHYHg3IY8PL4AeDjzEq9mf4yuVk BKbN79nUDZOzB5x6dL/eUL6TVUPhmuEvV3tM/bE3a9ZBNKsawLFP4vNYwVJPVjRUTnkpBwNzVEO Tec5+M8KpEjSbkCJWKcWmlS7wooE1B6/8xmveSGs45TKrIsMUmxyl8xCBXNDuVIbopBOJfuc5FU j2UK6Yd/cf7Bc6A== X-Developer-Key: i=rbm@suse.com; a=openpgp; fpr=030A8E9E424EE3C0655787E1C90B8A7C638658A6 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.1 X-Spam-Checker-Version: SpamAssassin 4.0.1 (2024-03-25) on in-5.smtp.seeweb.it X-Virus-Scanned: clamav-milter 1.0.7 at in-5.smtp.seeweb.it X-Virus-Status: Clean Subject: [LTP] [PATCH v4 4/8] syscalls/mknod04: Convert to new API 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: , X-Patchwork-Original-From: =?utf-8?q?Ricardo_B=2E_Marli=C3=A8re_via_ltp?= From: =?utf-8?q?Ricardo_B=2E_Marli=C3=A8re?= Reply-To: =?utf-8?q?Ricardo_B=2E_Marli=C3=A8re?= Cc: =?utf-8?q?Ricardo_B=2E_Marli=C3=A8re?= Errors-To: ltp-bounces+incoming=patchwork.ozlabs.org@lists.linux.it Sender: "ltp" From: Ricardo B. Marlière Signed-off-by: Ricardo B. Marlière Reviewed-by: Andrea Cervesato --- testcases/kernel/syscalls/mknod/mknod04.c | 319 ++++-------------------------- 1 file changed, 40 insertions(+), 279 deletions(-) diff --git a/testcases/kernel/syscalls/mknod/mknod04.c b/testcases/kernel/syscalls/mknod/mknod04.c index e0123ec07d95887a5fb8ab730103ba9531d4783d..ceb9565b4d2842b563637e882cedafb0e9731c01 100644 --- a/testcases/kernel/syscalls/mknod/mknod04.c +++ b/testcases/kernel/syscalls/mknod/mknod04.c @@ -1,301 +1,62 @@ +// SPDX-License-Identifier: GPL-2.0-or-later /* - * - * Copyright (c) International Business Machines Corp., 2001 - * - * This program is free software; you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation; either version 2 of the License, or - * (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See - * the GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program; if not, write to the Free Software - * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA + * Copyright (c) International Business Machines Corp., 2001 + * 07/2001 Ported by Wayne Boyer + * Copyright (c) 2025 SUSE LLC Ricardo B. Marlière */ -/* - * Test Name: mknod04 - * - * Test Description: - * Verify that mknod(2) succeeds when used to create a filesystem - * node on a directory with set group-ID bit set. - * The node created should not have group-ID bit set and its gid should be - * equal to the effective gid of the process. - * - * Expected Result: - * mknod() should return value 0 on success and node created should not - * have set group-ID bit set and its gid should be equal to the effective - * gid of the process. - * - * Algorithm: - * Setup: - * Setup signal handling. - * Create temporary directory. - * Pause for SIGUSR1 if option specified. - * - * Test: - * Loop if the proper options are given. - * Execute system call - * Check return code, if system call failed (return=-1) - * Log the errno and Issue a FAIL message. - * Otherwise, - * Verify the Functionality of system call - * if successful, - * Issue Functionality-Pass message. - * Otherwise, - * Issue Functionality-Fail message. - * Cleanup: - * Print errno log and/or timing stats if options given - * Delete the temporary directory created. - * - * Usage: - * mknod04 [-c n] [-f] [-i n] [-I x] [-P x] [-t] - * where, -c n : Run n copies concurrently. - * -f : Turn off functionality Testing. - * -i n : Execute test n times. - * -I x : Execute test for x seconds. - * -P x : Pause for x seconds between iterations. - * -t : Turn on syscall timing. - * - * HISTORY - * 07/2001 Ported by Wayne Boyer - * - * RESTRICTIONS: - * This test should be run by 'super-user' (root) only. - * +/*\ + * Verify that mknod(2) succeeds when used to create a filesystem node on a + * directory with set-group-ID bit set. The node created should not have + * set-group-ID bit set and its gid should be equal to the effective + * gid of the process. */ -#include -#include -#include -#include -#include -#include #include -#include -#include - -#include "test.h" -#include "safe_macros.h" - -#define LTPUSER "nobody" -#define MODE_RWX S_IFIFO | S_IRWXU | S_IRWXG | S_IRWXO -#define MODE_SGID S_IFIFO | S_ISGID | S_IRWXU | S_IRWXG | S_IRWXO -#define DIR_TEMP "testdir_4" -#define TNODE "tnode_%d" +#include "tst_uid.h" +#include "tst_test.h" -struct stat buf; /* struct. to hold stat(2) o/p contents */ -struct passwd *user1; /* struct. to hold getpwnam(3) o/p contents */ +#define MODE_RWX 0777 +#define MODE_SGID (S_ISGID | 0777) -char *TCID = "mknod04"; -int TST_TOTAL = 1; -char node_name[PATH_MAX]; /* buffer to hold node name created */ +#define TEMP_DIR "testdir" +#define TEMP_NODE TEMP_DIR "/testnode" -gid_t group1_gid, group2_gid, mygid; /* user and process group id's */ -uid_t save_myuid, user1_uid; /* user and process user id's */ -pid_t mypid; /* process id */ +static uid_t nobody_uid; +static gid_t nobody_gid, free_gid; -void setup(); /* setup function for the test */ -void cleanup(); /* cleanup function for the test */ - -int main(int ac, char **av) +static void run(void) { - int lc; - int fflag; - - tst_parse_opts(ac, av, NULL, NULL); - - setup(); - - for (lc = 0; TEST_LOOPING(lc); lc++) { - - tst_count = 0; + struct stat buf; - /* - * TEST CASE CONDITION: - * Attempt to create a filesystem node on a directory - * with group id (sgid) bit set such that, - * the node created by mknod(2) should not have group id - * (sgid) bit set and node's gid should be equal to the - * effective gid of the process. - */ - TEST(mknod(node_name, MODE_RWX, 0)); + SAFE_MKNOD(TEMP_NODE, MODE_RWX, 0); - /* Check return code from mknod(2) */ - if (TEST_RETURN == -1) { - tst_resm(TFAIL, "mknod(%s, %#o, 0) failed, errno=%d : " - "%s", node_name, MODE_RWX, TEST_ERRNO, - strerror(TEST_ERRNO)); - continue; - } - /* Set the functionality flag */ - fflag = 1; + SAFE_STAT(TEMP_NODE, &buf); + TST_EXP_EQ_LI(buf.st_mode & S_ISGID, 0); + TST_EXP_EQ_LI(buf.st_gid, free_gid); - /* Check for node's creation */ - if (stat(node_name, &buf) < 0) { - tst_resm(TFAIL, "stat() of %s failed, errno:%d", - node_name, TEST_ERRNO); - /* unset fflag */ - fflag = 0; - } - - /* Verify mode permissions of node */ - if (buf.st_mode & S_ISGID) { - tst_resm(TFAIL, "%s: Incorrect modes, setgid " - "bit set", node_name); - /* unset flag as functionality fails */ - fflag = 0; - } - - /* Verify group ID of node */ - if (buf.st_gid != group2_gid) { - tst_resm(TFAIL, "%s: Incorrect group", - node_name); - /* unset flag as functionality fails */ - fflag = 0; - } - if (fflag) { - tst_resm(TPASS, "Functionality of mknod(%s, " - "%#o, 0) successful", - node_name, MODE_RWX); - } - - /* Remove the node for the next go `round */ - if (unlink(node_name) == -1) { - tst_resm(TWARN, "unlink(%s) failed, errno:%d %s", - node_name, errno, strerror(errno)); - } - } - - /* Change the directory back to temporary directory */ - SAFE_CHDIR(cleanup, ".."); - - /* - * Invoke cleanup() to delete the test directories created - * in the setup() and exit main(). - */ - cleanup(); - - tst_exit(); + SAFE_UNLINK(TEMP_NODE); } -/* - * void - * setup(void) - performs all ONE TIME setup for this test. - * Exit the test program on receipt of unexpected signals. - * Create a temporary directory used to hold test directories created - * and change the directory to it. - * Verify that pid of process executing the test is root. - * Create a test directory on temporary directory and set the ownership - * of test directory to guest user and process, change mode permissions - * to set group-id bit on it. - * Set the effective uid/gid of the process to that of guest user. - */ -void setup(void) +static void setup(void) { - tst_require_root(); - - /* Capture unexpected signals */ - tst_sig(NOFORK, DEF_HANDLER, cleanup); + struct passwd *ltpuser = SAFE_GETPWNAM("nobody"); - TEST_PAUSE; + nobody_uid = ltpuser->pw_uid; + nobody_gid = ltpuser->pw_gid; + free_gid = tst_get_free_gid(nobody_gid); - /* Make a temp dir and cd to it */ - tst_tmpdir(); + SAFE_MKDIR(TEMP_DIR, MODE_RWX); + SAFE_CHOWN(TEMP_DIR, nobody_uid, free_gid); + SAFE_CHMOD(TEMP_DIR, MODE_SGID); - /* fix permissions on the tmpdir */ - if (chmod(".", 0711) != 0) { - tst_brkm(TBROK, cleanup, "chmod() failed"); - } - - /* Save the real user id of the current test process */ - save_myuid = getuid(); - - /* Save the process id of the current test process */ - mypid = getpid(); - - /* Get the node name to be created in the test */ - sprintf(node_name, TNODE, mypid); - - /* Get the uid/gid of ltp user */ - if ((user1 = getpwnam(LTPUSER)) == NULL) { - tst_brkm(TBROK, cleanup, "%s not in /etc/passwd", LTPUSER); - } - user1_uid = user1->pw_uid; - group1_gid = user1->pw_gid; - - /* Get the effective group id of the test process */ - group2_gid = getegid(); - - /* - * Create a test directory under temporary directory with the - * specified mode permissions, with uid/gid set to that of guest - * user and the test process. - */ - SAFE_MKDIR(cleanup, DIR_TEMP, MODE_RWX); - SAFE_CHOWN(cleanup, DIR_TEMP, user1_uid, group2_gid); - SAFE_CHMOD(cleanup, DIR_TEMP, MODE_SGID); - - /* - * Verify that test directory created with expected permission modes - * and ownerships. - */ - SAFE_STAT(cleanup, DIR_TEMP, &buf); - - /* Verify modes of test directory */ - if (!(buf.st_mode & S_ISGID)) { - tst_brkm(TBROK, cleanup, - "%s: Incorrect modes, setgid bit not set", DIR_TEMP); - } - - /* Verify group ID */ - if (buf.st_gid != group2_gid) { - tst_brkm(TBROK, cleanup, "%s: Incorrect group", DIR_TEMP); - } - - /* - * Set the effective group id and user id of the test process - * to that of guest user (nobody) - */ - SAFE_SETGID(cleanup, group1_gid); - if (setreuid(-1, user1_uid) < 0) { - tst_brkm(TBROK, cleanup, - "Unable to set process uid to that of ltp user"); - } - - /* Save the real group ID of the current process */ - mygid = getgid(); - - /* Change directory to DIR_TEMP */ - SAFE_CHDIR(cleanup, DIR_TEMP); + SAFE_SETGID(nobody_gid); + SAFE_SETREUID(-1, nobody_uid); } -/* - * cleanup() - Performs all ONE TIME cleanup for this test at - * completion or premature exit. - * Print test timing stats and errno log if test executed with options. - * Restore the real/effective user id of the process changed during - * setup(). - * Remove temporary directory and sub-directories/files under it - * created during setup(). - * Exit the test program with normal exit code. - */ -void cleanup(void) -{ - - /* - * Restore the effective uid of the process changed in the - * setup(). - */ - if (setreuid(-1, save_myuid) < 0) { - tst_brkm(TBROK, cleanup, - "resetting process real/effective uid failed"); - } - - tst_rmdir(); - -} +static struct tst_test test = { + .setup = setup, + .test_all = run, + .needs_root = 1, + .needs_tmpdir = 1, +}; From patchwork Fri Apr 25 18:06:05 2025 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: =?utf-8?q?Ricardo_B=2E_Marli=C3=A8re?= X-Patchwork-Id: 2077448 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@legolas.ozlabs.org Authentication-Results: legolas.ozlabs.org; dkim=pass (1024-bit key; unprotected) header.d=lists.linux.it header.i=@lists.linux.it header.a=rsa-sha256 header.s=picard header.b=GaAxAl8W; dkim=fail reason="signature verification failed" (2048-bit key; unprotected) header.d=suse.com header.i=@suse.com header.a=rsa-sha256 header.s=google header.b=d5OhTku/; dkim-atps=neutral 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=patchwork.ozlabs.org) 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 (secp384r1)) (No client certificate requested) by legolas.ozlabs.org (Postfix) with ESMTPS id 4Zkgn75RVXz1yMm for ; Sat, 26 Apr 2025 04:08:11 +1000 (AEST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=lists.linux.it; i=@lists.linux.it; q=dns/txt; s=picard; t=1745604507; h=date : mime-version : message-id : references : in-reply-to : to : subject : list-id : list-unsubscribe : list-archive : list-post : list-help : list-subscribe : from : reply-to : cc : content-type : content-transfer-encoding : sender : from; bh=Ugn1PuuuTi9ETy8+EW6Gtvhaj5h7XEqIRwLZvaqEAAg=; b=GaAxAl8W26EnPvyRB6bd1TAtkg7dlYmAZvEFtlezN+W5oiMTHdSrPI62f5afWGxXW21o1 mjOg5dtbwU4JuprelOryzx39DT0PmkmRkBAZStw4bF6Pg8Tqd+Sq5VTzPik4gvlNCXXkprS RA4igolLZXz1fGIrTXoQcBV2/SAOvww= Received: from picard.linux.it (localhost [IPv6:::1]) by picard.linux.it (Postfix) with ESMTP id 400E13CBA4F for ; Fri, 25 Apr 2025 20:08:27 +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 [217.194.8.6]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (secp384r1)) (No client certificate requested) by picard.linux.it (Postfix) with ESMTPS id 4A4F83CBA41 for ; Fri, 25 Apr 2025 20:06:27 +0200 (CEST) Received: from mail-wr1-x435.google.com (mail-wr1-x435.google.com [IPv6:2a00:1450:4864:20::435]) (using TLSv1.3 with cipher TLS_AES_128_GCM_SHA256 (128/128 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 6C9391400E0F for ; Fri, 25 Apr 2025 20:06:26 +0200 (CEST) Received: by mail-wr1-x435.google.com with SMTP id ffacd0b85a97d-39c1efc457bso1811547f8f.2 for ; Fri, 25 Apr 2025 11:06:26 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=suse.com; s=google; t=1745604385; x=1746209185; darn=lists.linux.it; h=cc:to:in-reply-to:references:message-id:content-transfer-encoding :mime-version:subject:date:from:from:to:cc:subject:date:message-id :reply-to; bh=upayJtOAGmhWX590JxHh4ycQI2bghJE9pw1G6fsUXkQ=; b=d5OhTku/ONQsXRNpotDAZdhMrtJejpqNhtglIf8HpQDIvQLkIxOGJxT9nYm7SU4NjW ApLCf3Kpmm4xF8/zGZngb+37HL5BrpcWZETua96Lke8lrA8YAZhexWziGe3bI052b/OR PW2IUV7q7q2VzB5fCAM9W3rDCwaDLThvQd7jfCFpFkL2dMMFbZuDlG44zlKlsKJTJkWi QZylOQe0zxCn/hlcD01GyN3Dc5AH6ezO3W8YLp6Sh87V3ETs5QCjVf6MZbrTmkd5Rb+d q0WBOBeV8wf9qvQBx6SxwnHksYX52U3nt6waGtYthhE1RofLYNtnTM0CfCSDIk4mWZyU TSNQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1745604385; x=1746209185; h=cc:to:in-reply-to:references:message-id:content-transfer-encoding :mime-version:subject:date:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=upayJtOAGmhWX590JxHh4ycQI2bghJE9pw1G6fsUXkQ=; b=FoTf8q3/CEpP/bZ/d0gPc2AlmMyMFV1dT8XGui2uOfHNcrfGEwC+1D0mbYakYwQB+i 3X2kKVrxWjrc3rLwmDpreMsxJHQGOMp6g/d3P3wFaIQw9S78TykU76amNlXIsEio3VnR RbVAnKebv7nZCFgQh7K8xfA4+WsUchDG+/nCkS6x45PRyuk7NsHaw0u4DbP9onfzg6Cb GNJRHczDVnCQl2TqZXeCp9oNgLuPU/QXZ4LkTwDlgnnmS8RYvsEjBo+DEsEWQzHqp5xj 2Gmxjc26DI/iw885y3ovQDZTzyH6Es7e3XvWAqCi1oZdI7KR+qkEcZ0D1rfVjcLBhekI 38mg== X-Gm-Message-State: AOJu0YwvID6Xi40Z2kmz9/Ww1kDzlhSAMiea/ucnvSwz8yflNUIFAwuV KU9+1/snB2FfoPF+s/dF/toAQ4VBBFxh83JNFdoHDwJtufbe2mLTJsw54NZH5hzEp57doAAz7vV n X-Gm-Gg: ASbGncv29d2ABD23Ie32PxVzx6ZywbdfnUJQtpGdaRK2V4DM5HNUuBY8K1W+jR4IO5v TMZw+h9l6Kou/ipPWeeqB8sETpOd/NNxLpQRFsKH3ICcJ/yKC9xuOIzONP+CqXmerFmLWWkc559 +lfErfJ95a514a6rZmiawFaw74Od7DyXJ3zHWmjrar8nA3tgfLiFxUu8/TKtw7R7bzVaatSGPwp WTyAIID6gjainVfhU7FoIVcFlcD1EZ6P5WI5PHLk9Oieu725TaJYOZBxgNQC8zUPP2E006aTBKu 2yTypZupbh4vpep+mcKPtb3T6+unPw== X-Google-Smtp-Source: AGHT+IEMdvRc95ZbaQpwonGpRng1SD4c1G+ScGbt2OQiflAmI1hhhrjhpEuQXkYWHMMq1P6qIeGQVw== X-Received: by 2002:a5d:59ad:0:b0:39a:d20b:5c25 with SMTP id ffacd0b85a97d-3a07aa75964mr214947f8f.26.1745604384918; Fri, 25 Apr 2025 11:06:24 -0700 (PDT) Received: from localhost ([179.228.213.210]) by smtp.gmail.com with UTF8SMTPSA id d2e1a72fcca58-73e25941be8sm3622024b3a.58.2025.04.25.11.06.23 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 25 Apr 2025 11:06:24 -0700 (PDT) Date: Fri, 25 Apr 2025 15:06:05 -0300 MIME-Version: 1.0 Message-Id: <20250425-conversions-mknod-v4-5-222e0d2e7ef1@suse.com> References: <20250425-conversions-mknod-v4-0-222e0d2e7ef1@suse.com> In-Reply-To: <20250425-conversions-mknod-v4-0-222e0d2e7ef1@suse.com> To: Linux Test Project X-Mailer: b4 0.14.2 X-Developer-Signature: v=1; a=openpgp-sha256; l=10125; i=rbm@suse.com; h=from:subject:message-id; bh=WeOMntYGPdLp9Tf3PIm4XrQlR1+hkzI6LBaz4P11EZg=; b=owEBbQKS/ZANAwAIAckLinxjhlimAcsmYgBoC88NPJgSqhx2RaPvvZF8blN7Wu7oqMM4l6VcB H2Mpqf+QHaJAjMEAAEIAB0WIQQDCo6eQk7jwGVXh+HJC4p8Y4ZYpgUCaAvPDQAKCRDJC4p8Y4ZY ptRUD/45tePXbvtgLGC2XivuWFXN3DhnlxLt6R8iDB/CSkBJuF0Y4QIpa24x/0cFSfhnlh0hfx4 rcaMDHl18j0IyISUiswLoWIiXt2zmZPNzgs1KYRNwvRV5uLFxSGxkMnd9IHdYpo8O8DTn8ynYIk EztVYriYlIX1PtR39+BmQzsM7VDyvWZx0nlNFCV3RMDxEJ0WGxJo0vNptzO7nkL30kD0P4dlwdv 0jLOV6LT3OcOPXNOCWOLkDo8wzWIeT44iF0z6sJWqFWaxTSR0kpZke9uW+yE4ivfk7s0rtRdaXC nHhw3aO2l1QtbXSiF5hSSRoXIyq0ZQNlKvPVTioAeFR7ZFXPxYoO7pgNd+Dt/pevPwIiNzLzRV1 L6ZAaqd/3KtV/uSheaCwxfF4vTeWsmD/GWpOl2bKb56R7xjKV1akNfkXjjBj4KadCNGvjb3HL27 /n76vQx+lnlWj7K60NZjUekEJnKwBc62NkFTL2+drdDcRB/yGkbyKPAhoVzywIVhGHwMXZuxLwQ 6jVn5Tp3vtLa0hzDlspEh0wQeIo/J44TdnmVU2+MLl/ADuiW0AycL72gjklYffPSm8EEOlzRsRf 7Qp09BeKs2WRGBviFjmuiVamN6+3Pmek3hrZSBGux2zLER3k2yrpoRfAaUVOyPTGv/I/ZZa+aK2 AG5WGpqox9CHEKQ== X-Developer-Key: i=rbm@suse.com; a=openpgp; fpr=030A8E9E424EE3C0655787E1C90B8A7C638658A6 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.1 X-Spam-Checker-Version: SpamAssassin 4.0.1 (2024-03-25) on in-6.smtp.seeweb.it X-Virus-Scanned: clamav-milter 1.0.7 at in-6.smtp.seeweb.it X-Virus-Status: Clean Subject: [LTP] [PATCH v4 5/8] syscalls/mknod05: Convert to new API 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: , X-Patchwork-Original-From: =?utf-8?q?Ricardo_B=2E_Marli=C3=A8re_via_ltp?= From: =?utf-8?q?Ricardo_B=2E_Marli=C3=A8re?= Reply-To: =?utf-8?q?Ricardo_B=2E_Marli=C3=A8re?= Cc: =?utf-8?q?Ricardo_B=2E_Marli=C3=A8re?= Errors-To: ltp-bounces+incoming=patchwork.ozlabs.org@lists.linux.it Sender: "ltp" From: Ricardo B. Marlière Reviewed-by: Cyril Hrubis Signed-off-by: Ricardo B. Marlière --- testcases/kernel/syscalls/mknod/mknod05.c | 285 ++++-------------------------- 1 file changed, 38 insertions(+), 247 deletions(-) diff --git a/testcases/kernel/syscalls/mknod/mknod05.c b/testcases/kernel/syscalls/mknod/mknod05.c index fbc5575403665803beb7f34b1da155e2224b4f20..4b7e9577266eb8b2da63b0341e0da723b92ee653 100644 --- a/testcases/kernel/syscalls/mknod/mknod05.c +++ b/testcases/kernel/syscalls/mknod/mknod05.c @@ -1,268 +1,59 @@ +// SPDX-License-Identifier: GPL-2.0-or-later /* - * - * Copyright (c) International Business Machines Corp., 2001 - * - * This program is free software; you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation; either version 2 of the License, or - * (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See - * the GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program; if not, write to the Free Software - * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA + * Copyright (c) International Business Machines Corp., 2001 + * 07/2001 Ported by Wayne Boyer + * Copyright (c) 2025 SUSE LLC Ricardo B. Marlière */ -/* - * Test Name: mknod05 - * - * Test Description: - * Verify that mknod(2) succeeds when used by root to create a filesystem - * node with set group-ID bit set on a directory with set group-ID bit set. - * The node created should have set group-ID bit set and its gid should be - * equal to that of its parent directory. - * - * Expected Result: - * mknod() should return value 0 on success and node created should have - * set group-ID bit set and its gid should be equal to that of its parent - * directory. - * - * Algorithm: - * Setup: - * Setup signal handling. - * Create temporary directory. - * Pause for SIGUSR1 if option specified. - * - * Test: - * Loop if the proper options are given. - * Execute system call - * Check return code, if system call failed (return=-1) - * Log the errno and Issue a FAIL message. - * Otherwise, - * Verify the Functionality of system call - * if successful, - * Issue Functionality-Pass message. - * Otherwise, - * Issue Functionality-Fail message. - * Cleanup: - * Print errno log and/or timing stats if options given - * Delete the temporary directory created. - * - * Usage: - * mknod05 [-c n] [-f] [-i n] [-I x] [-P x] [-t] - * where, -c n : Run n copies concurrently. - * -f : Turn off functionality Testing. - * -i n : Execute test n times. - * -I x : Execute test for x seconds. - * -P x : Pause for x seconds between iterations. - * -t : Turn on syscall timing. - * - * HISTORY - * 07/2001 Ported by Wayne Boyer - * - * RESTRICTIONS: - * This test should be run by 'super-user' (root) only. - * +/*\ + * Verify that mknod(2) succeeds when used to create a filesystem node with + * set group-ID bit set on a directory with set group-ID bit set. The node + * created should have set group-ID bit set and its gid should be equal to + * that of its parent directory. */ -#include -#include -#include -#include -#include -#include #include -#include -#include - -#include "test.h" -#include "safe_macros.h" - -#define LTPUSER "nobody" -#define MODE_RWX S_IFIFO | S_IRWXU | S_IRWXG | S_IRWXO -#define MODE_SGID S_IFIFO | S_ISGID | S_IRWXU | S_IRWXG | S_IRWXO -#define DIR_TEMP "testdir_5" -#define TNODE "tnode_%d" +#include "tst_uid.h" +#include "tst_test.h" -struct stat buf; /* struct. to hold stat(2) o/p contents */ -struct passwd *user1; /* struct. to hold getpwnam(3) o/p contents */ +#define MODE_RWX 0777 +#define MODE_SGID (S_ISGID | 0777) -char *TCID = "mknod05"; -int TST_TOTAL = 1; -char node_name[PATH_MAX]; /* buffer to hold node name created */ +#define TEMP_DIR "testdir" +#define TEMP_NODE TEMP_DIR "/testnode" -gid_t group1_gid, group2_gid, mygid; /* user and process group id's */ -uid_t save_myuid, user1_uid; /* user and process user id's */ -pid_t mypid; /* process id */ +static uid_t nobody_uid; +static gid_t nobody_gid, free_gid; -void setup(); /* setup function for the test */ -void cleanup(); /* cleanup function for the test */ - -int main(int ac, char **av) +static void run(void) { - int lc; - int fflag; - - tst_parse_opts(ac, av, NULL, NULL); - - setup(); - - for (lc = 0; TEST_LOOPING(lc); lc++) { + struct stat buf; - tst_count = 0; + SAFE_MKNOD(TEMP_NODE, MODE_SGID, 0); - /* - * Attempt to create a filesystem node with group id (sgid) - * bit set on a directory with group id (sgid) bit set - * such that, the node created by mknod(2) should have - * group id (sgid) bit set and node's gid should be equal - * to that of effective gid of the process. - */ - TEST(mknod(node_name, MODE_SGID, 0)); + SAFE_STAT(TEMP_NODE, &buf); + TST_EXP_EQ_LI(buf.st_mode & S_ISGID, S_ISGID); + TST_EXP_EQ_LI(buf.st_gid, free_gid); - /* Check return code from mknod(2) */ - if (TEST_RETURN == -1) { - tst_resm(TFAIL, "mknod(%s, %#o, 0) failed, errno=%d : " - "%s", node_name, MODE_SGID, TEST_ERRNO, - strerror(TEST_ERRNO)); - continue; - } - /* Set the functionality flag */ - fflag = 1; - - /* Check for node's creation */ - if (stat(node_name, &buf) < 0) { - tst_resm(TFAIL, "stat() of %s failed, errno:%d", - node_name, TEST_ERRNO); - /* unset functionality flag */ - fflag = 0; - } - - /* Verify mode permissions of node */ - if (!(buf.st_mode & S_ISGID)) { - tst_resm(TFAIL, "%s: Incorrect modes, " - "setgid bit not set", node_name); - /* unset flag as functionality fails */ - fflag = 0; - } - - /* Verify group ID */ - if (buf.st_gid != group2_gid) { - tst_resm(TFAIL, "%s: Incorrect group", - node_name); - /* unset flag as functionality fails */ - fflag = 0; - } - if (fflag) { - tst_resm(TPASS, "Functionality of mknod(%s, " - "%#o, 0) successful", - node_name, MODE_SGID); - } - - /* Remove the node for the next go `round */ - if (unlink(node_name) == -1) { - tst_resm(TWARN, "unlink(%s) failed, errno:%d %s", - node_name, errno, strerror(errno)); - } - } - - /* change the directory back to temporary directory */ - SAFE_CHDIR(cleanup, ".."); - - /* - * Invoke cleanup() to delete the test directories created - * in the setup() and exit main(). - */ - cleanup(); - - tst_exit(); + SAFE_UNLINK(TEMP_NODE); } -/* - * setup(void) - performs all ONE TIME setup for this test. - * Exit the test program on receipt of unexpected signals. - * Create a temporary directory used to hold test directories created - * and change the directory to it. - * Verify that pid of process executing the test is root. - * Create a test directory on temporary directory and set the ownership - * of test directory to guest user and process, change mode permissions - * to set group id bit on it. - */ -void setup(void) +static void setup(void) { - tst_require_root(); - - /* Capture unexpected signals */ - tst_sig(NOFORK, DEF_HANDLER, cleanup); - - TEST_PAUSE; - - /* Make a temp dir and cd to it */ - tst_tmpdir(); - - /* Save the real user id of the current test process */ - save_myuid = getuid(); - - /* Save the process id of the current test process */ - mypid = getpid(); - - /* Get the node name to be created in the test */ - sprintf(node_name, TNODE, mypid); - - /* Get the uid/gid of ltp user */ - if ((user1 = getpwnam(LTPUSER)) == NULL) { - tst_brkm(TBROK, cleanup, "%s not in /etc/passwd", LTPUSER); - } - user1_uid = user1->pw_uid; - group1_gid = user1->pw_gid; - - /* Get the effective group id of the test process */ - group2_gid = getegid(); + struct passwd *ltpuser = SAFE_GETPWNAM("nobody"); - /* - * Create a test directory under temporary directory with the - * specified mode permissions, with uid/gid set to that of guest - * user and the test process. - */ - SAFE_MKDIR(cleanup, DIR_TEMP, MODE_RWX); - SAFE_CHOWN(cleanup, DIR_TEMP, user1_uid, group2_gid); - SAFE_CHMOD(cleanup, DIR_TEMP, MODE_SGID); + nobody_uid = ltpuser->pw_uid; + nobody_gid = ltpuser->pw_gid; + free_gid = tst_get_free_gid(nobody_gid); - /* - * Verify that test directory created with expected permission modes - * and ownerships. - */ - SAFE_STAT(cleanup, DIR_TEMP, &buf); - /* Verify modes of test directory */ - if (!(buf.st_mode & S_ISGID)) { - tst_brkm(TBROK, cleanup, - "%s: Incorrect modes, setgid bit not set", DIR_TEMP); - } - - /* Verify group ID of test directory */ - if (buf.st_gid != group2_gid) { - tst_brkm(TBROK, cleanup, "%s: Incorrect group", DIR_TEMP); - } - - /* Change directory to DIR_TEMP */ - SAFE_CHDIR(cleanup, DIR_TEMP); + SAFE_MKDIR(TEMP_DIR, MODE_RWX); + SAFE_CHOWN(TEMP_DIR, nobody_uid, free_gid); + SAFE_CHMOD(TEMP_DIR, MODE_SGID); } -/* - * cleanup() - Performs all ONE TIME cleanup for this test at - * completion or premature exit. - * Print test timing stats and errno log if test executed with options. - * Remove temporary directory and sub-directories/files under it - * created during setup(). - * Exit the test program with normal exit code. - */ -void cleanup(void) -{ - - tst_rmdir(); - -} +static struct tst_test test = { + .setup = setup, + .test_all = run, + .needs_root = 1, + .needs_tmpdir = 1, +}; From patchwork Fri Apr 25 18:06:06 2025 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: =?utf-8?q?Ricardo_B=2E_Marli=C3=A8re?= X-Patchwork-Id: 2077449 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@legolas.ozlabs.org Authentication-Results: legolas.ozlabs.org; dkim=pass (1024-bit key; unprotected) header.d=lists.linux.it header.i=@lists.linux.it header.a=rsa-sha256 header.s=picard header.b=MEDJKTII; dkim=fail reason="signature verification failed" (2048-bit key; unprotected) header.d=suse.com header.i=@suse.com header.a=rsa-sha256 header.s=google header.b=PVJjhrxe; dkim-atps=neutral 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=patchwork.ozlabs.org) 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 (secp384r1)) (No client certificate requested) by legolas.ozlabs.org (Postfix) with ESMTPS id 4Zkgnh2Xh1z1yMm for ; Sat, 26 Apr 2025 04:08:40 +1000 (AEST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=lists.linux.it; i=@lists.linux.it; q=dns/txt; s=picard; t=1745604535; h=date : mime-version : message-id : references : in-reply-to : to : subject : list-id : list-unsubscribe : list-archive : list-post : list-help : list-subscribe : from : reply-to : cc : content-type : content-transfer-encoding : sender : from; bh=67NbvU8tCWY45JMX0xktBvi9Ns5EXoDtc74Zr0jxlZM=; b=MEDJKTIIa8TlJ4i65PkFaegdbrW6wTkwBU7IF8/TfeOygXcIoX+FSEsTTQ4lVUzcdancK cnLhApWLK6zeMSYAMTkipoDRZp2gKCYfQJtAAUtkVugO4vbnV5rhi91iY5AcWLZt2AXHvmS eNRKgYfk3HTFrXQzxRSmogopOLjxY20= Received: from picard.linux.it (localhost [IPv6:::1]) by picard.linux.it (Postfix) with ESMTP id B7DCC3CBA5F for ; Fri, 25 Apr 2025 20:08:55 +0200 (CEST) X-Original-To: ltp@lists.linux.it Delivered-To: ltp@picard.linux.it Received: from in-7.smtp.seeweb.it (in-7.smtp.seeweb.it [217.194.8.7]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (secp384r1)) (No client certificate requested) by picard.linux.it (Postfix) with ESMTPS id 7FF603CBA5F for ; Fri, 25 Apr 2025 20:06:29 +0200 (CEST) Received: from mail-wm1-x329.google.com (mail-wm1-x329.google.com [IPv6:2a00:1450:4864:20::329]) (using TLSv1.3 with cipher TLS_AES_128_GCM_SHA256 (128/128 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits) server-digest SHA256) (No client certificate requested) by in-7.smtp.seeweb.it (Postfix) with ESMTPS id AC47C2009FF for ; Fri, 25 Apr 2025 20:06:28 +0200 (CEST) Received: by mail-wm1-x329.google.com with SMTP id 5b1f17b1804b1-43cf06eabdaso23555125e9.2 for ; Fri, 25 Apr 2025 11:06:28 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=suse.com; s=google; t=1745604388; x=1746209188; darn=lists.linux.it; h=cc:to:in-reply-to:references:message-id:content-transfer-encoding :mime-version:subject:date:from:from:to:cc:subject:date:message-id :reply-to; bh=DGxcWtu0aUWRoUiKGcP+HFl/UIbQrkRu35BhnDRnf5M=; b=PVJjhrxeEqbRAvtojLf8yQcvPXXJhP/6MfS+CCzCx9kp1NY0WmaF8gGqVmh66ONhOI tMUeGfWUq4/B2ROJqqT0FRZGRYemYtCd37dbBfZSV04dno125oEoVq3eZPOKGgEK2Hz6 KSnff7qOUUYVqMtvZz3xh/KCC3w1S1dNdv7I7LdxN9QgileS46qmKjU/E6Lbt5fQf4Qk QT7NZHwzTiECvrOeIM9GtNRdkRWui5NiQTT54/DmuHUwWulbaDjd8ZnlNCaUlxt8pOm0 9EGHG3X0PiEnVvZpIw2F3t7CNz3nBG1ziVYKTmrFUH1svUIeWK3c8vA/RnjUmIXUQULf smog== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1745604388; x=1746209188; h=cc:to:in-reply-to:references:message-id:content-transfer-encoding :mime-version:subject:date:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=DGxcWtu0aUWRoUiKGcP+HFl/UIbQrkRu35BhnDRnf5M=; b=kg4eCXkyc0kIBbcfgyk55xsr1QvO0sOAougnzBWk0EcyMI+NNBNPtfW/dII0qsS3X6 FlyCHG7dceVq8OVuv964zCII6TfvDaJPPDjoRR1XRworS4s4bvN4RVW1IQk2Tj5DJj3p ud//OZUSU2FxVUK7di6l9x9BrlN4UshaIuWyku1p0m/AU+rGl5OmqRln8+/1xKhtdyM5 1eaCSQcs+2SojC6cUrfH4zCowNyHDJScziTlgcb6iNyMXX1meCIkogyYi3J4EkA9U8y3 bSLQax4WnDfE9K5JzAdLRL+OH8hGYKPhcYPnlvfaiC/2XuriWBvUXwpf4QdR5kiThz/s fz5Q== X-Gm-Message-State: AOJu0YzcwMmH4UYeLpx619PsFYUk5x8uwJWv7e8KhR+O394m6IWh0MwQ wNtETSdLp4xMIiIivTeBhwktDyQMXWcUhMrDL8ReDgN6BtGB33wNVw8UQn6uz28WTmZCwcpbuLh V X-Gm-Gg: ASbGncvT8s/JXkajq6qhP/FkXRiKzI/iV7OStzNWOMSyIpEWzMRuZqW0Qjk/hmwEYTb RbnhEcXIZ6A3zSKWVgbjg8w2BGBLc54DBqUVyGQR4Fdz0FjIySxdxigxBeUxld1U0dxX+oeSk3R Of5PrqMbSy8RVWR1+rxK5yQXy4BHbSNZ3QhT9ttBgxHBgYcXyi7w4tXqSv5+c2/QVyKKJG3C8cO w16FOn5V1RygXbXFkyuw9KRHoExhXFC8PqFkcOSKEw5q5kIvz7Go/PO9A5NPCkMA5KvZR3lzX14 Rk+t6OrZoDAsUiWkiOXfX5L6ivahxw== X-Google-Smtp-Source: AGHT+IFbYq3/nN3WmH5exn2Gaj5ROI4Lv4ktZSCSSC5B+dGpJH20HndYFIAwPUuPh34RB/bCpYTVEg== X-Received: by 2002:a05:6000:1844:b0:391:158f:3d59 with SMTP id ffacd0b85a97d-3a07aa69788mr252468f8f.15.1745604387697; Fri, 25 Apr 2025 11:06:27 -0700 (PDT) Received: from localhost ([179.228.213.210]) by smtp.gmail.com with UTF8SMTPSA id d9443c01a7336-22db5216ba5sm35619805ad.222.2025.04.25.11.06.26 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 25 Apr 2025 11:06:27 -0700 (PDT) Date: Fri, 25 Apr 2025 15:06:06 -0300 MIME-Version: 1.0 Message-Id: <20250425-conversions-mknod-v4-6-222e0d2e7ef1@suse.com> References: <20250425-conversions-mknod-v4-0-222e0d2e7ef1@suse.com> In-Reply-To: <20250425-conversions-mknod-v4-0-222e0d2e7ef1@suse.com> To: Linux Test Project X-Mailer: b4 0.14.2 X-Developer-Signature: v=1; a=openpgp-sha256; l=10637; i=rbm@suse.com; h=from:subject:message-id; bh=ULHfgCZ5YvLrrkHG7IAgm6Hc55y/3R8AGgAXLT1kLp8=; b=owEBbQKS/ZANAwAIAckLinxjhlimAcsmYgBoC88NsDxGZ6tAfZ3hqkGQcmGQx/sHL19O3cueT AUrDTTpHs2JAjMEAAEIAB0WIQQDCo6eQk7jwGVXh+HJC4p8Y4ZYpgUCaAvPDQAKCRDJC4p8Y4ZY ph7yD/9362hUiTEWBHQ02oa1+NbyvSsfwh4xxYunt6i9z/ILv0Rw9bLXGwpQvyYMRYYVC1z6wDX 9H0varoUMKArWLVsbztYzQeekP8tmfghlbONnkVpkT9qtTZ/EB14d8iUV8hHsb+ThsI9Init9ZB SGptJWGaNLzW5sCuCmxF//qvshKv/qg4XJjDZ2XYmQJqoeRRUwR147L9A+XkfdO1jlt1ZYzlFEf /dCiivFEc6pkmrHe2ERLCZ4/Diw8sKAGPetbJZr0833+jtZO7EU5Sc89kRe2X57B90GBTel+4a1 d10tWkgyy+wzPtDx4SzzCDshBU7R58RlWY2VdDQcUBWnUuWDuLWzM3Ya5oVrZdT7Y33Cdl1hzGi P8UPlnvDkppB9FUHRB2uYd0kKUpyf7m3tmv0wrIAFBZrk+OC1j2mdpzLVjWoGKxqDN6XIAYQ1tJ vxYpYVSMAUQjg/jv3NQ/GGYKV4vBVPwmYlxa/BLZQ63FrEr3Fu9IeW0fWLiHJ/s0vfqjl15WXMn ohdqTfmP4FlzY8IDFtuajB9wsLCMDWUXNLTZt6EavgthuUBO3Rkbu2uxrmnqbrMZFDoeenb39xA syUQlG47nCJ1zlOpxpAZpBkxzhsM/iZgAaPrw6qfZRkwwVqeTEs34yIxE99QowqyvaiZM+2P23+ mI44hJGdIFt67jg== X-Developer-Key: i=rbm@suse.com; a=openpgp; fpr=030A8E9E424EE3C0655787E1C90B8A7C638658A6 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.1 X-Spam-Checker-Version: SpamAssassin 4.0.1 (2024-03-25) on in-7.smtp.seeweb.it X-Virus-Scanned: clamav-milter 1.0.7 at in-7.smtp.seeweb.it X-Virus-Status: Clean Subject: [LTP] [PATCH v4 6/8] syscalls/mknod06: Convert to new API 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: , X-Patchwork-Original-From: =?utf-8?q?Ricardo_B=2E_Marli=C3=A8re_via_ltp?= From: =?utf-8?q?Ricardo_B=2E_Marli=C3=A8re?= Reply-To: =?utf-8?q?Ricardo_B=2E_Marli=C3=A8re?= Cc: =?utf-8?q?Ricardo_B=2E_Marli=C3=A8re?= Errors-To: ltp-bounces+incoming=patchwork.ozlabs.org@lists.linux.it Sender: "ltp" From: Ricardo B. Marlière Signed-off-by: Ricardo B. Marlière --- testcases/kernel/syscalls/mknod/mknod06.c | 301 +++++------------------------- 1 file changed, 43 insertions(+), 258 deletions(-) diff --git a/testcases/kernel/syscalls/mknod/mknod06.c b/testcases/kernel/syscalls/mknod/mknod06.c index 8f70cf07a260a4709242e67a8c3df983936eb63e..a7b16111dbbc1a0085308c41ab78882ecd830f5a 100644 --- a/testcases/kernel/syscalls/mknod/mknod06.c +++ b/testcases/kernel/syscalls/mknod/mknod06.c @@ -1,280 +1,65 @@ +// SPDX-License-Identifier: GPL-2.0-or-later /* - * - * Copyright (c) International Business Machines Corp., 2001 - * - * This program is free software; you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation; either version 2 of the License, or - * (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See - * the GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program; if not, write to the Free Software - * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA + * Copyright (c) International Business Machines Corp., 2001 + * 07/2001 Ported by Wayne Boyer + * Copyright (c) 2025 SUSE LLC Ricardo B. Marlière */ -/* - * Test Name: mknod06 - * - * Test Description: - * Verify that, - * 1) mknod(2) returns -1 and sets errno to EEXIST if specified path - * already exists. - * 2) mknod(2) returns -1 and sets errno to EFAULT if pathname points - * outside user's accessible address space. - * 3) mknod(2) returns -1 and sets errno to ENOENT if the directory - * component in pathname does not exist. - * 4) mknod(2) returns -1 and sets errno to ENAMETOOLONG if the pathname - * component was too long. - * 5) mknod(2) returns -1 and sets errno to ENOTDIR if the directory - * component in pathname is not a directory. - * - * Expected Result: - * mknod() should fail with return value -1 and set expected errno. +/*\ + * Verify that mknod(2) fails with the correct error codes: * - * Algorithm: - * Setup: - * Setup signal handling. - * Create temporary directory. - * Pause for SIGUSR1 if option specified. - * - * Test: - * Loop if the proper options are given. - * Execute system call - * Check return code, if system call failed (return=-1) - * if errno set == expected errno - * Issue sys call fails with expected return value and errno. - * Otherwise, - * Issue sys call fails with unexpected errno. - * Otherwise, - * Issue sys call returns unexpected value. - * - * Cleanup: - * Print errno log and/or timing stats if options given - * Delete the temporary directory(s)/file(s) created. - * - * Usage: - * mknod06 [-c n] [-e] [-i n] [-I x] [-P x] [-t] - * where, -c n : Run n copies concurrently. - * -e : Turn on errno logging. - * -i n : Execute test n times. - * -I x : Execute test for x seconds. - * -P x : Pause for x seconds between iterations. - * -t : Turn on syscall timing. - * - * HISTORY - * 07/2001 Ported by Wayne Boyer - * - * RESTRICTIONS: - * This test should be executed by super-user (root) only. + * - ENAMETOOLONG if the pathname component was too long. + * - EEXIST if specified path already exists. + * - EFAULT if pathname points outside user's accessible address space. + * - ENOENT if the directory component in pathname does not exist. + * - ENOENT if the pathname is empty. + * - ENOTDIR if the directory component in pathname is not a directory. */ -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include +#include "tst_test.h" -#include "test.h" +#define MODE_FIFO_RWX (S_IFIFO | 0777) -#define MODE_RWX S_IFIFO | S_IRWXU | S_IRWXG | S_IRWXO +static char *longpathname; -int setup1(); /* setup function to test mknod for EEXIST */ -int setup3(); /* setup function to test mknod for ENOTDIR */ -int longpath_setup(); /* setup function to test mknod for ENAMETOOLONG */ -int no_setup(); /* simply returns 0 to the caller */ -char Longpathname[PATH_MAX + 2]; - -struct test_case_t { /* test case struct. to hold ref. test cond's */ +static struct tcase { char *pathname; char *desc; int exp_errno; - int (*setupfunc) (); -} Test_cases[] = { - {"tnode_1", "Specified node already exists", EEXIST, setup1}, { - NULL, "Invalid address", EFAULT, no_setup}, { - "testdir_2/tnode_2", "Non-existent file", ENOENT, no_setup}, { - "", "Pathname is empty", ENOENT, no_setup}, { - Longpathname, "Pathname too long", ENAMETOOLONG, longpath_setup}, { - "tnode/tnode_3", "Path contains regular file", ENOTDIR, setup3}, { - NULL, NULL, 0, no_setup} +} tcases[] = { + { NULL, "Pathname too long", ENAMETOOLONG }, + { "tnode_1", "Specified node already exists", EEXIST }, + { NULL, "Invalid address", EFAULT }, + { "testdir_2/tnode_2", "Non-existent file", ENOENT }, + { "", "Pathname is empty", ENOENT }, + { "tnode/tnode_3", "Path contains regular file", ENOTDIR }, }; -char *TCID = "mknod06"; -int TST_TOTAL = ARRAY_SIZE(Test_cases); - -void setup(); /* setup function for the tests */ -void cleanup(); /* cleanup function for the tests */ - -int main(int ac, char **av) +static void run(unsigned int i) { - int lc; - char *node_name; /* ptr. for node name created */ - char *test_desc; /* test specific error message */ - int ind; /* counter to test different test conditions */ - - tst_parse_opts(ac, av, NULL, NULL); - - /* - * Invoke setup function to call individual test setup functions - * for the test which run as root/super-user. - */ - setup(); - - for (lc = 0; TEST_LOOPING(lc); lc++) { - - tst_count = 0; - - for (ind = 0; Test_cases[ind].desc != NULL; ind++) { - node_name = Test_cases[ind].pathname; - test_desc = Test_cases[ind].desc; - - /* - * Call mknod(2) to test different test conditions. - * verify that it fails with -1 return value and - * sets appropriate errno. - */ - TEST(mknod(node_name, MODE_RWX, 0)); - - /* Check return code from mknod(2) */ - if (TEST_RETURN != -1) { - tst_resm(TFAIL, - "mknod() returned %ld, expected " - "-1, errno:%d", TEST_RETURN, - Test_cases[ind].exp_errno); - continue; - } + struct tcase *tc = &tcases[i]; - if (TEST_ERRNO == Test_cases[ind].exp_errno) { - tst_resm(TPASS, "mknod() fails, %s, errno:%d", - test_desc, TEST_ERRNO); - } else { - tst_resm(TFAIL, "mknod() fails, %s, errno:%d, " - "expected errno:%d", test_desc, - TEST_ERRNO, Test_cases[ind].exp_errno); - } - } - - } - - /* - * Invoke cleanup() to delete the test directories created - * in the setup(). - */ - cleanup(); - - tst_exit(); + TST_EXP_FAIL(mknod(tc->pathname, MODE_FIFO_RWX, 0), tc->exp_errno, "%s", + tc->desc); } -/* - * setup(void) - performs all ONE TIME setup for this test. - * Exit the test program on receipt of unexpected signals. - * Create a temporary directory used to hold test directories and nodes - * created and change the directory to it. - * Invoke individual test setup functions according to the order - * set in struct. definition. - */ -void setup(void) +static void setup(void) { - int ind; - - tst_require_root(); - - /* Capture unexpected signals */ - tst_sig(NOFORK, DEF_HANDLER, cleanup); - - TEST_PAUSE; + SAFE_MKNOD("tnode_1", MODE_FIFO_RWX, 0); + SAFE_MKNOD("tnode", MODE_FIFO_RWX, 0); - /* Make a temp dir and cd to it */ - tst_tmpdir(); - - /* call individual setup functions */ - for (ind = 0; Test_cases[ind].desc != NULL; ind++) { - if (!Test_cases[ind].pathname) - Test_cases[ind].pathname = tst_get_bad_addr(cleanup); - Test_cases[ind].setupfunc(); - } -} - -/* - * no_setup() - Some test conditions for mknod(2) do not any setup. - * Hence, this function just returns 0. - */ -int no_setup(void) -{ - return 0; -} - -/* - * longpath_setup() - setup to create a node with a name length exceeding - * the MAX. length of PATH_MAX. - * This function retruns 0. - */ -int longpath_setup(void) -{ - int ind; /* counter variable */ - - for (ind = 0; ind <= (PATH_MAX + 1); ind++) { - Longpathname[ind] = 'a'; - } - return 0; + for (int i = 0; i <= (PATH_MAX + 1); i++) + longpathname[i] = 'a'; + tcases[0].pathname = longpathname; } -/* - * setup1() - setup function for a test condition for which mknod(2) - * returns -1 and sets errno to EEXIST. - * This function creates a node using mknod(2) and tries to create - * same node in the test and fails with above errno. - * This function returns 0. - */ -int setup1(void) -{ - /* Create a node using mknod */ - if (mknod("tnode_1", MODE_RWX, 0) < 0) { - tst_brkm(TBROK, cleanup, "Fails to create node in setup1()"); - } - - return 0; -} - -/* - * setup3() - setup function for a test condition for which mknod(2) - * returns -1 and sets errno to ENOTDIR. - * This function creates a node under temporary directory and the - * test attempts to create another node under under this node and fails - * with ENOTDIR as the node created here is a regular file. - * This function returns 0. - */ -int setup3(void) -{ - /* Create a node using mknod */ - if (mknod("tnode", MODE_RWX, 0) < 0) { - tst_brkm(TBROK, cleanup, "Fails to create node in setup3()"); - } - - return 0; -} - -/* - * cleanup() - Performs all ONE TIME cleanup for this test at - * completion or premature exit. - * Print test timing stats and errno log if test executed with options. - * Remove temporary directory and sub-directories/files under it - * created during setup(). - * Exit the test program with normal exit code. - */ -void cleanup(void) -{ - - tst_rmdir(); - -} +static struct tst_test test = { + .setup = setup, + .test = run, + .tcnt = ARRAY_SIZE(tcases), + .needs_tmpdir = 1, + .bufs = (struct tst_buffers[]) { + { &longpathname, .size = PATH_MAX + 2 }, + {}, + }, +}; From patchwork Fri Apr 25 18:06:07 2025 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: =?utf-8?q?Ricardo_B=2E_Marli=C3=A8re?= X-Patchwork-Id: 2077450 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@legolas.ozlabs.org Authentication-Results: legolas.ozlabs.org; dkim=pass (1024-bit key; unprotected) header.d=lists.linux.it header.i=@lists.linux.it header.a=rsa-sha256 header.s=picard header.b=bfGlv0co; dkim=fail reason="signature verification failed" (2048-bit key; unprotected) header.d=suse.com header.i=@suse.com header.a=rsa-sha256 header.s=google header.b=VAfeyl5g; dkim-atps=neutral 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=patchwork.ozlabs.org) 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 (secp384r1)) (No client certificate requested) by legolas.ozlabs.org (Postfix) with ESMTPS id 4Zkgp802bXz1yMm for ; Sat, 26 Apr 2025 04:09:04 +1000 (AEST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=lists.linux.it; i=@lists.linux.it; q=dns/txt; s=picard; t=1745604558; h=date : mime-version : message-id : references : in-reply-to : to : subject : list-id : list-unsubscribe : list-archive : list-post : list-help : list-subscribe : from : reply-to : cc : content-type : content-transfer-encoding : sender : from; bh=1epQLxhKBOrP57Fw1rNp3BjxYS5ehc13f0DWUC9VmyE=; b=bfGlv0co3FOecoPNvebRaJ6HCb2xk+olHqYpJMSa182Ow21yUphuSkrhsLaSkOSyX248f l4FngAfyROV3+mxnaxeMkdROlathABCoZCPaq7CD/Y7nz0SeFYJM86Sk5sTFxc1856oEj9+ V5d9QZvgjUlvsYqAS/75JhiaZEtW01k= Received: from picard.linux.it (localhost [IPv6:::1]) by picard.linux.it (Postfix) with ESMTP id E50A53CBAB9 for ; Fri, 25 Apr 2025 20:09:18 +0200 (CEST) X-Original-To: ltp@lists.linux.it Delivered-To: ltp@picard.linux.it Received: from in-7.smtp.seeweb.it (in-7.smtp.seeweb.it [IPv6:2001:4b78:1:20::7]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (secp384r1) server-digest SHA384) (No client certificate requested) by picard.linux.it (Postfix) with ESMTPS id C36113CBA8D for ; Fri, 25 Apr 2025 20:06:33 +0200 (CEST) Received: from mail-wr1-x433.google.com (mail-wr1-x433.google.com [IPv6:2a00:1450:4864:20::433]) (using TLSv1.3 with cipher TLS_AES_128_GCM_SHA256 (128/128 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits) server-digest SHA256) (No client certificate requested) by in-7.smtp.seeweb.it (Postfix) with ESMTPS id 65B42200A04 for ; Fri, 25 Apr 2025 20:06:32 +0200 (CEST) Received: by mail-wr1-x433.google.com with SMTP id ffacd0b85a97d-39ac8e7688aso1579569f8f.2 for ; Fri, 25 Apr 2025 11:06:32 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=suse.com; s=google; t=1745604391; x=1746209191; darn=lists.linux.it; h=cc:to:in-reply-to:references:message-id:content-transfer-encoding :mime-version:subject:date:from:from:to:cc:subject:date:message-id :reply-to; bh=GiDEk8HEsUMIpF2GRsgZ2yBWGZSQpNZoY2vme4O528A=; b=VAfeyl5g0nGGzZRYniCdJDTTYFNLh6GoIc74O+Fw/gXNoURyKGDJENI100atvxOutA 0yAEu/oyo5hhL91Z+EqBHDel1o3kwilTtqvlbft+7YN0GSTx/HOJ3aqlz9ln4x6Y17VY fIkDqAsdhxTWyA8kXeO5KBSs24Xoro/OsbHsnRYMDuf6KFaJ6yVFuLv9ulfZw/hiMS4Q 0HhAEHellN2lQgnziqKI4RX+0iLC9XzLi7/sUUhaQadtuufbtqBJbkQAt3Ryc3HAqNLQ 9MsuKFlfI4p5cb/1WAkZmr5tmc6Jaa2IL8ZMRD6vbzEvw0mKlS83O771p5lsiw6haHp4 hIjQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1745604391; x=1746209191; h=cc:to:in-reply-to:references:message-id:content-transfer-encoding :mime-version:subject:date:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=GiDEk8HEsUMIpF2GRsgZ2yBWGZSQpNZoY2vme4O528A=; b=pVSpIgMF+w/vsh3+2865purUvh4uB5ZA8Z3W1DiD5IVFUfWpYYkz84+sNCqglJZ5ls LaTfTC4k5N7OUolyxBLYsY5Y8LR4YBDKAzL0j4GuEifLSsfOolGXcOu/nEG3w4KyFaq3 r3qzNSXzPf60oqqTezgb99kM13SXYYxjJcgN4cGRLJsEotveePqD5wt6CMf3UDqQi1vt 9gfEH9Q4D3sCT1b2ViDsaiwnqyW6kOOZojUGo1Ps2M3HT5VKfVjdCL+IOuaCpj0mT5wu WpQVwpKFRwr9bc8gk1fhlkqft0oloZatoN9aw8RZLiiZrNlo5w0mKlcPLZTuohiXTQ2f t4xQ== X-Gm-Message-State: AOJu0Yx/ElD7PySAydIHNSps97Uh48zM+rd8fnL1Z84fdRbMGtcOqCwX AKNUjAcZwxbpzaN5yx0vJOmD88GKErnjdIjh0DwTb3IsJbN46YCtQkoVmOx909E09BjGjgo9+yd V X-Gm-Gg: ASbGnctYikHOlx9wdbZlKff2jIfMGkXaMAx1GyDJBXGsJ44dZdp6XPVLu3YnCTUr/fx KpoH+QOBb8ZfB2oVnszCvyiyG8yJHQ+Y+Jw4G6zNJ+Kw4/nk0DqjFvixOxSfzYjzxXqyQu6uaCn 0RwRXTGP7dKyRCc8y/COnmYswCrRaBBVHvAzHDInA3ac06RzNjlJkXZAhmucbKTV6H0pRrt8ueA EC/QbQ/LUVl1gn6KysPFE9fDb7l/mQ+W4OC+Iqwwuk75cs0bIN17NVMj/R3KZ/bfX1mtXGm2VwE AsHYSg/sUnZQxy6aTnm5r6v6e+YnDw== X-Google-Smtp-Source: AGHT+IFVWcxM/ttktqHMNdAWESNhgKW1mrabg+4cEMoQ0QfRbLxCuP3+yS7YCjc5UZoSM2Qefzi4JA== X-Received: by 2002:a5d:64e7:0:b0:391:4389:f36a with SMTP id ffacd0b85a97d-3a074f3a1acmr2777450f8f.48.1745604391030; Fri, 25 Apr 2025 11:06:31 -0700 (PDT) Received: from localhost ([179.228.213.210]) by smtp.gmail.com with UTF8SMTPSA id d2e1a72fcca58-73e25912c94sm3497451b3a.3.2025.04.25.11.06.30 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 25 Apr 2025 11:06:30 -0700 (PDT) Date: Fri, 25 Apr 2025 15:06:07 -0300 MIME-Version: 1.0 Message-Id: <20250425-conversions-mknod-v4-7-222e0d2e7ef1@suse.com> References: <20250425-conversions-mknod-v4-0-222e0d2e7ef1@suse.com> In-Reply-To: <20250425-conversions-mknod-v4-0-222e0d2e7ef1@suse.com> To: Linux Test Project X-Mailer: b4 0.14.2 X-Developer-Signature: v=1; a=openpgp-sha256; l=7941; i=rbm@suse.com; h=from:subject:message-id; bh=JOMHKWMIKded5YqXdRVNWuMfiKjJjVilUFg8x3GmCZI=; b=owEBbQKS/ZANAwAIAckLinxjhlimAcsmYgBoC88Nsn1gE+awvqlosMb/oogZE8ijZ+SfGu3gF VHSV64rb2qJAjMEAAEIAB0WIQQDCo6eQk7jwGVXh+HJC4p8Y4ZYpgUCaAvPDQAKCRDJC4p8Y4ZY pgSOD/9PPv/aqlc3FS4MEeLDvMasfDUfuwQLEA0zKObaV17TNLDI4xUoMTT5cpUJ6kMSbDycpgn WY2bckRCq+AdKBiwX9xddNel3PmEAAQgZybfkU4Ilab6ym1FRA8mNgXof7F2kRHNrlF2hLgJpg8 nyahJ0+9di+HTytTUmkyj6rHLocHb5k6wFGk9RkjO7EgowxcDHQLhj/2Z/IBzoRXaoB4WSCfyly aX4Z6kEDt/YdKZLT5SylQnNSj2H7k1rOfyBrj3lWpswEasK8/OavAZNj5ecYvpBzj3/lA3T6Th/ 8XYO/R4yfwQqhP+9lTsCGxe1/0ZIWFGSi52LSOX6Ro9NmVOeh3EHesbjsw6guEhvdWS3Oj27c+j 3BnQDvdKuORZuRtnRZUx8CSQv5UiDNSIHVxucMLuG+kG2ZqzOeTrqyRym3QwP47lQWOsXSZeORH MO9a5cawohIZd6auB+pnS8v07PxQ8GdGriQ1msRNYfna0UrgDBAPqXLrxa7a9joDClKrVr1uUSS ZTCnlhNUqCbzMO6oRa/Gdxw5vJ+In/ax7fqxZljnCSxcDqxpFnuC6qJWyWrTw+adND/g1JxfdYa W5vQn54TMhlfI067AFCQ8Bgew79zUk1jw8UKTvLAjcMCMahCN1ZHACOA2j2w/uHSXLWMS1rZlQY ELh7Dk/c29eggeQ== X-Developer-Key: i=rbm@suse.com; a=openpgp; fpr=030A8E9E424EE3C0655787E1C90B8A7C638658A6 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.1 X-Spam-Checker-Version: SpamAssassin 4.0.1 (2024-03-25) on in-7.smtp.seeweb.it X-Virus-Scanned: clamav-milter 1.0.7 at in-7.smtp.seeweb.it X-Virus-Status: Clean Subject: [LTP] [PATCH v4 7/8] syscalls/mknod07: Convert to new API 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: , X-Patchwork-Original-From: =?utf-8?q?Ricardo_B=2E_Marli=C3=A8re_via_ltp?= From: =?utf-8?q?Ricardo_B=2E_Marli=C3=A8re?= Reply-To: =?utf-8?q?Ricardo_B=2E_Marli=C3=A8re?= Cc: =?utf-8?q?Ricardo_B=2E_Marli=C3=A8re?= Errors-To: ltp-bounces+incoming=patchwork.ozlabs.org@lists.linux.it Sender: "ltp" From: Ricardo B. Marlière Signed-off-by: Ricardo B. Marlière --- testcases/kernel/syscalls/mknod/mknod07.c | 209 +++++++++--------------------- 1 file changed, 59 insertions(+), 150 deletions(-) diff --git a/testcases/kernel/syscalls/mknod/mknod07.c b/testcases/kernel/syscalls/mknod/mknod07.c index 829199061532fabffb1ba2c892cc8cccfd1d4b6a..76701a346b896e823b2451a23445eda24a974e8a 100644 --- a/testcases/kernel/syscalls/mknod/mknod07.c +++ b/testcases/kernel/syscalls/mknod/mknod07.c @@ -1,184 +1,93 @@ +// SPDX-License-Identifier: GPL-2.0-or-later /* - * - * Copyright (c) International Business Machines Corp., 2001 - * 07/2001 Ported by Wayne Boyer - * - * This program is free software; you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation; either version 2 of the License, or - * (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See - * the GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program; if not, write to the Free Software Foundation, - * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA + * Copyright (c) International Business Machines Corp., 2001 + * 07/2001 Ported by Wayne Boyer + * Copyright (c) 2025 SUSE LLC Ricardo B. Marlière */ -/* - * - * Test Description: - * Verify that, - * 1) mknod(2) returns -1 and sets errno to EPERM if the process id of - * the caller is not super-user. - * 2) mknod(2) returns -1 and sets errno to EACCES if parent directory - * does not allow write permission to the process. - * 3) mknod(2) returns -1 and sets errno to EROFS if pathname refers to - * a file on a read-only file system. - * 4) mknod(2) returns -1 and sets errno to ELOOP if too many symbolic - * links were encountered in resolving pathname. +/*\ + * Verify that mknod(2) fails with the correct error codes: * + * - EACCES if parent directory does not allow write permission to the process. + * - EPERM if the process id of the caller is not super-user. + * - EROFS if pathname refers to a file on a read-only file system. + * - ELOOP if too many symbolic links were encountered in resolving pathname. */ -#include -#include -#include -#include -#include -#include #include -#include -#include -#include #include -#include "test.h" -#include "safe_macros.h" +#include "tst_test.h" -#define DIR_TEMP "testdir_1" -#define DIR_TEMP_MODE (S_IRUSR | S_IXUSR) -#define DIR_MODE (S_IRUSR|S_IWUSR|S_IXUSR|S_IRGRP| \ - S_IXGRP|S_IROTH|S_IXOTH) -#define MNT_POINT "mntpoint" +#define TEMP_MNT "mnt" +#define TEMP_DIR "testdir" +#define TEMP_DIR_MODE 0500 -#define FIFO_MODE (S_IFIFO | S_IRUSR | S_IRGRP | S_IROTH) -#define SOCKET_MODE (S_IFSOCK | S_IRWXU | S_IRWXG | S_IRWXO) -#define CHR_MODE (S_IFCHR | S_IRUSR | S_IWUSR) -#define BLK_MODE (S_IFBLK | S_IRUSR | S_IWUSR) +#define ELOOP_DIR "test_eloop" +#define ELOOP_FILE "/test_eloop" +#define ELOOP_DIR_MODE 0755 +#define ELOOP_MAX 43 -#define ELOPFILE "/test_eloop" +#define FIFO_MODE (S_IFIFO | 0444) +#define SOCKET_MODE (S_IFSOCK | 0777) +#define CHR_MODE (S_IFCHR | 0600) +#define BLK_MODE (S_IFBLK | 0600) -static char elooppathname[sizeof(ELOPFILE) * 43] = "."; +static char *elooppathname; -static const char *device; -static int mount_flag; - -static struct test_case_t { +static struct tcase { char *pathname; int mode; int exp_errno; int major, minor; -} test_cases[] = { - { "testdir_1/tnode_1", SOCKET_MODE, EACCES, 0, 0 }, - { "testdir_1/tnode_2", FIFO_MODE, EACCES, 0, 0 }, - { "tnode_3", CHR_MODE, EPERM, 1, 3 }, - { "tnode_4", BLK_MODE, EPERM, 0, 0 }, - { "mntpoint/tnode_5", SOCKET_MODE, EROFS, 0, 0 }, - { elooppathname, FIFO_MODE, ELOOP, 0, 0 }, +} tcases[] = { + { NULL, FIFO_MODE, ELOOP, 0, 0 }, + { TEMP_DIR "/tnode1", SOCKET_MODE, EACCES, 0, 0 }, + { TEMP_DIR "/tnode2", FIFO_MODE, EACCES, 0, 0 }, + { "tnode3", CHR_MODE, EPERM, 1, 3 }, + { "tnode4", BLK_MODE, EPERM, 0, 0 }, + { TEMP_MNT "/tnode5", SOCKET_MODE, EROFS, 0, 0 }, }; -char *TCID = "mknod07"; -int TST_TOTAL = ARRAY_SIZE(test_cases); - -static void setup(void); -static void mknod_verify(const struct test_case_t *test_case); -static void cleanup(void); +#define TEST_SIZE ARRAY_SIZE(tcases) -int main(int ac, char **av) +static void run(unsigned int i) { - int lc; - int i; + struct tcase *tc = &tcases[i]; - tst_parse_opts(ac, av, NULL, NULL); - - setup(); - - for (lc = 0; TEST_LOOPING(lc); lc++) { - tst_count = 0; - - for (i = 0; i < TST_TOTAL; i++) - mknod_verify(&test_cases[i]); - } - - cleanup(); - tst_exit(); + TST_EXP_FAIL(mknod(tc->pathname, tc->mode, + makedev(tc->major, tc->minor)), + tc->exp_errno); } static void setup(void) { - int i; - struct passwd *ltpuser; - const char *fs_type; - - tst_require_root(); - - tst_sig(NOFORK, DEF_HANDLER, cleanup); - - tst_tmpdir(); + struct passwd *ltpuser = SAFE_GETPWNAM("nobody"); - fs_type = tst_dev_fs_type(); - device = tst_acquire_device(cleanup); + SAFE_SETEUID(ltpuser->pw_uid); + SAFE_MKDIR(TEMP_DIR, TEMP_DIR_MODE); - if (!device) - tst_brkm(TCONF, cleanup, "Failed to acquire device"); - - tst_mkfs(cleanup, device, fs_type, NULL, NULL); - - TEST_PAUSE; - - /* mount a read-only file system for EROFS test */ - SAFE_MKDIR(cleanup, MNT_POINT, DIR_MODE); - SAFE_MOUNT(cleanup, device, MNT_POINT, fs_type, MS_RDONLY, NULL); - mount_flag = 1; - - ltpuser = SAFE_GETPWNAM(cleanup, "nobody"); - SAFE_SETEUID(cleanup, ltpuser->pw_uid); - - SAFE_MKDIR(cleanup, DIR_TEMP, DIR_TEMP_MODE); + SAFE_MKDIR(ELOOP_DIR, ELOOP_DIR_MODE); + SAFE_SYMLINK("../test_eloop", "test_eloop/test_eloop"); /* - * NOTE: the ELOOP test is written based on that the consecutive - * symlinks limits in kernel is hardwired to 40. + * The kernel limits symlink resolution hop amount to 40, + * create a pathname with more than that */ - SAFE_MKDIR(cleanup, "test_eloop", DIR_MODE); - SAFE_SYMLINK(cleanup, "../test_eloop", "test_eloop/test_eloop"); - for (i = 0; i < 43; i++) - strcat(elooppathname, ELOPFILE); -} - -static void mknod_verify(const struct test_case_t *test_case) -{ - TEST(mknod(test_case->pathname, test_case->mode, - makedev(test_case->major, test_case->minor))); - - if (TEST_RETURN != -1) { - tst_resm(TFAIL, "mknod succeeded unexpectedly"); - return; - } - - if (TEST_ERRNO == test_case->exp_errno) { - tst_resm(TPASS | TTERRNO, "mknod failed as expected"); - } else { - tst_resm(TFAIL | TTERRNO, - "mknod failed unexpectedly; expected: " - "%d - %s", test_case->exp_errno, - strerror(test_case->exp_errno)); - } + strcpy(elooppathname, "."); + for (int i = 0; i < ELOOP_MAX; i++) + strcat(elooppathname, ELOOP_FILE); + tcases[0].pathname = elooppathname; } -static void cleanup(void) -{ - if (seteuid(0) == -1) - tst_resm(TWARN | TERRNO, "seteuid(0) failed"); - - if (mount_flag && tst_umount(MNT_POINT) < 0) - tst_resm(TWARN | TERRNO, "umount device:%s failed", device); - - if (device) - tst_release_device(device); - - tst_rmdir(); -} +static struct tst_test test = { + .setup = setup, + .test = run, + .tcnt = ARRAY_SIZE(tcases), + .mntpoint = TEMP_MNT, + .needs_rofs = 1, + .bufs = (struct tst_buffers[]){ + { &elooppathname, .size = sizeof(ELOOP_FILE) * ELOOP_MAX }, + {}, + }, +}; From patchwork Fri Apr 25 18:06:08 2025 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: =?utf-8?q?Ricardo_B=2E_Marli=C3=A8re?= X-Patchwork-Id: 2077451 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@legolas.ozlabs.org Authentication-Results: legolas.ozlabs.org; dkim=pass (1024-bit key; unprotected) header.d=lists.linux.it header.i=@lists.linux.it header.a=rsa-sha256 header.s=picard header.b=c9/Zj58/; dkim=fail reason="signature verification failed" (2048-bit key; unprotected) header.d=suse.com header.i=@suse.com header.a=rsa-sha256 header.s=google header.b=MnwwEZyQ; dkim-atps=neutral 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=patchwork.ozlabs.org) 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 (secp384r1)) (No client certificate requested) by legolas.ozlabs.org (Postfix) with ESMTPS id 4Zkgpb5CWgz1yMm for ; Sat, 26 Apr 2025 04:09:27 +1000 (AEST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=lists.linux.it; i=@lists.linux.it; q=dns/txt; s=picard; t=1745604583; h=date : mime-version : message-id : references : in-reply-to : to : subject : list-id : list-unsubscribe : list-archive : list-post : list-help : list-subscribe : from : reply-to : cc : content-type : content-transfer-encoding : sender : from; bh=CjyQC7U+SavDcIoLaradXU4tQarC+iNXFjgoIG6ZdF4=; b=c9/Zj58/GEEP/serpSp3SgqDnEEFh42MOE63TSYAcdB6gmcyrpH/45y0ZkDpg1UuZ9dFd XEUweb3H1CgwTlWU/h1J5uIIdq56gIF+LFJTXc4hNrfH10rRwBAFGABsScXgWCTUJIGmTdA SuEmd6H5QxeO87joqD2+X0Wy4KljmPI= Received: from picard.linux.it (localhost [IPv6:::1]) by picard.linux.it (Postfix) with ESMTP id 32C763CBA9E for ; Fri, 25 Apr 2025 20:09:43 +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 (secp384r1)) (No client certificate requested) by picard.linux.it (Postfix) with ESMTPS id 19B063CB902 for ; Fri, 25 Apr 2025 20:06:35 +0200 (CEST) Received: from mail-ej1-x634.google.com (mail-ej1-x634.google.com [IPv6:2a00:1450:4864:20::634]) (using TLSv1.3 with cipher TLS_AES_128_GCM_SHA256 (128/128 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 4135B1400E0F for ; Fri, 25 Apr 2025 20:06:35 +0200 (CEST) Received: by mail-ej1-x634.google.com with SMTP id a640c23a62f3a-acbb85ce788so504139666b.3 for ; Fri, 25 Apr 2025 11:06:35 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=suse.com; s=google; t=1745604394; x=1746209194; darn=lists.linux.it; h=cc:to:in-reply-to:references:message-id:content-transfer-encoding :mime-version:subject:date:from:from:to:cc:subject:date:message-id :reply-to; bh=a3F4+XtqRlQb0EnuIgfPnuQuapcM2VWD5H/uAzGKuHg=; b=MnwwEZyQaRuW4yzyF4wF6syj7Z4Kvlzadti/sG0CKo+aBNGa/I86O9f8zbpFP10QHJ ibPoKw/57nEt6hFLiOkVE7wle83P/fCk7LLN4o9/NjgX9EKBE1dlj6LoFBRDn2Orj2cb 98hoSMAHgPcXei4Dfo6tqYytByQPpGUKyc2c+Lo9Sayap+Xb/FadGM7pH1kTYmtRTPTi jl3cbQ57x4d/iHb24pU8PbDAR45EOvhOGI4CwsgPHSiv4vONZu2uABTtKQOp+st9EFEW uV97a+qG1wms8BrBiyvMHRdYFnFZt+vs6GPglHQjbhT/yHhFpPGsQE5F52CVEv3V1Xx1 ivIg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1745604394; x=1746209194; h=cc:to:in-reply-to:references:message-id:content-transfer-encoding :mime-version:subject:date:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=a3F4+XtqRlQb0EnuIgfPnuQuapcM2VWD5H/uAzGKuHg=; b=ZyARluTumiwYhk4SLHdlqSWZ4B9pxA2zFKPjO/6x0N0yfOpDK//UeKoE3asXn/y8AW VJ722Vv3MANPl8VKy5H4hTfN7DqFgILw/z51sNjQ194zH1sa0GIBaQVlkIZiUswvcfZh AOuj7YQYegGq/QZGBPZvns9Vm66gEBj/Gvp+ubXDzYZPrSChFkZ0OocPaOyRlj4SGQj2 8i6IcHDSeFwBaz9xfTmmABjRRQ0wIMqAyX+KdraaGy5Wt4jSgbBgIay4JsNmcymnIA6/ RogzeXqNKNnshK0fxU3SpPq/dmNHHl5LBJBk4lHmooR8+JXwUlID1yy16SeANCyBbsum e/Mg== X-Gm-Message-State: AOJu0YwD/yH+GiwjK08v2UnpjuhSvmXboicQClNStoBlciRHIXzkvAPm 2QHt0mJIfEHp/Zvdt7ixzh2SAf/LYYgWh5+JYUW6BYyfv8s7oJvhzBzMNk72Ba1VV6Qj6I/XdLS X X-Gm-Gg: ASbGncsC7JzWgS/m8Z+QoUklP3z9/52XH1awGVd9mEQ3xQvjgQxgMaxxPtLrKPRgBym fNq9QZXFshSyk6SUT2fV3S11Wdl0Sglu3aswn2oHn0p5/BZ2/CqsHLucoUss9QZFcVZBCDo0xe2 HkVtOFFKXvgDvt+9fzGGBm7o4NLSd38N/BLoqwevuWcJHFBDQr/zk0ieIgGPiCY6wiP2rU2Wfxc 2+j71mNMRRxugM850/kbvW74QnQN04vk37CE2YGHnOUC1iNbcyCEKbUqy9lO4JP3uqoNgiFr0sn JXwJAJfL50Sx4zerHVxemvZL9YpzQg== X-Google-Smtp-Source: AGHT+IH4AGw/DQgNBSRodDE86CRPhG1rW/E3EI5f6b2B+IOxAdFYzLMkooh9dCqltlh5eGGxLlsT2A== X-Received: by 2002:a17:907:e915:b0:acb:b0d7:15d8 with SMTP id a640c23a62f3a-ace713dee09mr334745166b.51.1745604394278; Fri, 25 Apr 2025 11:06:34 -0700 (PDT) Received: from localhost ([179.228.213.210]) by smtp.gmail.com with UTF8SMTPSA id 98e67ed59e1d1-309f782d461sm2165249a91.39.2025.04.25.11.06.33 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 25 Apr 2025 11:06:33 -0700 (PDT) Date: Fri, 25 Apr 2025 15:06:08 -0300 MIME-Version: 1.0 Message-Id: <20250425-conversions-mknod-v4-8-222e0d2e7ef1@suse.com> References: <20250425-conversions-mknod-v4-0-222e0d2e7ef1@suse.com> In-Reply-To: <20250425-conversions-mknod-v4-0-222e0d2e7ef1@suse.com> To: Linux Test Project X-Mailer: b4 0.14.2 X-Developer-Signature: v=1; a=openpgp-sha256; l=10394; i=rbm@suse.com; h=from:subject:message-id; bh=5d02Akp71nLCIi1hSNHWfKu8vkGfmUpo87B47cW6JLI=; b=owEBbQKS/ZANAwAIAckLinxjhlimAcsmYgBoC88OH6Whhkjsc+lSpjMW6NmQ7+HAWHo8XFA2L pbFD0tQDEOJAjMEAAEIAB0WIQQDCo6eQk7jwGVXh+HJC4p8Y4ZYpgUCaAvPDgAKCRDJC4p8Y4ZY prIHEAChE7puYDM2TGB+t8QUabbmKVj+3sTzbJQC5jxBVmU4b7Q6PNV/o7cf9Mgrbn/sSIRrhdj H6PqirODV/4lZY+4+h35g1Pwt7G4x/wkQhbmiyZGFl/2oXUa0+hwhrHF7hGnPnlM2N9geb28TFG t2qAd2ag+2mRb6Tkja6tOIA0FN8Cdv/wng3HS+bM39y0l3p6PnBX8kh3FW9EDIMnhfgaKTyED01 eePtlWaPY2kPuDwulwcPT1iJt8+1zQeb7H3WxBJCOLfQz9FkXL2HUixooYIdbvfL0vapk5uP7FP p9PL37ctu4rCelmlkSka6LAleSvf1ldb4/KEbZcoLZ2f82vVVF+oHb7djEsxeSdf/C1wkM88mfw DHW6JABCBPjmTLRg6pWMS6I5EQ9xWIlNYMMU7+o3CA6E/OTVE0Subi2CaugF3OuUM5fSUVB8Iz0 VSiLvnpzc675waYTXslno4ghwPWt11PQp+AVYDS0KMIQCZw61/jjIbouWLsU4xsUR3fOaPY56/e 9bxoJt0TtRPmCDsKV8F/YCmxbmAi7tmaz9QQ0Q8vBWUvWkr8mJyvx1aWhq3dRntNJruuAiyA/K2 +IL+Y2O2totb/HQ9WE60+RsUCSJVDtYj9/oBlueZu1fhQEiqo7FtiEtvGAfpFBk6k9iF2MfWd/r 1LIe0lJq1WBOlQg== X-Developer-Key: i=rbm@suse.com; a=openpgp; fpr=030A8E9E424EE3C0655787E1C90B8A7C638658A6 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.1 X-Spam-Checker-Version: SpamAssassin 4.0.1 (2024-03-25) on in-6.smtp.seeweb.it X-Virus-Scanned: clamav-milter 1.0.7 at in-6.smtp.seeweb.it X-Virus-Status: Clean Subject: [LTP] [PATCH v4 8/8] syscalls/mknod08: Convert to new API 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: , X-Patchwork-Original-From: =?utf-8?q?Ricardo_B=2E_Marli=C3=A8re_via_ltp?= From: =?utf-8?q?Ricardo_B=2E_Marli=C3=A8re?= Reply-To: =?utf-8?q?Ricardo_B=2E_Marli=C3=A8re?= Cc: =?utf-8?q?Ricardo_B=2E_Marli=C3=A8re?= Errors-To: ltp-bounces+incoming=patchwork.ozlabs.org@lists.linux.it Sender: "ltp" From: Ricardo B. Marlière Signed-off-by: Ricardo B. Marlière Reviewed-by: Petr Vorel --- testcases/kernel/syscalls/mknod/mknod08.c | 312 ++++-------------------------- 1 file changed, 37 insertions(+), 275 deletions(-) diff --git a/testcases/kernel/syscalls/mknod/mknod08.c b/testcases/kernel/syscalls/mknod/mknod08.c index 8647fdebb4766151ffd91fd30083389e5def4850..56fd26204ff89aba541663d61067f886b42784fc 100644 --- a/testcases/kernel/syscalls/mknod/mknod08.c +++ b/testcases/kernel/syscalls/mknod/mknod08.c @@ -1,296 +1,58 @@ +// SPDX-License-Identifier: GPL-2.0-or-later /* - * - * Copyright (c) International Business Machines Corp., 2001 - * - * This program is free software; you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation; either version 2 of the License, or - * (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See - * the GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program; if not, write to the Free Software - * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA + * Copyright (c) International Business Machines Corp., 2001 + * 07/2001 Ported by Wayne Boyer + * Copyright (c) 2025 SUSE LLC Ricardo B. Marlière */ -/* - * Test Name: mknod08 - * - * Test Description: - * Verify that mknod(2) succeeds when used to create a filesystem - * node on a directory without set group-ID bit set. The node created - * should not have set group-ID bit set and its gid should be equal to that - * of its parent directory. - * - * Expected Result: - * mknod() should return value 0 on success and node created should not - * have set group-ID bit set. - * - * Algorithm: - * Setup: - * Setup signal handling. - * Create temporary directory. - * Pause for SIGUSR1 if option specified. - * - * Test: - * Loop if the proper options are given. - * Execute system call - * Check return code, if system call failed (return=-1) - * Log the errno and Issue a FAIL message. - * Otherwise, - * Verify the Functionality of system call - * if successful, - * Issue Functionality-Pass message. - * Otherwise, - * Issue Functionality-Fail message. - * Cleanup: - * Print errno log and/or timing stats if options given - * Delete the temporary directory created. - * - * Usage: - * mknod08 [-c n] [-e] [-f] [-i n] [-I x] [-P x] [-t] - * where, -c n : Run n copies concurrently. - * -e : Turn on errno logging. - * -f : Turn off functionality Testing. - * -i n : Execute test n times. - * -I x : Execute test for x seconds. - * -P x : Pause for x seconds between iterations. - * -t : Turn on syscall timing. - * - * HISTORY - * 07/2001 Ported by Wayne Boyer - * - * RESTRICTIONS: - * This test should be run by 'super-user' (root) only. - * +/*\ + * Verify that mknod(2) succeeds when used to create a filesystem node on a + * directory without set group-ID bit set. The node created should not have + * set group-ID bit set and its gid should be equal to that of its parent + * directory. */ -#include -#include -#include -#include -#include -#include #include -#include -#include - -#include "test.h" -#include "safe_macros.h" - -#define LTPUSER "nobody" -#define MODE_RWX S_IFIFO | S_IRWXU | S_IRWXG | S_IRWXO -#define DIR_TEMP "testdir_1" -#define TNODE "tnode_%d" +#include "tst_uid.h" +#include "tst_test.h" -struct stat buf; /* struct. to hold stat(2) o/p contents */ -struct passwd *user1; /* struct. to hold getpwnam(3) o/p contents */ +#define MODE_RWX 0777 -char *TCID = "mknod08"; -int TST_TOTAL = 1; -char node_name[PATH_MAX]; /* buffer to hold node name created */ +#define TEMP_DIR "tempdir" +#define TEMP_NODE TEMP_DIR "/testnode" -gid_t group1_gid, group2_gid, mygid; /* user and process group id's */ -uid_t save_myuid, user1_uid; /* user and process user id's */ -pid_t mypid; /* process id */ +uid_t nobody_uid; +gid_t nobody_gid, free_gid; -void setup(); /* setup function for the test */ -void cleanup(); /* cleanup function for the test */ - -int main(int ac, char **av) +static void run(void) { - int lc; - int fflag; - - tst_parse_opts(ac, av, NULL, NULL); - - setup(); - - for (lc = 0; TEST_LOOPING(lc); lc++) { - - tst_count = 0; + struct stat buf; - /* - * Call mknod() to creat a node on a directory without - * set group-ID (sgid) bit set. - */ - TEST(mknod(node_name, MODE_RWX, 0)); + SAFE_MKNOD(TEMP_NODE, MODE_RWX, 0); - /* Check return code from mknod(2) */ - if (TEST_RETURN == -1) { - tst_resm(TFAIL, - "mknod(%s, %#o, 0) failed, errno=%d : %s", - node_name, MODE_RWX, TEST_ERRNO, - strerror(TEST_ERRNO)); - continue; - } - /* Set the functionality flag */ - fflag = 1; + SAFE_STAT(TEMP_NODE, &buf); + TST_EXP_EQ_LI(buf.st_mode & S_ISGID, 0); + TST_EXP_EQ_LI(buf.st_gid, nobody_gid); - /* Check for node's creation */ - if (stat(node_name, &buf) < 0) { - tst_resm(TFAIL, - "stat() of %s failed, errno:%d", - node_name, TEST_ERRNO); - /* unset flag as functionality fails */ - fflag = 0; - } - - /* Verify mode permissions of node */ - if (buf.st_mode & S_ISGID) { - tst_resm(TFAIL, "%s: Incorrect modes, setgid " - "bit set", node_name); - /* unset flag as functionality fails */ - fflag = 0; - } - - /* Verify group ID */ - if (buf.st_gid != mygid) { - tst_resm(TFAIL, "%s: Incorrect group", - node_name); - /* unset flag as functionality fails */ - fflag = 0; - } - if (fflag) { - tst_resm(TPASS, "Functionality of mknod(%s, " - "%#o, 0) successful", - node_name, MODE_RWX); - } - - /* Remove the node for the next go `round */ - if (unlink(node_name) == -1) { - tst_resm(TWARN, - "unlink(%s) failed, errno:%d %s", - node_name, errno, strerror(errno)); - } - } - - /* Change the directory back to temporary directory */ - SAFE_CHDIR(cleanup, ".."); - - /* - * Invoke cleanup() to delete the test directories created - * in the setup() and exit main(). - */ - cleanup(); - - tst_exit(); + SAFE_UNLINK(TEMP_NODE); } -/* - * setup(void) - performs all ONE TIME setup for this test. - * Exit the test program on receipt of unexpected signals. - * Create a temporary directory used to hold test directories created - * and change the directory to it. - * Verify that pid of process executing the test is root. - * Create a test directory on temporary directory and set the ownership - * of test directory to nobody user. - * Set the effective uid/gid of the process to that of nobody user. - */ -void setup(void) +static void setup(void) { - tst_require_root(); - - /* Capture unexpected signals */ - tst_sig(NOFORK, DEF_HANDLER, cleanup); - - TEST_PAUSE; + struct passwd *ltpuser = SAFE_GETPWNAM("nobody"); - /* Make a temp dir and cd to it */ - tst_tmpdir(); + nobody_uid = ltpuser->pw_uid; + nobody_gid = ltpuser->pw_gid; + free_gid = tst_get_free_gid(nobody_gid); - /* fix permissions on the tmpdir */ - if (chmod(".", 0711) != 0) { - tst_brkm(TBROK, cleanup, "chmod() failed"); - } - - /* Save the real user id of the test process */ - save_myuid = getuid(); - - /* Save the process id of the test process */ - mypid = getpid(); - - /* Get the node name to be created in the test */ - sprintf(node_name, TNODE, mypid); - - /* Get the uid/gid of guest user - nobody */ - if ((user1 = getpwnam(LTPUSER)) == NULL) { - tst_brkm(TBROK, cleanup, "%s not in /etc/passwd", LTPUSER); - } - user1_uid = user1->pw_uid; - group1_gid = user1->pw_gid; - - /* Get effective group id of the test process */ - group2_gid = getegid(); - - /* - * Create a test directory under temporary directory with the - * specified mode permissions, with uid/gid set to that of guest - * user and the test process. - */ - SAFE_MKDIR(cleanup, DIR_TEMP, MODE_RWX); - SAFE_CHOWN(cleanup, DIR_TEMP, user1_uid, group2_gid); - - /* - * Verify that test directory created with expected permission modes - * and ownerships. - */ - SAFE_STAT(cleanup, DIR_TEMP, &buf); - - /* Verify modes of test directory */ - if (buf.st_mode & S_ISGID) { - tst_brkm(TBROK, cleanup, - "%s: Incorrect modes, setgid bit set", DIR_TEMP); - } - - /* Verify group ID */ - if (buf.st_gid != group2_gid) { - tst_brkm(TBROK, cleanup, "%s: Incorrect group", DIR_TEMP); - } - - /* - * Set the effective group id and user id of the test process - * to that of guest user. - */ - SAFE_SETGID(cleanup, group1_gid); - if (setreuid(-1, user1_uid) < 0) { - tst_brkm(TBROK, cleanup, - "Unable to set process uid to that of ltp user"); - } - - /* Save the real group ID of the current process */ - mygid = getgid(); - - /* Change directory to DIR_TEMP */ - SAFE_CHDIR(cleanup, DIR_TEMP); + SAFE_MKDIR(TEMP_DIR, MODE_RWX); + SAFE_CHOWN(TEMP_DIR, nobody_uid, free_gid); + SAFE_SETGID(nobody_gid); } -/* - * cleanup() - Performs all ONE TIME cleanup for this test at - * completion or premature exit. - * Print test timing stats and errno log if test executed with options. - * Restore the real/effective user id of the process changed during - * setup(). - * Remove temporary directory and sub-directories/files under it - * created during setup(). - * Exit the test program with normal exit code. - */ -void cleanup(void) -{ - - /* - * Restore the effective uid of the process changed in the - * setup(). - */ - if (setreuid(-1, save_myuid) < 0) { - tst_brkm(TBROK, NULL, - "resetting process real/effective uid failed"); - } - - tst_rmdir(); - -} +static struct tst_test test = { + .setup = setup, + .test_all = run, + .needs_root = 1, + .needs_tmpdir = 1, +};