From patchwork Wed Aug 3 10:19:39 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Yang Xu X-Patchwork-Id: 1663254 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Authentication-Results: bilbo.ozlabs.org; dkim=fail reason="signature verification failed" (2048-bit key; unprotected) header.d=fujitsu.com header.i=@fujitsu.com header.a=rsa-sha256 header.s=170520fj header.b=BNloeusw; dkim-atps=neutral Authentication-Results: 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=) 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 RSA-PSS (2048 bits) server-digest SHA256) (No client certificate requested) by bilbo.ozlabs.org (Postfix) with ESMTPS id 4LyRBZ6P9dz9s5W for ; Wed, 3 Aug 2022 19:19:17 +1000 (AEST) Received: from picard.linux.it (localhost [IPv6:::1]) by picard.linux.it (Postfix) with ESMTP id 37B363C91B1 for ; Wed, 3 Aug 2022 11:19:13 +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 (P-384)) (No client certificate requested) by picard.linux.it (Postfix) with ESMTPS id E2F6D3C0294 for ; Wed, 3 Aug 2022 11:19:10 +0200 (CEST) Received: from mail1.bemta34.messagelabs.com (mail1.bemta34.messagelabs.com [195.245.231.4]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by in-4.smtp.seeweb.it (Postfix) with ESMTPS id 970F61000A49 for ; Wed, 3 Aug 2022 11:19:09 +0200 (CEST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=fujitsu.com; s=170520fj; t=1659518348; i=@fujitsu.com; bh=29yUIeCpnuwLtBA7hvKMboabhgf9Iva2+HSJ054CYig=; h=From:To:CC:Subject:Date:Message-ID:MIME-Version:Content-Type; b=BNloeuswBHvwtpZ1NSKx4MCDhsfOvM1QgMifd6Gz+PH3h4t9M5gvijsG08UOlQ1xP T0KmZtYbIE7V4VugC+5S4MuU3zlbMRVTEdMsVAKhL1ZjIVno/Jvcle6gc6Lb+O0qBM 0PbZyrn32HKxflSOpZPDVCqj608cJJzA7j1r9mllWqPAjGmQIkunJZrLDS0K6zFEMk HwjJgauoP2FYHfqVqhS2kCb/BWWkDYoAERcRTAdcSnSICft5N1Xh07Gd0b1yJlIP9P XIzAqInyjGKNxaqtDn/5VknLlCI9o+uo0/LpyvEABwRey73ZFyJzAZD5XElg9ztHuJ 6P0JASBtdzHNQ== X-Brightmail-Tracker: H4sIAAAAAAAAA+NgFjrOIsWRWlGSWpSXmKPExsViZ8MxSbfb9lW SwfonFhab96xjsVjxfQejRfejPawOzB77fq9j9Xi/7yqbx+bT1QHMUayZeUn5FQmsGa1LbzMV bOGvONG8kL2B8R1PFyMXh5DAFkaJGzO+s0M4y5kkNt98zgLh7GaUaPvbw9rFyMnBJqAp8axzA TOILSIgIdHR8JYdxGYWCJF4N3k9C4gtLOAocaLxFCOIzSKgIvF09VqwXl4BD4lJU+6D1UgIKE hMefieGSIuKHFy5hMWiDkSEgdfvGCGqFGUuNTxjRHCrpB4ffgSVFxN4uq5TcwTGPlnIWmfhaR 9ASPTKkbrpKLM9IyS3MTMHF1DAwNdQ0NTXWMLXUMTA73EKt1EvdRS3fLU4hJdI73E8mK91OJi veLK3OScFL281JJNjMDwTSlW69nBeGLVT71DjJIcTEqivGfMXyUJ8SXlp1RmJBZnxBeV5qQWH 2KU4eBQkuAtsAbKCRalpqdWpGXmAGMJJi3BwaMkwvvdCijNW1yQmFucmQ6ROsWoKCXOO9sGKC EAksgozYNrg8XvJUZZKWFeRgYGBiGegtSi3MwSVPlXjOIcjErCvCdAtvNk5pXATX8FtJgJaLE O1wuQxSWJCCmpBibO6ksiEpe//X3IuNqt8r7jVTvptSJdm+tffvPdI8VoVJ+2+sev0EmNza/m NS8t57/becjUxObM1F1T4u7sfHd4Tbn5oYcSp/alrGn+mcm3Yxbbo1WBCQn/DuveC113r3LTl c06ERVLhe8cWv4pefs6701ZmkU1bzLerJBT3zz3+7c/7+VdpbQUv6cXP7mpaSAXe81XmuXZO/ 4Wjx9Pqhmk/jas67NbLNQpsuOs4/nQ7G+8mq2MazbItVz+IOrwNJl/5Z6/O7MLTh03m9SSNEv qYeTmQyns/3/tKr/AY+FkE6GhejvsTkhVh9qVKv76I76vVRwLSk895d9tIm0Z9jbjgH6V54LK x4+PaAsbafMpsRRnJBpqMRcVJwIAxyMzuloDAAA= X-Env-Sender: xuyang2018.jy@fujitsu.com X-Msg-Ref: server-10.tower-565.messagelabs.com!1659518347!379781!1 X-Originating-IP: [62.60.8.146] X-SYMC-ESS-Client-Auth: outbound-route-from=pass X-StarScan-Received: X-StarScan-Version: 9.87.3; banners=-,-,- X-VirusChecked: Checked Received: (qmail 12384 invoked from network); 3 Aug 2022 09:19:07 -0000 Received: from unknown (HELO n03ukasimr02.n03.fujitsu.local) (62.60.8.146) by server-10.tower-565.messagelabs.com with ECDHE-RSA-AES256-GCM-SHA384 encrypted SMTP; 3 Aug 2022 09:19:07 -0000 Received: from n03ukasimr02.n03.fujitsu.local (localhost [127.0.0.1]) by n03ukasimr02.n03.fujitsu.local (Postfix) with ESMTP id 974331000E9; Wed, 3 Aug 2022 10:19:07 +0100 (BST) Received: from R01UKEXCASM126.r01.fujitsu.local (R01UKEXCASM126 [10.183.43.178]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-SHA384 (256/256 bits)) (No client certificate requested) by n03ukasimr02.n03.fujitsu.local (Postfix) with ESMTPS id 88C291000CE; Wed, 3 Aug 2022 10:19:07 +0100 (BST) Received: from localhost.localdomain (10.167.220.84) by R01UKEXCASM126.r01.fujitsu.local (10.183.43.178) with Microsoft SMTP Server (TLS) id 15.0.1497.32; Wed, 3 Aug 2022 10:19:05 +0100 From: Yang Xu To: Date: Wed, 3 Aug 2022 18:19:39 +0800 Message-ID: <1659521981-2241-1-git-send-email-xuyang2018.jy@fujitsu.com> X-Mailer: git-send-email 1.8.3.1 MIME-Version: 1.0 X-Originating-IP: [10.167.220.84] X-ClientProxiedBy: G08CNEXCHPEKD08.g08.fujitsu.local (10.167.33.83) To R01UKEXCASM126.r01.fujitsu.local (10.183.43.178) X-Virus-Scanned: clamav-milter 0.102.4 at in-4.smtp.seeweb.it X-Virus-Status: Clean X-Spam-Status: No, score=0.1 required=7.0 tests=DKIM_SIGNED,DKIM_VALID, DKIM_VALID_AU,DKIM_VALID_EF,SPF_HELO_NONE,SPF_PASS autolearn=disabled version=3.4.4 X-Spam-Checker-Version: SpamAssassin 3.4.4 (2020-01-24) on in-4.smtp.seeweb.it Subject: [LTP] [PATCH v1 1/3] tst_safe_file_at: Add SAFE_FCHOWNAT macro X-BeenThere: ltp@lists.linux.it X-Mailman-Version: 2.1.29 Precedence: list List-Id: Linux Test Project List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: ltp-bounces+incoming=patchwork.ozlabs.org@lists.linux.it Sender: "ltp" Signed-off-by: Yang Xu --- include/tst_safe_file_at.h | 9 +++++++++ lib/tst_safe_file_at.c | 20 ++++++++++++++++++++ 2 files changed, 29 insertions(+) diff --git a/include/tst_safe_file_at.h b/include/tst_safe_file_at.h index 8df34227f..e253198e6 100644 --- a/include/tst_safe_file_at.h +++ b/include/tst_safe_file_at.h @@ -25,6 +25,10 @@ #define SAFE_UNLINKAT(dirfd, path, flags) \ safe_unlinkat(__FILE__, __LINE__, (dirfd), (path), (flags)) +#define SAFE_FCHOWNAT(dirfd, path, owner, group, flags) \ + safe_fchownat(__FILE__, __LINE__, \ + (dirfd), (path), (owner), (group), (flags)) + const char *tst_decode_fd(const int fd) __attribute__((warn_unused_result)); @@ -58,4 +62,9 @@ int safe_unlinkat(const char *const file, const int lineno, const int dirfd, const char *const path, const int flags) __attribute__ ((nonnull)); +int safe_fchownat(const char *const file, const int lineno, + const int dirfd, const char *const path, uid_t owner, + gid_t group, int flags) + __attribute__ ((nonnull)); + #endif diff --git a/lib/tst_safe_file_at.c b/lib/tst_safe_file_at.c index ca8ef2f68..6370a68e5 100644 --- a/lib/tst_safe_file_at.c +++ b/lib/tst_safe_file_at.c @@ -195,3 +195,23 @@ int safe_unlinkat(const char *const file, const int lineno, return rval; } + +int safe_fchownat(const char *const file, const int lineno, + const int dirfd, const char *const path, uid_t owner, gid_t group, int flags) +{ + int rval; + + rval = fchownat(dirfd, path, owner, group, flags); + + if (rval == -1) { + tst_brk_(file, lineno, TBROK | TERRNO, + "fchownat(%d<%s>, '%s', %d, %d, %d) failed", dirfd, + tst_decode_fd(dirfd), path, owner, group, flags); + } else if (rval) { + tst_brk_(file, lineno, TBROK | TERRNO, + "Invalid fchownat(%d<%s>, '%s', %d, %d, %d) return value %d", + dirfd, tst_decode_fd(dirfd), path, owner, group, flags, rval); + } + + return rval; +} From patchwork Wed Aug 3 10:19:40 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Yang Xu X-Patchwork-Id: 1663255 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Authentication-Results: bilbo.ozlabs.org; dkim=fail reason="signature verification failed" (2048-bit key; unprotected) header.d=fujitsu.com header.i=@fujitsu.com header.a=rsa-sha256 header.s=170520fj header.b=w+TaA75X; dkim-atps=neutral Authentication-Results: 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=) 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 RSA-PSS (2048 bits) server-digest SHA256) (No client certificate requested) by bilbo.ozlabs.org (Postfix) with ESMTPS id 4LyRBn0WQ8z9s5W for ; Wed, 3 Aug 2022 19:19:29 +1000 (AEST) Received: from picard.linux.it (localhost [IPv6:::1]) by picard.linux.it (Postfix) with ESMTP id D9A5E3C93F2 for ; Wed, 3 Aug 2022 11:19:24 +0200 (CEST) X-Original-To: ltp@lists.linux.it Delivered-To: ltp@picard.linux.it Received: from in-2.smtp.seeweb.it (in-2.smtp.seeweb.it [217.194.8.2]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (P-384)) (No client certificate requested) by picard.linux.it (Postfix) with ESMTPS id AAD233C9354 for ; Wed, 3 Aug 2022 11:19:18 +0200 (CEST) Received: from mail1.bemta32.messagelabs.com (mail1.bemta32.messagelabs.com [195.245.230.1]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by in-2.smtp.seeweb.it (Postfix) with ESMTPS id DB389600A57 for ; Wed, 3 Aug 2022 11:19:17 +0200 (CEST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=fujitsu.com; s=170520fj; t=1659518356; i=@fujitsu.com; bh=XIQJgqhgtgp25V9sr/mpFoe7S3WVst40JgInlg0wq78=; h=From:To:CC:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version:Content-Type; b=w+TaA75XrP26uOmhQq0FUBqgnz14dd0X2h4B2ChuM564UuepWkdQd0cEFpzJVZ78B cdSJbNVSHdzukj5NdO7/1cCrVZdmVIexJSsLUanN98Y5OjCn77J+QxmqghOnGPzF6g M1fv5Ms+Bl85Aaa50vqz8J4VtbfHujJ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tGXxdju+n3lkZ7bdHtK54mlyLi4/YsnI/x7enjWVNpOeteWQy1ew AU9/XHQy+c1v7mkuWvr/vfb2x/2qu0GWhNK+Kv8+8nn/yk9mV/7RFPcND6eXVZ0sepdjHhIq6 xBsdOXPlaWZvnYHvn8iOuJNH7ny990ipw0aJpTgj0VCLuag4EQC6PggNbwMAAA== X-Env-Sender: xuyang2018.jy@fujitsu.com X-Msg-Ref: server-11.tower-587.messagelabs.com!1659518356!198886!1 X-Originating-IP: [62.60.8.97] X-SYMC-ESS-Client-Auth: outbound-route-from=pass X-StarScan-Received: X-StarScan-Version: 9.87.3; banners=-,-,- X-VirusChecked: Checked Received: (qmail 6733 invoked from network); 3 Aug 2022 09:19:16 -0000 Received: from unknown (HELO n03ukasimr01.n03.fujitsu.local) (62.60.8.97) by server-11.tower-587.messagelabs.com with ECDHE-RSA-AES256-GCM-SHA384 encrypted SMTP; 3 Aug 2022 09:19:16 -0000 Received: from n03ukasimr01.n03.fujitsu.local (localhost [127.0.0.1]) by n03ukasimr01.n03.fujitsu.local (Postfix) with ESMTP id 01F36100190; Wed, 3 Aug 2022 10:19:16 +0100 (BST) Received: from R01UKEXCASM126.r01.fujitsu.local (R01UKEXCASM126 [10.183.43.178]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-SHA384 (256/256 bits)) (No client certificate requested) by n03ukasimr01.n03.fujitsu.local (Postfix) with ESMTPS id E9994100043; Wed, 3 Aug 2022 10:19:15 +0100 (BST) Received: from localhost.localdomain (10.167.220.84) by R01UKEXCASM126.r01.fujitsu.local (10.183.43.178) with Microsoft SMTP Server (TLS) id 15.0.1497.32; Wed, 3 Aug 2022 10:19:13 +0100 From: Yang Xu To: Date: Wed, 3 Aug 2022 18:19:40 +0800 Message-ID: <1659521981-2241-2-git-send-email-xuyang2018.jy@fujitsu.com> X-Mailer: git-send-email 1.8.3.1 In-Reply-To: <1659521981-2241-1-git-send-email-xuyang2018.jy@fujitsu.com> References: <1659521981-2241-1-git-send-email-xuyang2018.jy@fujitsu.com> MIME-Version: 1.0 X-Originating-IP: [10.167.220.84] X-ClientProxiedBy: G08CNEXCHPEKD08.g08.fujitsu.local (10.167.33.83) To R01UKEXCASM126.r01.fujitsu.local (10.183.43.178) X-Virus-Scanned: clamav-milter 0.102.4 at in-2.smtp.seeweb.it X-Virus-Status: Clean X-Spam-Status: No, score=0.1 required=7.0 tests=DKIM_SIGNED,DKIM_VALID, DKIM_VALID_AU,DKIM_VALID_EF,SPF_HELO_NONE,SPF_PASS autolearn=disabled version=3.4.4 X-Spam-Checker-Version: SpamAssassin 3.4.4 (2020-01-24) on in-2.smtp.seeweb.it Subject: [LTP] [PATCH v1 2/3] tst_cgroup: Add safe_cg_open and safe_cg_fchown functions X-BeenThere: ltp@lists.linux.it X-Mailman-Version: 2.1.29 Precedence: list List-Id: Linux Test Project List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: ltp-bounces+incoming=patchwork.ozlabs.org@lists.linux.it Sender: "ltp" safe_cg_open is used to open the sub control's file ie cgroup.procs and returns the fd. safe_cg_fchown is used to use fchownat to change file's uid and gid. Signed-off-by: Yang Xu --- include/tst_cgroup.h | 15 +++++++++++++++ lib/tst_cgroup.c | 39 +++++++++++++++++++++++++++++++++++++++ 2 files changed, 54 insertions(+) diff --git a/include/tst_cgroup.h b/include/tst_cgroup.h index d06847cc6..292c9baa4 100644 --- a/include/tst_cgroup.h +++ b/include/tst_cgroup.h @@ -188,6 +188,21 @@ ssize_t safe_cg_read(const char *const file, const int lineno, char *const out, const size_t len) __attribute__ ((nonnull)); +#define SAFE_CG_OPEN(cg, file_name, flags) \ + safe_cg_open(__FILE__, __LINE__, (cg), (file_name), (flags)) + +int safe_cg_open(const char *const file, const int lineno, + const struct tst_cg_group *const cg, + const char *const file_name, int flags); + +#define SAFE_CG_FCHOWN(cg, file_name, owner, group) \ + safe_cg_fchown(__FILE__, __LINE__, \ + (cg), (file_name), (owner), (group)) + +void safe_cg_fchown(const char *const file, const int lineno, + const struct tst_cg_group *const cg, + const char *const file_name, uid_t owner, gid_t group); + #define SAFE_CG_PRINTF(cg, file_name, fmt, ...) \ safe_cg_printf(__FILE__, __LINE__, \ (cg), (file_name), (fmt), __VA_ARGS__) diff --git a/lib/tst_cgroup.c b/lib/tst_cgroup.c index 1cfd79243..dedc0f65b 100644 --- a/lib/tst_cgroup.c +++ b/lib/tst_cgroup.c @@ -1297,6 +1297,45 @@ ssize_t safe_cg_read(const char *const file, const int lineno, return read_ret; } +int safe_cg_open(const char *const file, const int lineno, + const struct tst_cg_group *cg, + const char *const file_name, int flags) +{ + const struct cgroup_file *const cfile = + cgroup_file_find(file, lineno, file_name); + struct cgroup_dir *const *dir; + const char *alias; + int fd; + + for_each_dir(cg, cfile->ctrl_indx, dir) { + alias = cgroup_file_alias(cfile, *dir); + if (!alias) + continue; + + fd = safe_openat(file, lineno, (*dir)->dir_fd, alias, flags); + } + + return fd; +} + +void safe_cg_fchown(const char *const file, const int lineno, + const struct tst_cg_group *cg, + const char *const file_name, uid_t owner, gid_t group) +{ + const struct cgroup_file *const cfile = + cgroup_file_find(file, lineno, file_name); + struct cgroup_dir *const *dir; + const char *alias; + + for_each_dir(cg, cfile->ctrl_indx, dir) { + alias = cgroup_file_alias(cfile, *dir); + if (!alias) + continue; + + safe_fchownat(file, lineno, (*dir)->dir_fd, alias, owner, group, 0); + } +} + void safe_cg_printf(const char *const file, const int lineno, const struct tst_cg_group *cg, const char *const file_name, From patchwork Wed Aug 3 10:19:41 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Yang Xu X-Patchwork-Id: 1663256 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Authentication-Results: bilbo.ozlabs.org; dkim=fail reason="signature verification failed" (2048-bit key; unprotected) header.d=fujitsu.com header.i=@fujitsu.com header.a=rsa-sha256 header.s=170520fj header.b=IqQsB495; dkim-atps=neutral Authentication-Results: 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=) 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 RSA-PSS (2048 bits)) (No client certificate requested) by bilbo.ozlabs.org (Postfix) with ESMTPS id 4LyRBz2M11z9s5W for ; Wed, 3 Aug 2022 19:19:39 +1000 (AEST) Received: from picard.linux.it (localhost [IPv6:::1]) by picard.linux.it (Postfix) with ESMTP id 8E91E3C2FBE for ; Wed, 3 Aug 2022 11:19:36 +0200 (CEST) X-Original-To: ltp@lists.linux.it Delivered-To: ltp@picard.linux.it Received: from in-2.smtp.seeweb.it (in-2.smtp.seeweb.it [IPv6:2001:4b78:1:20::2]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (P-384)) (No client certificate requested) by picard.linux.it (Postfix) with ESMTPS id 11CF93C93FF for ; Wed, 3 Aug 2022 11:19:22 +0200 (CEST) Received: from mail1.bemta34.messagelabs.com (mail1.bemta34.messagelabs.com [195.245.231.4]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by in-2.smtp.seeweb.it (Postfix) with ESMTPS id 567EC600A57 for ; Wed, 3 Aug 2022 11:19:20 +0200 (CEST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=fujitsu.com; s=170520fj; t=1659518360; i=@fujitsu.com; bh=/1D0MiabFTr8K+3Ep+xNLATXhvGYv+zdLm/gOGM5Mjc=; h=From:To:CC:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version:Content-Type; b=IqQsB495OsulgfyNeOAhKM+fFNiAcA+6BVVj0ZUJw0oBCsuYl9HuN6Ya6tDD0/ZoH wCd7ik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BhR+X5NXmVskFSt33Ec76pvD3zfxsk6a5H3z3hyauCQjo3vtgblDin5ff+he5Hb n45UabW19KuZm67OaiBr8vD24vFt27IJ6joOP6mZjdF46rP69f+EnyTcme+TseRpSt3Kxueab M4mbBzN2rQ6e/Xyl/a0VM/6xSR+b1iRfOPZh4w/nAzda++Bd/41a5mO0wm125RCRxluv+n9XH uXT3Pma2fT2N5dZT9uvTtOZcf7+b2V93d295ut+tVU/tj/C+Wv5ZiaU4I9FQi7moOBEADjGaT 34DAAA= X-Env-Sender: xuyang2018.jy@fujitsu.com X-Msg-Ref: server-4.tower-548.messagelabs.com!1659518359!51098!1 X-Originating-IP: [62.60.8.179] X-SYMC-ESS-Client-Auth: outbound-route-from=pass X-StarScan-Received: X-StarScan-Version: 9.87.3; banners=-,-,- X-VirusChecked: Checked Received: (qmail 11950 invoked from network); 3 Aug 2022 09:19:20 -0000 Received: from unknown (HELO n03ukasimr04.n03.fujitsu.local) (62.60.8.179) by server-4.tower-548.messagelabs.com with ECDHE-RSA-AES256-GCM-SHA384 encrypted SMTP; 3 Aug 2022 09:19:20 -0000 Received: from n03ukasimr04.n03.fujitsu.local (localhost [127.0.0.1]) by n03ukasimr04.n03.fujitsu.local (Postfix) with ESMTP id C1E627B; Wed, 3 Aug 2022 10:19:19 +0100 (BST) Received: from R01UKEXCASM126.r01.fujitsu.local (R01UKEXCASM126 [10.183.43.178]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-SHA384 (256/256 bits)) (No client certificate requested) by n03ukasimr04.n03.fujitsu.local (Postfix) with ESMTPS id B56BB155; Wed, 3 Aug 2022 10:19:19 +0100 (BST) Received: from localhost.localdomain (10.167.220.84) by R01UKEXCASM126.r01.fujitsu.local (10.183.43.178) with Microsoft SMTP Server (TLS) id 15.0.1497.32; Wed, 3 Aug 2022 10:19:17 +0100 From: Yang Xu To: Date: Wed, 3 Aug 2022 18:19:41 +0800 Message-ID: <1659521981-2241-3-git-send-email-xuyang2018.jy@fujitsu.com> X-Mailer: git-send-email 1.8.3.1 In-Reply-To: <1659521981-2241-1-git-send-email-xuyang2018.jy@fujitsu.com> References: <1659521981-2241-1-git-send-email-xuyang2018.jy@fujitsu.com> MIME-Version: 1.0 X-Originating-IP: [10.167.220.84] X-ClientProxiedBy: G08CNEXCHPEKD08.g08.fujitsu.local (10.167.33.83) To R01UKEXCASM126.r01.fujitsu.local (10.183.43.178) X-Virus-Scanned: clamav-milter 0.102.4 at in-2.smtp.seeweb.it X-Virus-Status: Clean X-Spam-Status: No, score=0.1 required=7.0 tests=DKIM_SIGNED,DKIM_VALID, DKIM_VALID_AU,DKIM_VALID_EF,SPF_HELO_NONE,SPF_PASS autolearn=disabled version=3.4.4 X-Spam-Checker-Version: SpamAssassin 3.4.4 (2020-01-24) on in-2.smtp.seeweb.it Subject: [LTP] [PATCH v1 3/3] memcontrol05: copy from kernel selftest test_cgcore_lesser_euid_open X-BeenThere: ltp@lists.linux.it X-Mailman-Version: 2.1.29 Precedence: list List-Id: Linux Test Project List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: ltp-bounces+incoming=patchwork.ozlabs.org@lists.linux.it Sender: "ltp" Signed-off-by: Yang Xu --- TODO: In the future, also add a regression test in cgroup namespace[1] if I have free time. Or, I will add it on v2. [1]https://git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git/commit/?id=bf35a787 runtest/controllers | 1 + testcases/kernel/controllers/memcg/.gitignore | 1 + .../kernel/controllers/memcg/memcontrol05.c | 90 +++++++++++++++++++ 3 files changed, 92 insertions(+) create mode 100644 testcases/kernel/controllers/memcg/memcontrol05.c diff --git a/runtest/controllers b/runtest/controllers index 22d482050..5c51a414a 100644 --- a/runtest/controllers +++ b/runtest/controllers @@ -21,6 +21,7 @@ memcontrol01 memcontrol01 memcontrol02 memcontrol02 memcontrol03 memcontrol03 memcontrol04 memcontrol04 +memcontrol05 memcontrol05 cgroup_fj_function_debug cgroup_fj_function.sh debug cgroup_fj_function_cpuset cgroup_fj_function.sh cpuset diff --git a/testcases/kernel/controllers/memcg/.gitignore b/testcases/kernel/controllers/memcg/.gitignore index 3883cede6..8b9f6005c 100644 --- a/testcases/kernel/controllers/memcg/.gitignore +++ b/testcases/kernel/controllers/memcg/.gitignore @@ -9,3 +9,4 @@ memcontrol01 memcontrol02 memcontrol03 memcontrol04 +memcontrol05 diff --git a/testcases/kernel/controllers/memcg/memcontrol05.c b/testcases/kernel/controllers/memcg/memcontrol05.c new file mode 100644 index 000000000..24976b602 --- /dev/null +++ b/testcases/kernel/controllers/memcg/memcontrol05.c @@ -0,0 +1,90 @@ +// SPDX-License-Identifier: GPL-2.0-or-later +/* + * Copyright (c) 2022 FUJITSU LIMITED. All rights reserved. + * Author: Yang Xu + */ + +/*\ + * [Description] + * + * When a task is writing to an fd opened by a different task, the perm check + * should use the credentials of the latter task. + * + * It is copy from kernel selftests cgroup test_core test_cgcore_lesser_euid_open + * subcase. The difference is that kernel selftest only supports cgroup v2 but + * here we also support cgroup v1 and v2. + * + * It is a regression test for + * + * commit e57457641613fef0d147ede8bd6a3047df588b95 + * Author: Tejun Heo + * Date: Thu Jan 6 11:02:29 2022 -1000 + * + * cgroup: Use open-time cgroup namespace for process migration perm checks + */ + +#include +#include +#include +#include +#include "tst_test.h" +#include "tst_safe_file_at.h" + +static struct tst_cg_group *cg_child; +static uid_t nobody_uid, save_uid; + +static void test_lesser_euid_open(void) +{ + int fd; + + cg_child = tst_cg_group_mk(tst_cg, "child"); + if (!SAFE_FORK()) { + SAFE_CG_FCHOWN(cg_child, "cgroup.procs", nobody_uid, -1); + SAFE_SETEUID(nobody_uid); + + fd = SAFE_CG_OPEN(cg_child, "cgroup.procs", O_RDWR); + SAFE_SETEUID(save_uid); + + TEST(write(fd, "0", 1)); + if (TST_RET >= 0 || TST_ERR != EACCES) + tst_res(TFAIL, "lesser_euid_open failed"); + else + tst_res(TPASS | TTERRNO, "less_euid_open passed"); + + SAFE_CLOSE(fd); + exit(0); + } + + tst_reap_children(); + cg_child = tst_cg_group_rm(cg_child); +} + +static void setup(void) +{ + struct passwd *pw; + + pw = SAFE_GETPWNAM("nobody"); + nobody_uid = pw->pw_uid; + save_uid = geteuid(); +} + +static void cleanup(void) +{ + if (cg_child) { + SAFE_CG_PRINTF(tst_cg_drain, "cgroup.procs", "%d", getpid()); + cg_child = tst_cg_group_rm(cg_child); + } +} + +static struct tst_test test = { + .setup = setup, + .cleanup = cleanup, + .test_all = test_lesser_euid_open, + .forks_child = 1, + .needs_root = 1, + .needs_cgroup_ctrls = (const char *const[]){ "memory", NULL }, + .tags = (const struct tst_tag[]) { + {"linux-git", "e57457641613"}, + {} + }, +};