From patchwork Fri May 15 15:23:18 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Nate Karstens X-Patchwork-Id: 1291424 X-Patchwork-Delegate: davem@davemloft.net Return-Path: X-Original-To: patchwork-incoming@ozlabs.org Delivered-To: patchwork-incoming@ozlabs.org Authentication-Results: ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=vger.kernel.org (client-ip=23.128.96.18; helo=vger.kernel.org; envelope-from=sparclinux-owner@vger.kernel.org; receiver=) Authentication-Results: ozlabs.org; dmarc=pass (p=quarantine dis=none) header.from=garmin.com Authentication-Results: ozlabs.org; dkim=pass (2048-bit key; unprotected) header.d=garmin.com header.i=@garmin.com header.a=rsa-sha256 header.s=selector1 header.b=iaqAUjEV; dkim-atps=neutral Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by ozlabs.org (Postfix) with ESMTP id 49Nsdw1yr6z9sV3 for ; Sat, 16 May 2020 01:24:36 +1000 (AEST) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1726614AbgEOPYN (ORCPT ); Fri, 15 May 2020 11:24:13 -0400 Received: from mail-eopbgr700119.outbound.protection.outlook.com ([40.107.70.119]:43540 "EHLO NAM04-SN1-obe.outbound.protection.outlook.com" rhost-flags-OK-OK-OK-FAIL) by vger.kernel.org with ESMTP id S1726362AbgEOPYG (ORCPT ); Fri, 15 May 2020 11:24:06 -0400 ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=UuZT9xaQszvCMxzm1kOCMxt39RjxZxfaXz1Pz2XkmWxkYJ+U+1jfgAA4FSI5OFMgtPSEvDwOhgdY2LJv4e5SvmSZdwHfMC+n8uuc4PAE3DZFM4IzDyWC+faun0TqnS1QakiRGZiCEs1LRB3chT5bHZin++TtAC7W08PdB93GjCoZDxd3IhuK3+oi9ytZK+w73poA59gwlHQO2Z4hqCDmNcIUgAXazVTksfkwcwyqnuDqC540JHTE4CFiuXgm1Wl92C+hENVRNVln2Nq92FwdoGaBpMnIt5Vjoev/WZs97OprO4HyFrHc8TdAWaoWidIrMfCUgc3mQJ7pZFLTkvFjCg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=microsoft.com; s=arcselector9901; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck; bh=QsGNsjYsI8F4KJql4yZYX+Vqvvff2TzQBu9X3M2j3GQ=; b=KrDIn/IRlMTZjRVkQ4+q4+mw+d+K0vZ3DF5Z7kV7NrIAZ0HWr9+r3YHK6STB+hBmegr01Mj/mFLMTq1S0eWEbv+QBl2OhsMa+0L7TKCqCJdp1FCCzqaAwzElCRolYLzqf+N4AzvpjnEVnVLlnk1jPj9jN82RRKB6rq+iHLKzfiROGnTSZNXwNBbQdhQDgMMOMg5QUGd6Ob6Xqlh+Jpkeu0uOofJjNRXI6QldPoDOs+YmLlysvrbOyRtq2hhrd/xJPyhv+mFk4Gtrfi+Vt1SNgvbeBiDxu2C4q1acVHP5a6JhyD+pCVWLL2z4M80Xivj1YaWUGX7A87jZrrnWuU09Tw== ARC-Authentication-Results: i=1; mx.microsoft.com 1; spf=pass (sender ip is 204.77.163.244) smtp.rcpttodomain=zeniv.linux.org.uk smtp.mailfrom=garmin.com; dmarc=pass (p=quarantine sp=quarantine pct=100) action=none header.from=garmin.com; dkim=none (message not signed); arc=none DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=garmin.com; s=selector1; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck; bh=QsGNsjYsI8F4KJql4yZYX+Vqvvff2TzQBu9X3M2j3GQ=; b=iaqAUjEVMMV9INxTJ3Xj15oXJ2Tr5dFVM5el7qG7ey1YtMiGvxnTkc7ctZat0LK/7MJK/GY1Mhgl6fWBRkwdM1/mX/sbvessuM36KeWxxCTGlTLJJX2HwuYKolqe4EI7t4al97FeQu25kP0WvqDaf08zkXw7NrXWAu9w1ovbvE1VASNIJkiuqJDsFlJ3iaJex4036VIbQbElJD13XACMvEd7GUVWye7K30jR5jHHRfEX51RPOrB6KkETvb73euazNOHrBbfdAsUfbXe2dkC3cq8/1hoEhK3LtPiFlgcNeSfDh/1msuI/vGK5U3goKd0ngqFkR+LoE7BY19pg73ugiA== Received: from BN6PR11CA0046.namprd11.prod.outlook.com (2603:10b6:404:4b::32) by DM6PR04MB4154.namprd04.prod.outlook.com (2603:10b6:5:9a::11) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.3000.24; Fri, 15 May 2020 15:24:01 +0000 Received: from BN7NAM10FT028.eop-nam10.prod.protection.outlook.com (2603:10b6:404:4b:cafe::1b) by BN6PR11CA0046.outlook.office365.com (2603:10b6:404:4b::32) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.3000.20 via Frontend Transport; Fri, 15 May 2020 15:24:01 +0000 Authentication-Results: spf=pass (sender IP is 204.77.163.244) smtp.mailfrom=garmin.com; zeniv.linux.org.uk; dkim=none (message not signed) header.d=none;zeniv.linux.org.uk; dmarc=pass action=none header.from=garmin.com; Received-SPF: Pass (protection.outlook.com: domain of garmin.com designates 204.77.163.244 as permitted sender) receiver=protection.outlook.com; client-ip=204.77.163.244; helo=edgetransport.garmin.com; Received: from edgetransport.garmin.com (204.77.163.244) by BN7NAM10FT028.mail.protection.outlook.com (10.13.156.237) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.3000.19 via Frontend Transport; Fri, 15 May 2020 15:24:00 +0000 Received: from OLAWPA-EXMB7.ad.garmin.com (10.5.144.21) by olawpa-edge2.garmin.com (10.60.4.35) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_CBC_SHA256) id 15.1.1466.3; Fri, 15 May 2020 10:23:58 -0500 Received: from ola-d01c000-vm.ad.garmin.com (10.5.84.15) by OLAWPA-EXMB7.ad.garmin.com (10.5.144.21) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_CBC_SHA256_P256) id 15.1.1913.5; Fri, 15 May 2020 10:23:59 -0500 From: Nate Karstens To: Alexander Viro , Jeff Layton , "J. Bruce Fields" , Arnd Bergmann , Richard Henderson , Ivan Kokshaysky , Matt Turner , "James E.J. Bottomley" , Helge Deller , "David S. Miller" , Jakub Kicinski , Eric Dumazet , David Laight , , , , , , , CC: Changli Gao , Nate Karstens Subject: [PATCH v2 1/4] fs: Implement close-on-fork Date: Fri, 15 May 2020 10:23:18 -0500 Message-ID: <20200515152321.9280-2-nate.karstens@garmin.com> X-Mailer: git-send-email 2.26.1 In-Reply-To: <20200515152321.9280-1-nate.karstens@garmin.com> References: <20200515152321.9280-1-nate.karstens@garmin.com> MIME-Version: 1.0 X-ClientProxiedBy: OLAWPA-EXMB3.ad.garmin.com (10.5.144.15) To OLAWPA-EXMB7.ad.garmin.com (10.5.144.21) X-TM-AS-Product-Ver: SMEX-12.5.0.1300-8.5.1020-25422.000 X-TM-AS-Result: No-8.366000-8.000000-10 X-TMASE-MatchedRID: zU8/ga22QnsY5XJhZJs6SDCMW7zNwFaIGiQ8GIEGP38y2ckJNvUX+HzK 3Q9zSFL7ATYOMR69+dqRXQsE2URVLPpC5SMG+P7XB8FxO/BQHsIacZilk37ECL95OdmJ178BjL9 k66lsprSFCmd9YpPXsWn9q4aEyPwAwsZtKo32enS7qoPZRcH3U8tDHw9RrCNbx5B+7qLBJ+xAHO g8qEtqyI+pAn19BHXOF/tIpAzU+Bdk5pVuCWjzQc36paW7ZnFor4ukWaaTegCfuM4lD6uC8TECc rZ55BeGF9v+Dr8BUC0xFzy2mxela8ctxF7vDKgQiVJZi91I9JjgXnxE81iysQcB7juZygIJyVBW 8fUk7pM1wU4Zygz0SnW00rbMu3zpYwDOL7t3RyEPe5gzF3TVt1OMvMY8acYWSg8ufp5n3T4n4FP RjzsKxkuD8yJMtBEu7I0yDuih8283KXWd30Ii3RRFJJyf5BJe3QfwsVk0UbtuRXh7bFKB7k/MEt SMvTDCLLLAiOOemOylwObsQibNC/NFVcbL+CYQsBTJSD2iAW0= X-TM-AS-User-Approved-Sender: No X-TM-AS-User-Blocked-Sender: No X-TMASE-Result: 10--8.366000-8.000000 X-TMASE-Version: SMEX-12.5.0.1300-8.5.1020-25422.000 X-EOPAttributedMessage: 0 X-MS-Office365-Filtering-HT: Tenant X-Forefront-Antispam-Report: CIP:204.77.163.244;CTRY:US;LANG:en;SCL:1;SRV:;IPV:CAL;SFV:NSPM;H:edgetransport.garmin.com;PTR:extedge.garmin.com;CAT:NONE;SFTY:;SFS:(376002)(396003)(346002)(39860400002)(136003)(46966005)(8936002)(54906003)(107886003)(8676002)(316002)(7416002)(5660300002)(110136005)(44832011)(2616005)(186003)(26005)(4326008)(70586007)(2906002)(336012)(356005)(70206006)(6666004)(86362001)(36756003)(478600001)(47076004)(82310400002)(7696005)(426003)(7636003)(82740400003)(1076003)(921003);DIR:OUT;SFP:1102; X-MS-PublicTrafficType: Email X-MS-Office365-Filtering-Correlation-Id: 067c2890-a865-47dc-8f3b-08d7f8e3fe64 X-MS-TrafficTypeDiagnostic: DM6PR04MB4154: X-Microsoft-Antispam-PRVS: X-MS-Oob-TLC-OOBClassifiers: OLM:4714; X-Forefront-PRVS: 04041A2886 X-MS-Exchange-SenderADCheck: 1 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: iAS3Sor/+udiXNczVDCj21/aQvEvRwLXCCH+me6ncNHBIFwrfxz2RnIVbkKs9Q2LIHgQdxwbTMlmyP252bqhGZ+vrD6DjnbxwaEVx9WuQQRxfFVx+CdkxAVT3Oe9u0Z2cDKgqVQlYVmzjbSGMYbTt8lKiKzxbFjWR7lOhc6MQQU2BgbQB0RG7GdA9gHU6HhRZCaaeQ41Lodzx4QfUCEBMCoITQK60g2eS2ASZ1kbj5TgSJhXlSXzuviL+pCl23NRNXjCGcN1+kb2rlTfhAYcRvaeiUGb7tG7VRiMAFI6AqKV96iBB2dswyosrI3k/CgIEhlgITy2qa098gS1HBoRw18IwJg6hJlCDTuAwwGnqDPJNxa7JCdRdFY/lqc8xMunKlqpFMHyiXh56Rckm0UJlUg5Kkid7NW7r+wFlYSqRD4cIZakVQj8/raxSEWIvxYVeU+oMFks7YFJ6lPFb6EgUtP8HWupkLDlU1ui1lNWSEanr3e3vgKsSeYEPNLGGuX02kmEopRfG9VQthJdxWnzmjko2i1E+/CWarOcP9je/c4= X-OriginatorOrg: garmin.com X-MS-Exchange-CrossTenant-OriginalArrivalTime: 15 May 2020 15:24:00.4392 (UTC) X-MS-Exchange-CrossTenant-Network-Message-Id: 067c2890-a865-47dc-8f3b-08d7f8e3fe64 X-MS-Exchange-CrossTenant-Id: 38d0d425-ba52-4c0a-a03e-2a65c8e82e2d X-MS-Exchange-CrossTenant-OriginalAttributedTenantConnectingIp: TenantId=38d0d425-ba52-4c0a-a03e-2a65c8e82e2d;Ip=[204.77.163.244];Helo=[edgetransport.garmin.com] X-MS-Exchange-CrossTenant-FromEntityHeader: HybridOnPrem X-MS-Exchange-Transport-CrossTenantHeadersStamped: DM6PR04MB4154 Sender: sparclinux-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: sparclinux@vger.kernel.org The close-on-fork flag causes the file descriptor to be closed atomically in the child process before the child process returns from fork(). Implement this feature and provide a method to get/set the close-on-fork flag using fcntl(2). This functionality was approved by the Austin Common Standards Revision Group for inclusion in the next revision of the POSIX standard (see issue 1318 in the Austin Group Defect Tracker). If clone(2) is used to create a child process and the CLONE_FILES flag is set, then both processes will share the table of file descriptors and the state of the close-on-fork flag for any individual file descriptor. If unshare(2) is later used to stop sharing the file descriptor table, then any file descriptor with the close-on-fork flag set will be closed in the process that calls unshare(2). execve(2) also causes the file descriptor table to be unshared, so any file descriptor with the close-on-fork flag set will be closed in the process that calls execve(2). Co-developed-by: Changli Gao Signed-off-by: Changli Gao Signed-off-by: Nate Karstens --- fs/fcntl.c | 4 +- fs/file.c | 64 ++++++++++++++++++++++++-- include/linux/fdtable.h | 7 +++ include/linux/file.h | 2 + include/uapi/asm-generic/fcntl.h | 5 +- tools/include/uapi/asm-generic/fcntl.h | 5 +- 6 files changed, 77 insertions(+), 10 deletions(-) diff --git a/fs/fcntl.c b/fs/fcntl.c index 2e4c0fa2074b..913b0cb70804 100644 --- a/fs/fcntl.c +++ b/fs/fcntl.c @@ -334,11 +334,11 @@ static long do_fcntl(int fd, unsigned int cmd, unsigned long arg, err = f_dupfd(arg, filp, O_CLOEXEC); break; case F_GETFD: - err = get_close_on_exec(fd) ? FD_CLOEXEC : 0; + err = f_getfd(fd); break; case F_SETFD: err = 0; - set_close_on_exec(fd, arg & FD_CLOEXEC); + f_setfd(fd, arg); break; case F_GETFL: err = filp->f_flags; diff --git a/fs/file.c b/fs/file.c index c8a4e4c86e55..81194349e980 100644 --- a/fs/file.c +++ b/fs/file.c @@ -47,7 +47,7 @@ static void free_fdtable_rcu(struct rcu_head *rcu) * spinlock held for write. */ static void copy_fd_bitmaps(struct fdtable *nfdt, struct fdtable *ofdt, - unsigned int count) + unsigned int count, bool copy_cof) { unsigned int cpy, set; @@ -58,6 +58,13 @@ static void copy_fd_bitmaps(struct fdtable *nfdt, struct fdtable *ofdt, memcpy(nfdt->close_on_exec, ofdt->close_on_exec, cpy); memset((char *)nfdt->close_on_exec + cpy, 0, set); + if (copy_cof) { + memcpy(nfdt->close_on_fork, ofdt->close_on_fork, cpy); + memset((char *)nfdt->close_on_fork + cpy, 0, set); + } else { + memset((char *)nfdt->close_on_fork, 0, cpy + set); + } + cpy = BITBIT_SIZE(count); set = BITBIT_SIZE(nfdt->max_fds) - cpy; memcpy(nfdt->full_fds_bits, ofdt->full_fds_bits, cpy); @@ -79,7 +86,7 @@ static void copy_fdtable(struct fdtable *nfdt, struct fdtable *ofdt) memcpy(nfdt->fd, ofdt->fd, cpy); memset((char *)nfdt->fd + cpy, 0, set); - copy_fd_bitmaps(nfdt, ofdt, ofdt->max_fds); + copy_fd_bitmaps(nfdt, ofdt, ofdt->max_fds, true); } static struct fdtable * alloc_fdtable(unsigned int nr) @@ -118,7 +125,7 @@ static struct fdtable * alloc_fdtable(unsigned int nr) fdt->fd = data; data = kvmalloc(max_t(size_t, - 2 * nr / BITS_PER_BYTE + BITBIT_SIZE(nr), L1_CACHE_BYTES), + 3 * nr / BITS_PER_BYTE + BITBIT_SIZE(nr), L1_CACHE_BYTES), GFP_KERNEL_ACCOUNT); if (!data) goto out_arr; @@ -126,6 +133,8 @@ static struct fdtable * alloc_fdtable(unsigned int nr) data += nr / BITS_PER_BYTE; fdt->close_on_exec = data; data += nr / BITS_PER_BYTE; + fdt->close_on_fork = data; + data += nr / BITS_PER_BYTE; fdt->full_fds_bits = data; return fdt; @@ -236,6 +245,17 @@ static inline void __clear_close_on_exec(unsigned int fd, struct fdtable *fdt) __clear_bit(fd, fdt->close_on_exec); } +static inline void __set_close_on_fork(unsigned int fd, struct fdtable *fdt) +{ + __set_bit(fd, fdt->close_on_fork); +} + +static inline void __clear_close_on_fork(unsigned int fd, struct fdtable *fdt) +{ + if (test_bit(fd, fdt->close_on_fork)) + __clear_bit(fd, fdt->close_on_fork); +} + static inline void __set_open_fd(unsigned int fd, struct fdtable *fdt) { __set_bit(fd, fdt->open_fds); @@ -290,6 +310,7 @@ struct files_struct *dup_fd(struct files_struct *oldf, int *errorp) new_fdt = &newf->fdtab; new_fdt->max_fds = NR_OPEN_DEFAULT; new_fdt->close_on_exec = newf->close_on_exec_init; + new_fdt->close_on_fork = newf->close_on_fork_init; new_fdt->open_fds = newf->open_fds_init; new_fdt->full_fds_bits = newf->full_fds_bits_init; new_fdt->fd = &newf->fd_array[0]; @@ -330,13 +351,17 @@ struct files_struct *dup_fd(struct files_struct *oldf, int *errorp) open_files = count_open_files(old_fdt); } - copy_fd_bitmaps(new_fdt, old_fdt, open_files); + copy_fd_bitmaps(new_fdt, old_fdt, open_files, false); old_fds = old_fdt->fd; new_fds = new_fdt->fd; for (i = open_files; i != 0; i--) { struct file *f = *old_fds++; + + if (close_on_fork(open_files - i, old_fdt)) + f = NULL; + if (f) { get_file(f); } else { @@ -453,6 +478,7 @@ struct files_struct init_files = { .max_fds = NR_OPEN_DEFAULT, .fd = &init_files.fd_array[0], .close_on_exec = init_files.close_on_exec_init, + .close_on_fork = init_files.close_on_fork_init, .open_fds = init_files.open_fds_init, .full_fds_bits = init_files.full_fds_bits_init, }, @@ -840,6 +866,36 @@ void __f_unlock_pos(struct file *f) * file count (done either by fdget() or by fork()). */ +void f_setfd(unsigned int fd, int flags) +{ + struct files_struct *files = current->files; + struct fdtable *fdt; + spin_lock(&files->file_lock); + fdt = files_fdtable(files); + if (flags & FD_CLOEXEC) + __set_close_on_exec(fd, fdt); + else + __clear_close_on_exec(fd, fdt); + if (flags & FD_CLOFORK) + __set_close_on_fork(fd, fdt); + else + __clear_close_on_fork(fd, fdt); + spin_unlock(&files->file_lock); +} + +int f_getfd(unsigned int fd) +{ + struct files_struct *files = current->files; + struct fdtable *fdt; + int flags; + rcu_read_lock(); + fdt = files_fdtable(files); + flags = (close_on_exec(fd, fdt) ? FD_CLOEXEC : 0) | + (close_on_fork(fd, fdt) ? FD_CLOFORK : 0); + rcu_read_unlock(); + return flags; +} + void set_close_on_exec(unsigned int fd, int flag) { struct files_struct *files = current->files; diff --git a/include/linux/fdtable.h b/include/linux/fdtable.h index f07c55ea0c22..61c551947fa3 100644 --- a/include/linux/fdtable.h +++ b/include/linux/fdtable.h @@ -27,6 +27,7 @@ struct fdtable { unsigned int max_fds; struct file __rcu **fd; /* current fd array */ unsigned long *close_on_exec; + unsigned long *close_on_fork; unsigned long *open_fds; unsigned long *full_fds_bits; struct rcu_head rcu; @@ -37,6 +38,11 @@ static inline bool close_on_exec(unsigned int fd, const struct fdtable *fdt) return test_bit(fd, fdt->close_on_exec); } +static inline bool close_on_fork(unsigned int fd, const struct fdtable *fdt) +{ + return test_bit(fd, fdt->close_on_fork); +} + static inline bool fd_is_open(unsigned int fd, const struct fdtable *fdt) { return test_bit(fd, fdt->open_fds); @@ -61,6 +67,7 @@ struct files_struct { spinlock_t file_lock ____cacheline_aligned_in_smp; unsigned int next_fd; unsigned long close_on_exec_init[1]; + unsigned long close_on_fork_init[1]; unsigned long open_fds_init[1]; unsigned long full_fds_bits_init[1]; struct file __rcu * fd_array[NR_OPEN_DEFAULT]; diff --git a/include/linux/file.h b/include/linux/file.h index 142d102f285e..0ee15ee24010 100644 --- a/include/linux/file.h +++ b/include/linux/file.h @@ -83,6 +83,8 @@ static inline void fdput_pos(struct fd f) extern int f_dupfd(unsigned int from, struct file *file, unsigned flags); extern int replace_fd(unsigned fd, struct file *file, unsigned flags); +extern int f_getfd(unsigned int fd); +extern void f_setfd(unsigned int fd, int flags); extern void set_close_on_exec(unsigned int fd, int flag); extern bool get_close_on_exec(unsigned int fd); extern int __get_unused_fd_flags(unsigned flags, unsigned long nofile); diff --git a/include/uapi/asm-generic/fcntl.h b/include/uapi/asm-generic/fcntl.h index 9dc0bf0c5a6e..0cb7199a7743 100644 --- a/include/uapi/asm-generic/fcntl.h +++ b/include/uapi/asm-generic/fcntl.h @@ -98,8 +98,8 @@ #endif #define F_DUPFD 0 /* dup */ -#define F_GETFD 1 /* get close_on_exec */ -#define F_SETFD 2 /* set/clear close_on_exec */ +#define F_GETFD 1 /* get close_on_exec & close_on_fork */ +#define F_SETFD 2 /* set/clear close_on_exec & close_on_fork */ #define F_GETFL 3 /* get file->f_flags */ #define F_SETFL 4 /* set file->f_flags */ #ifndef F_GETLK @@ -160,6 +160,7 @@ struct f_owner_ex { /* for F_[GET|SET]FL */ #define FD_CLOEXEC 1 /* actually anything with low bit set goes */ +#define FD_CLOFORK 2 /* for posix fcntl() and lockf() */ #ifndef F_RDLCK diff --git a/tools/include/uapi/asm-generic/fcntl.h b/tools/include/uapi/asm-generic/fcntl.h index ac190958c981..e04a00fecb4a 100644 --- a/tools/include/uapi/asm-generic/fcntl.h +++ b/tools/include/uapi/asm-generic/fcntl.h @@ -97,8 +97,8 @@ #endif #define F_DUPFD 0 /* dup */ -#define F_GETFD 1 /* get close_on_exec */ -#define F_SETFD 2 /* set/clear close_on_exec */ +#define F_GETFD 1 /* get close_on_exec & close_on_fork */ +#define F_SETFD 2 /* set/clear close_on_exec & close_on_fork */ #define F_GETFL 3 /* get file->f_flags */ #define F_SETFL 4 /* set file->f_flags */ #ifndef F_GETLK @@ -159,6 +159,7 @@ struct f_owner_ex { /* for F_[GET|SET]FL */ #define FD_CLOEXEC 1 /* actually anything with low bit set goes */ +#define FD_CLOFORK 2 /* for posix fcntl() and lockf() */ #ifndef F_RDLCK From patchwork Fri May 15 15:23:19 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Nate Karstens X-Patchwork-Id: 1291420 X-Patchwork-Delegate: davem@davemloft.net Return-Path: X-Original-To: patchwork-incoming@ozlabs.org Delivered-To: patchwork-incoming@ozlabs.org Authentication-Results: ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=vger.kernel.org (client-ip=23.128.96.18; helo=vger.kernel.org; envelope-from=sparclinux-owner@vger.kernel.org; receiver=) Authentication-Results: ozlabs.org; dmarc=pass (p=quarantine dis=none) header.from=garmin.com Authentication-Results: ozlabs.org; dkim=pass (2048-bit key; unprotected) header.d=garmin.com header.i=@garmin.com header.a=rsa-sha256 header.s=selector1 header.b=I1vGgzFi; dkim-atps=neutral Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by ozlabs.org (Postfix) with ESMTP id 49Nsdc4zmmz9sVw for ; Sat, 16 May 2020 01:24:20 +1000 (AEST) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1727976AbgEOPYO (ORCPT ); Fri, 15 May 2020 11:24:14 -0400 Received: from mail-dm6nam12on2130.outbound.protection.outlook.com ([40.107.243.130]:13665 "EHLO NAM12-DM6-obe.outbound.protection.outlook.com" rhost-flags-OK-OK-OK-FAIL) by vger.kernel.org with ESMTP id S1727801AbgEOPYG (ORCPT ); Fri, 15 May 2020 11:24:06 -0400 ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=SpCzqUyVeV2MvPjtPnTHWxXpInR2ZxrpN3w8YrKdU8ADXrHViGAST2BvR5SfOKL7FhzJX92pwRt/pur2ET0XZLLUtFHL0Wjj1UaTc5oUOVK9/RQyVc7qa9kHy8V6trBt7vQ8lKwPwsIm2Y1pAr5Qhp51Vz0wEdbRlhyubWccjvVF+U24mtrurL0PN/DffwX+dZWOx5oJQs29AH3Jd/1CLtL2ZLx74isuoqHrGlrDvgQ0tezd/KqbczyPAoHrr1wBeH9Az/2W3WFiMoODZcmqdrn9t9bx1Ovt+Lsnl91x4NymudazFie91Pf4XcWjyimKLvgD3htX+LbDaWGe0RmFcw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=microsoft.com; s=arcselector9901; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck; bh=P6T+uyYMiAVhFTnmHkr8vkLx5ezWonx48r5TGpN5qqI=; b=fwAxDaz5qKMhm2DjNcx/bjGNV7UqLJFqvq8bBDPLvVQFSL6UhE3fbnyv/a6Nir1bX4xLpL19VSGrCJYr6DuMY7IhN6Vc6ZcP/DrjO2bno0rRX7uIqRoYOA2wtCKWnslxltcDT0rRMjQg+xrKCqvX7fLoOWDLKpjtG5OC4vSDYdszFYZPfbVCLxIliGtGkwRwBt5FO8TOVEMP/rSzLvwms2FhqCbntbRtcQslJAc91a6YxashWnxBUx9DK/yEWoobT2subsqUnmXmwmXTAx+IN60qB1AFJFTIM4mQ+ZPTdBaMp7yvdxGMxNZzsvg5WkeAYpu9HpHE1QwH26baacOyuw== ARC-Authentication-Results: i=1; mx.microsoft.com 1; spf=pass (sender ip is 204.77.163.244) smtp.rcpttodomain=zeniv.linux.org.uk smtp.mailfrom=garmin.com; dmarc=pass (p=quarantine sp=quarantine pct=100) action=none header.from=garmin.com; dkim=none (message not signed); arc=none DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=garmin.com; s=selector1; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck; bh=P6T+uyYMiAVhFTnmHkr8vkLx5ezWonx48r5TGpN5qqI=; b=I1vGgzFiGU/0aLcS3d/oYtnPnxb26RqNmWF3xMLGgilO5VGa0DNbecRNC9CbjRV+Rctaq4ehfF+DWXed3QeYlrTbjJbfo1rr4CPWhE2o3X3ovNg1ONAHgPeaC9OnkYbmcKorMsb2GFqFeNSqKjq43JQ9L7OFIEbrjshHgrNQH4Vwz0P18WZifgOmcTqePAxEHpbHJKlfJxOBKsn6PRG7/rwvkkpBaYjfbbRCf5rVeD/VdxPPS7vzwAT7TEcNrItFNebh+CtOnID4Y0aIDjkdSOt2z8I/wVmh1hRmbC2aUUhJ+HhWp3NfvYJegiLcX5QZhGLEG0E36h7PJne/9sUy8w== Received: from BN6PR11CA0044.namprd11.prod.outlook.com (2603:10b6:404:4b::30) by DM6PR04MB5100.namprd04.prod.outlook.com (2603:10b6:5:16::10) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.2979.33; Fri, 15 May 2020 15:24:02 +0000 Received: from BN7NAM10FT028.eop-nam10.prod.protection.outlook.com (2603:10b6:404:4b:cafe::3) by BN6PR11CA0044.outlook.office365.com (2603:10b6:404:4b::30) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.3000.20 via Frontend Transport; Fri, 15 May 2020 15:24:02 +0000 Authentication-Results: spf=pass (sender IP is 204.77.163.244) smtp.mailfrom=garmin.com; zeniv.linux.org.uk; dkim=none (message not signed) header.d=none;zeniv.linux.org.uk; dmarc=pass action=none header.from=garmin.com; Received-SPF: Pass (protection.outlook.com: domain of garmin.com designates 204.77.163.244 as permitted sender) receiver=protection.outlook.com; client-ip=204.77.163.244; helo=edgetransport.garmin.com; Received: from edgetransport.garmin.com (204.77.163.244) by BN7NAM10FT028.mail.protection.outlook.com (10.13.156.237) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.3000.19 via Frontend Transport; Fri, 15 May 2020 15:24:01 +0000 Received: from OLAWPA-EXMB7.ad.garmin.com (10.5.144.21) by olawpa-edge2.garmin.com (10.60.4.35) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_CBC_SHA256) id 15.1.1466.3; Fri, 15 May 2020 10:23:58 -0500 Received: from ola-d01c000-vm.ad.garmin.com (10.5.84.15) by OLAWPA-EXMB7.ad.garmin.com (10.5.144.21) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_CBC_SHA256_P256) id 15.1.1913.5; Fri, 15 May 2020 10:23:59 -0500 From: Nate Karstens To: Alexander Viro , Jeff Layton , "J. Bruce Fields" , Arnd Bergmann , Richard Henderson , Ivan Kokshaysky , Matt Turner , "James E.J. Bottomley" , Helge Deller , "David S. Miller" , Jakub Kicinski , Eric Dumazet , David Laight , , , , , , , CC: Changli Gao , Nate Karstens Subject: [PATCH v2 2/4] fs: Add O_CLOFORK flag for open(2) and dup3(2) Date: Fri, 15 May 2020 10:23:19 -0500 Message-ID: <20200515152321.9280-3-nate.karstens@garmin.com> X-Mailer: git-send-email 2.26.1 In-Reply-To: <20200515152321.9280-1-nate.karstens@garmin.com> References: <20200515152321.9280-1-nate.karstens@garmin.com> MIME-Version: 1.0 X-ClientProxiedBy: OLAWPA-EXMB3.ad.garmin.com (10.5.144.15) To OLAWPA-EXMB7.ad.garmin.com (10.5.144.21) X-TM-AS-Product-Ver: SMEX-12.5.0.1300-8.5.1020-25422.000 X-TM-AS-Result: No-9.399500-8.000000-10 X-TMASE-MatchedRID: g25QWLQyM7v1HKFnt7/e8tKhw1CGAxrIlHLUcNM85doAZTQQTIkkc93N NJQDizxeGDXccV5w1UP1q35E6lDQr2+4O3SBmLlW9u1rQ4BgXPIBmf/gD11vZAaYevV4zG3ZQBz oPKhLashZ3hT8koiLOx4fZrHGL7yoEVfyWRZcVuVZMZ6MZ0H1UhACJh4BWAPePTublrdV/SPAgD 8QYQcBsjk4XrS69X2i0/NbBMSkGddoWWTS0CIqzlgUnyU84hcfquFC73XPA2ffc2Xd6VJ+ym9Ih irTclUbTnj5SlaoRXUaH2v8HV+LCgzyMxeMEX6wFEUknJ/kEl7dB/CxWTRRu25FeHtsUoHuXl// B5rrV1RVFUQEIC0/f+wk1G5ssoeQZd0ZOVOHZfRYKVgm72vjJg== X-TM-AS-User-Approved-Sender: No X-TM-AS-User-Blocked-Sender: No X-TMASE-Result: 10--9.399500-8.000000 X-TMASE-Version: SMEX-12.5.0.1300-8.5.1020-25422.000 X-EOPAttributedMessage: 0 X-MS-Office365-Filtering-HT: Tenant X-Forefront-Antispam-Report: CIP:204.77.163.244;CTRY:US;LANG:en;SCL:1;SRV:;IPV:CAL;SFV:NSPM;H:edgetransport.garmin.com;PTR:extedge.garmin.com;CAT:NONE;SFTY:;SFS:(39860400002)(376002)(346002)(396003)(136003)(46966005)(7636003)(36756003)(107886003)(1076003)(82310400002)(2906002)(54906003)(356005)(478600001)(70586007)(110136005)(70206006)(186003)(44832011)(336012)(8936002)(2616005)(8676002)(7696005)(26005)(5660300002)(6666004)(4326008)(426003)(316002)(86362001)(7416002)(82740400003)(47076004)(921003);DIR:OUT;SFP:1102; X-MS-PublicTrafficType: Email X-MS-Office365-Filtering-Correlation-Id: fecd949f-3720-43d5-58c1-08d7f8e3ff2a X-MS-TrafficTypeDiagnostic: DM6PR04MB5100: X-Microsoft-Antispam-PRVS: X-MS-Oob-TLC-OOBClassifiers: OLM:6790; X-Forefront-PRVS: 04041A2886 X-MS-Exchange-SenderADCheck: 1 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: isZu81VyAfRY+lWWSVPUDfl/Tmz7AWp5v1jxqT9bx4yLZ+kMYkZgDxR2oKI524TqHwZ86G53Cf0h6tcL1w2TUhQihdZee6HpT8kVEf/CZeLJW6U3tdZ5qft73Bu7OXQFu+/5yUvTDH2w4kMBt6I4efgDw41fJ3HHx5bzVnUNsS/9x8Z3ok/gT6iedlctSNinxj+w0ZVocGVYSoJ10k6Wqb43jk0eqByFi4T52qeieNprz4oAoz9l24YZfHaJLT7M5oHZLi8TgyFRhFHUYok3XiUyHRskdOG2vuklgRTIRgiH/NGirjBkZiQSEseUWMGLM7MF6RxYHTUk2oKDLY0ZotkKMKmolCjFE6DMHF+IrHHpJeaOjvWE39FHTvG21VH5IwhdlCWRJ6bhto0luBr38vNxq7JnkG1lsFPRPkQ38uUEOdXUYTign1P085L1t5hZpPi1TqiIPHSng4VSqCj4r9Pq/SJeKvx/KyTBgXXECTakWr31+ftQ5xfd/J7Nrd59p7GsHeJ/Jxw821/LbQhG/A== X-OriginatorOrg: garmin.com X-MS-Exchange-CrossTenant-OriginalArrivalTime: 15 May 2020 15:24:01.7355 (UTC) X-MS-Exchange-CrossTenant-Network-Message-Id: fecd949f-3720-43d5-58c1-08d7f8e3ff2a X-MS-Exchange-CrossTenant-Id: 38d0d425-ba52-4c0a-a03e-2a65c8e82e2d X-MS-Exchange-CrossTenant-OriginalAttributedTenantConnectingIp: TenantId=38d0d425-ba52-4c0a-a03e-2a65c8e82e2d;Ip=[204.77.163.244];Helo=[edgetransport.garmin.com] X-MS-Exchange-CrossTenant-FromEntityHeader: HybridOnPrem X-MS-Exchange-Transport-CrossTenantHeadersStamped: DM6PR04MB5100 Sender: sparclinux-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: sparclinux@vger.kernel.org Add the O_CLOFORK flag to open(2) and dup3(2) to automatically set the close-on-fork flag in the new file descriptor, saving a separate call to fcntl(2). Co-developed-by: Changli Gao Signed-off-by: Changli Gao Signed-off-by: Nate Karstens --- arch/alpha/include/uapi/asm/fcntl.h | 2 ++ arch/parisc/include/uapi/asm/fcntl.h | 39 +++++++++++++------------- arch/sparc/include/uapi/asm/fcntl.h | 1 + fs/fcntl.c | 2 +- fs/file.c | 10 ++++++- include/linux/fcntl.h | 2 +- include/uapi/asm-generic/fcntl.h | 4 +++ tools/include/uapi/asm-generic/fcntl.h | 4 +++ 8 files changed, 42 insertions(+), 22 deletions(-) diff --git a/arch/alpha/include/uapi/asm/fcntl.h b/arch/alpha/include/uapi/asm/fcntl.h index 50bdc8e8a271..fbab69b15f7f 100644 --- a/arch/alpha/include/uapi/asm/fcntl.h +++ b/arch/alpha/include/uapi/asm/fcntl.h @@ -35,6 +35,8 @@ #define O_PATH 040000000 #define __O_TMPFILE 0100000000 +#define O_CLOFORK 0200000000 /* set close_on_fork */ + #define F_GETLK 7 #define F_SETLK 8 #define F_SETLKW 9 diff --git a/arch/parisc/include/uapi/asm/fcntl.h b/arch/parisc/include/uapi/asm/fcntl.h index 03ce20e5ad7d..8f5989e75b05 100644 --- a/arch/parisc/include/uapi/asm/fcntl.h +++ b/arch/parisc/include/uapi/asm/fcntl.h @@ -2,26 +2,27 @@ #ifndef _PARISC_FCNTL_H #define _PARISC_FCNTL_H -#define O_APPEND 000000010 -#define O_BLKSEEK 000000100 /* HPUX only */ -#define O_CREAT 000000400 /* not fcntl */ -#define O_EXCL 000002000 /* not fcntl */ -#define O_LARGEFILE 000004000 -#define __O_SYNC 000100000 +#define O_APPEND 0000000010 +#define O_BLKSEEK 0000000100 /* HPUX only */ +#define O_CREAT 0000000400 /* not fcntl */ +#define O_EXCL 0000002000 /* not fcntl */ +#define O_LARGEFILE 0000004000 +#define __O_SYNC 0000100000 #define O_SYNC (__O_SYNC|O_DSYNC) -#define O_NONBLOCK 000200004 /* HPUX has separate NDELAY & NONBLOCK */ -#define O_NOCTTY 000400000 /* not fcntl */ -#define O_DSYNC 001000000 /* HPUX only */ -#define O_RSYNC 002000000 /* HPUX only */ -#define O_NOATIME 004000000 -#define O_CLOEXEC 010000000 /* set close_on_exec */ - -#define O_DIRECTORY 000010000 /* must be a directory */ -#define O_NOFOLLOW 000000200 /* don't follow links */ -#define O_INVISIBLE 004000000 /* invisible I/O, for DMAPI/XDSM */ - -#define O_PATH 020000000 -#define __O_TMPFILE 040000000 +#define O_NONBLOCK 0000200004 /* HPUX has separate NDELAY & NONBLOCK */ +#define O_NOCTTY 0000400000 /* not fcntl */ +#define O_DSYNC 0001000000 /* HPUX only */ +#define O_RSYNC 0002000000 /* HPUX only */ +#define O_NOATIME 0004000000 +#define O_CLOEXEC 0010000000 /* set close_on_exec */ + +#define O_DIRECTORY 0000010000 /* must be a directory */ +#define O_NOFOLLOW 0000000200 /* don't follow links */ +#define O_INVISIBLE 0004000000 /* invisible I/O, for DMAPI/XDSM */ + +#define O_PATH 0020000000 +#define __O_TMPFILE 0040000000 +#define O_CLOFORK 0100000000 #define F_GETLK64 8 #define F_SETLK64 9 diff --git a/arch/sparc/include/uapi/asm/fcntl.h b/arch/sparc/include/uapi/asm/fcntl.h index 67dae75e5274..d631ea13bac3 100644 --- a/arch/sparc/include/uapi/asm/fcntl.h +++ b/arch/sparc/include/uapi/asm/fcntl.h @@ -37,6 +37,7 @@ #define O_PATH 0x1000000 #define __O_TMPFILE 0x2000000 +#define O_CLOFORK 0x4000000 #define F_GETOWN 5 /* for sockets. */ #define F_SETOWN 6 /* for sockets. */ diff --git a/fs/fcntl.c b/fs/fcntl.c index 913b0cb70804..40af2a48702b 100644 --- a/fs/fcntl.c +++ b/fs/fcntl.c @@ -1033,7 +1033,7 @@ static int __init fcntl_init(void) * Exceptions: O_NONBLOCK is a two bit define on parisc; O_NDELAY * is defined as O_NONBLOCK on some platforms and not on others. */ - BUILD_BUG_ON(21 - 1 /* for O_RDONLY being 0 */ != + BUILD_BUG_ON(22 - 1 /* for O_RDONLY being 0 */ != HWEIGHT32( (VALID_OPEN_FLAGS & ~(O_NONBLOCK | O_NDELAY)) | __FMODE_EXEC | __FMODE_NONOTIFY)); diff --git a/fs/file.c b/fs/file.c index 81194349e980..4a1b84eecec6 100644 --- a/fs/file.c +++ b/fs/file.c @@ -547,6 +547,10 @@ int __alloc_fd(struct files_struct *files, __set_close_on_exec(fd, fdt); else __clear_close_on_exec(fd, fdt); + if (flags & O_CLOFORK) + __set_close_on_fork(fd, fdt); + else + __clear_close_on_fork(fd, fdt); error = fd; #if 1 /* Sanity check */ @@ -953,6 +957,10 @@ __releases(&files->file_lock) __set_close_on_exec(fd, fdt); else __clear_close_on_exec(fd, fdt); + if (flags & O_CLOFORK) + __set_close_on_fork(fd, fdt); + else + __clear_close_on_fork(fd, fdt); spin_unlock(&files->file_lock); if (tofree) @@ -993,7 +1001,7 @@ static int ksys_dup3(unsigned int oldfd, unsigned int newfd, int flags) struct file *file; struct files_struct *files = current->files; - if ((flags & ~O_CLOEXEC) != 0) + if ((flags & ~(O_CLOEXEC | O_CLOFORK)) != 0) return -EINVAL; if (unlikely(oldfd == newfd)) diff --git a/include/linux/fcntl.h b/include/linux/fcntl.h index 7bcdcf4f6ab2..cd4c625647db 100644 --- a/include/linux/fcntl.h +++ b/include/linux/fcntl.h @@ -10,7 +10,7 @@ (O_RDONLY | O_WRONLY | O_RDWR | O_CREAT | O_EXCL | O_NOCTTY | O_TRUNC | \ O_APPEND | O_NDELAY | O_NONBLOCK | O_NDELAY | __O_SYNC | O_DSYNC | \ FASYNC | O_DIRECT | O_LARGEFILE | O_DIRECTORY | O_NOFOLLOW | \ - O_NOATIME | O_CLOEXEC | O_PATH | __O_TMPFILE) + O_NOATIME | O_CLOEXEC | O_PATH | __O_TMPFILE | O_CLOFORK) /* List of all valid flags for the how->upgrade_mask argument: */ #define VALID_UPGRADE_FLAGS \ diff --git a/include/uapi/asm-generic/fcntl.h b/include/uapi/asm-generic/fcntl.h index 0cb7199a7743..165a0736a3aa 100644 --- a/include/uapi/asm-generic/fcntl.h +++ b/include/uapi/asm-generic/fcntl.h @@ -89,6 +89,10 @@ #define __O_TMPFILE 020000000 #endif +#ifndef O_CLOFORK +#define O_CLOFORK 040000000 /* set close_on_fork */ +#endif + /* a horrid kludge trying to make sure that this will fail on old kernels */ #define O_TMPFILE (__O_TMPFILE | O_DIRECTORY) #define O_TMPFILE_MASK (__O_TMPFILE | O_DIRECTORY | O_CREAT) diff --git a/tools/include/uapi/asm-generic/fcntl.h b/tools/include/uapi/asm-generic/fcntl.h index e04a00fecb4a..69d8a000ec65 100644 --- a/tools/include/uapi/asm-generic/fcntl.h +++ b/tools/include/uapi/asm-generic/fcntl.h @@ -88,6 +88,10 @@ #define __O_TMPFILE 020000000 #endif +#ifndef O_CLOFORK +#define O_CLOFORK 040000000 /* set close_on_fork */ +#endif + /* a horrid kludge trying to make sure that this will fail on old kernels */ #define O_TMPFILE (__O_TMPFILE | O_DIRECTORY) #define O_TMPFILE_MASK (__O_TMPFILE | O_DIRECTORY | O_CREAT) From patchwork Fri May 15 15:23:20 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Nate Karstens X-Patchwork-Id: 1291417 X-Patchwork-Delegate: davem@davemloft.net Return-Path: X-Original-To: patchwork-incoming@ozlabs.org Delivered-To: patchwork-incoming@ozlabs.org Authentication-Results: ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=vger.kernel.org (client-ip=23.128.96.18; helo=vger.kernel.org; envelope-from=sparclinux-owner@vger.kernel.org; receiver=) Authentication-Results: ozlabs.org; dmarc=pass (p=quarantine dis=none) header.from=garmin.com Authentication-Results: ozlabs.org; dkim=pass (2048-bit key; unprotected) header.d=garmin.com header.i=@garmin.com header.a=rsa-sha256 header.s=selector1 header.b=k1K/A5BF; dkim-atps=neutral Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by ozlabs.org (Postfix) with ESMTP id 49NsdX2Dhkz9sW4 for ; Sat, 16 May 2020 01:24:16 +1000 (AEST) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1727970AbgEOPYO (ORCPT ); Fri, 15 May 2020 11:24:14 -0400 Received: from mail-dm6nam10on2118.outbound.protection.outlook.com ([40.107.93.118]:49121 "EHLO NAM10-DM6-obe.outbound.protection.outlook.com" rhost-flags-OK-OK-OK-FAIL) by vger.kernel.org with ESMTP id S1726250AbgEOPYG (ORCPT ); Fri, 15 May 2020 11:24:06 -0400 ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=KEOLUHMa2UoJi0CEe2LxxdHB5IMJ4t88cPDIRObJbEtymzC3VnTzySi71FSCm8/OhWlFUD8lg2gAuBxJPHdN1jKr2X9W9qgGcI9Ll2LtmBGtftORXVVxF/dxfADTTBKe65VCq3Oofcq8fJltBvjZHhcGZwOlVd2mTF0cnXABqaZu3RvyVVTzIlicYNtqyIJb0MwJkz6Tew/Ho2Q1Hok2NdF0RKdQEkzhGs14BXKzNf+l4asgisM7Ecn2akCmOo9I+RcYq22kApXqO2ZxNEXl+wbT2JIYsJp+YuviPxZxnNtMgyFRX2IxfEa6ve/TcIGGqfCi6dNYsgS95etYi0vzbw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=microsoft.com; s=arcselector9901; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck; bh=QQjMj+RVOA3gQhcB59BEGhR0ZVZ+DwBiLoZN26WeP4M=; b=EnQ7F8I84B1XsrDk63SJa357gqcbxGVl5v5Lci6yN+wEsFDBOk+mTnu1zFZ2vZg2BARJkG0Z9ifDACBamySlpskckp3DHOVK2hBw/ianuD3qADgpN+DkmnG1TqOF32DOwVjGKwocqY4QOuCJrk+DN+63eBEeOmYGmy17+aF4nvVg1AGAgrZtifrFaczREBDc4cTeJMflAbhatvmBcX5vdq1imRdvR8Sdq9KovjmgBD4REdjEMXqNS54XYClcFmms2z1Cs2mDuIwS8bsAYkrSU2wC9AMXknMK7RuAekeRfpwGxmHi7Hyc2Y1nSHXSvnOBfk0AhfdLjRgrqqUzBqdzjg== ARC-Authentication-Results: i=1; mx.microsoft.com 1; spf=pass (sender ip is 204.77.163.244) smtp.rcpttodomain=zeniv.linux.org.uk smtp.mailfrom=garmin.com; dmarc=pass (p=quarantine sp=quarantine pct=100) action=none header.from=garmin.com; dkim=none (message not signed); arc=none DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=garmin.com; s=selector1; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck; bh=QQjMj+RVOA3gQhcB59BEGhR0ZVZ+DwBiLoZN26WeP4M=; b=k1K/A5BFIPA6wU8Lo48HDz6BHwBdHsIzMjinzCgUvwl59wiBoMpEdaOSCoPcVbWz+RlxH/7gERj2HhmZzRZkaY6ocb7r+sDlQSfKgxWSWSl3h7fLlvtCQFxLdD7HsrsqRHc6xtJZA8HEF6l6wsroBJ74SPTXiWteBV0iRVJk6Sg8Ppti0agvIW38+cQ4UocVmyqbWEfn5+sWOuH3381MGNYWUGUpvVmw2Npe/WOm3AQJZawO3dT7+j8iLloMCe+SWM0/r+sSw0GxgG/yj4lSnRP+PYxFOP4K8GkxRitL0xHgd8BsdxJz5V1Rs0razZB5ytjBZ1cRiJ9eco9FkYea9Q== Received: from DM5PR04CA0054.namprd04.prod.outlook.com (2603:10b6:3:ef::16) by MWHPR04MB1119.namprd04.prod.outlook.com (2603:10b6:300:72::7) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.3000.25; Fri, 15 May 2020 15:24:02 +0000 Received: from DM6NAM10FT013.eop-nam10.prod.protection.outlook.com (2603:10b6:3:ef:cafe::54) by DM5PR04CA0054.outlook.office365.com (2603:10b6:3:ef::16) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.3000.26 via Frontend Transport; Fri, 15 May 2020 15:24:02 +0000 Authentication-Results: spf=pass (sender IP is 204.77.163.244) smtp.mailfrom=garmin.com; zeniv.linux.org.uk; dkim=none (message not signed) header.d=none;zeniv.linux.org.uk; dmarc=pass action=none header.from=garmin.com; Received-SPF: Pass (protection.outlook.com: domain of garmin.com designates 204.77.163.244 as permitted sender) receiver=protection.outlook.com; client-ip=204.77.163.244; helo=edgetransport.garmin.com; Received: from edgetransport.garmin.com (204.77.163.244) by DM6NAM10FT013.mail.protection.outlook.com (10.13.152.142) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.3000.19 via Frontend Transport; Fri, 15 May 2020 15:24:02 +0000 Received: from OLAWPA-EXMB7.ad.garmin.com (10.5.144.21) by olawpa-edge1.garmin.com (10.60.4.227) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_CBC_SHA256) id 15.1.1466.3; Fri, 15 May 2020 10:23:59 -0500 Received: from ola-d01c000-vm.ad.garmin.com (10.5.84.15) by OLAWPA-EXMB7.ad.garmin.com (10.5.144.21) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_CBC_SHA256_P256) id 15.1.1913.5; Fri, 15 May 2020 10:23:59 -0500 From: Nate Karstens To: Alexander Viro , Jeff Layton , "J. Bruce Fields" , Arnd Bergmann , Richard Henderson , Ivan Kokshaysky , Matt Turner , "James E.J. Bottomley" , Helge Deller , "David S. Miller" , Jakub Kicinski , Eric Dumazet , David Laight , , , , , , , CC: Changli Gao , Nate Karstens Subject: [PATCH v2 3/4] fs: Add F_DUPFD_CLOFORK to fcntl(2) Date: Fri, 15 May 2020 10:23:20 -0500 Message-ID: <20200515152321.9280-4-nate.karstens@garmin.com> X-Mailer: git-send-email 2.26.1 In-Reply-To: <20200515152321.9280-1-nate.karstens@garmin.com> References: <20200515152321.9280-1-nate.karstens@garmin.com> MIME-Version: 1.0 X-ClientProxiedBy: OLAWPA-EXMB3.ad.garmin.com (10.5.144.15) To OLAWPA-EXMB7.ad.garmin.com (10.5.144.21) X-TM-AS-Product-Ver: SMEX-12.5.0.1300-8.5.1020-25422.000 X-TM-AS-Result: No-4.203000-8.000000-10 X-TMASE-MatchedRID: 7BIPnr8mPjQY5XJhZJs6SDCMW7zNwFaIvj5VWb6CNmV+SLLtNOiBhgml i9Nhz+dFfGzuoVn0Vs6PQi9XuOWoOHI/MxNRI7UkzNIobH2DzGEEa8g1x8eqF9uykrHhg4PdNFZ RXtDJ5V4dF/1KVDvFSVHD52u9u0z5m71ITw4wJLGeAiCmPx4NwGmRqNBHmBve38LauI2fxt4qtq 5d3cxkNS+oniWV7avzmcqybxBa2+C6QCDPhlLtQhPpmZ4cQhq+T2ylkfPFK8WScp9O5U1lNmTUl UcmTofyMAfmDr1ydimGukhCAALSJVVbZb5kmRl4XyZ6pl/oDQ1+Az0rNWZh1oK3xHwHujePaS3X XfcxpZY= X-TM-AS-User-Approved-Sender: No X-TM-AS-User-Blocked-Sender: No X-TMASE-Result: 10--4.203000-8.000000 X-TMASE-Version: SMEX-12.5.0.1300-8.5.1020-25422.000 X-EOPAttributedMessage: 0 X-MS-Office365-Filtering-HT: Tenant X-Forefront-Antispam-Report: CIP:204.77.163.244;CTRY:US;LANG:en;SCL:1;SRV:;IPV:CAL;SFV:NSPM;H:edgetransport.garmin.com;PTR:extedge.garmin.com;CAT:NONE;SFTY:;SFS:(136003)(396003)(346002)(376002)(39860400002)(46966005)(478600001)(8936002)(8676002)(5660300002)(7416002)(336012)(426003)(70586007)(44832011)(70206006)(54906003)(1076003)(2616005)(26005)(36756003)(110136005)(7696005)(186003)(316002)(6666004)(107886003)(7636003)(47076004)(82740400003)(2906002)(356005)(4326008)(86362001)(82310400002)(921003);DIR:OUT;SFP:1102; X-MS-PublicTrafficType: Email X-MS-Office365-Filtering-Correlation-Id: fe1ea777-cec6-4b25-bdf6-08d7f8e3ff5c X-MS-TrafficTypeDiagnostic: MWHPR04MB1119: X-Microsoft-Antispam-PRVS: X-MS-Oob-TLC-OOBClassifiers: OLM:4714; X-Forefront-PRVS: 04041A2886 X-MS-Exchange-SenderADCheck: 1 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: KegLR94YNgJIwrJakop+vn4lw7A96sDvjjeVEfiIAlOdRundn75LJsuVvJMoDze88+LuwKCEcY0X0PRxvI9eHWHr4tyVT2HG4PDAdaE+/404WLeTZVcX7Y0+o+YW4J8GJb6Ze7sS0yBossnuCfoSrfyAbbvW11MaWjfGIafoQ2Zv/trf2/dYlLK46qLES+H1cyyv94lAgvXP6iGqAe5529u9pz7dzBBFrO5ZDNUgsGAVI/lY3080YHsd7zW3UZEUpZe7/C6t4JDaHXtuK79JmS6e98yJaTkLkBVtDe56FvyUtX8cFH7Xmot5ESArKIhXzTGJKpyn2Ho1BhfcTzlSkQYa0B2E33iCDUKVtjHqpvibFyRMeWwIbewrwC9ON6Pw/UqC0PwN//hEwZeU+c2v0iD22Yd5vGni12yfKFDmDez7R9f6j4u1gI8/8rg1p10x9kl+FcM1W7VUd3JglBnXzqlYXUsedz+zV5TcyaUnwEEAwxhDmLfyteX5KygZHCq1VfkTG/fqXG+L8nLUmmO45w== X-OriginatorOrg: garmin.com X-MS-Exchange-CrossTenant-OriginalArrivalTime: 15 May 2020 15:24:02.0777 (UTC) X-MS-Exchange-CrossTenant-Network-Message-Id: fe1ea777-cec6-4b25-bdf6-08d7f8e3ff5c X-MS-Exchange-CrossTenant-Id: 38d0d425-ba52-4c0a-a03e-2a65c8e82e2d X-MS-Exchange-CrossTenant-OriginalAttributedTenantConnectingIp: TenantId=38d0d425-ba52-4c0a-a03e-2a65c8e82e2d;Ip=[204.77.163.244];Helo=[edgetransport.garmin.com] X-MS-Exchange-CrossTenant-FromEntityHeader: HybridOnPrem X-MS-Exchange-Transport-CrossTenantHeadersStamped: MWHPR04MB1119 Sender: sparclinux-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: sparclinux@vger.kernel.org Implement functionality for duplicating a file descriptor and having the close-on-fork flag automatically set in the new file descriptor. Signed-off-by: Nate Karstens --- fs/fcntl.c | 4 ++++ include/uapi/linux/fcntl.h | 3 +++ tools/include/uapi/linux/fcntl.h | 3 +++ 3 files changed, 10 insertions(+) diff --git a/fs/fcntl.c b/fs/fcntl.c index 40af2a48702b..e15cdd77b1df 100644 --- a/fs/fcntl.c +++ b/fs/fcntl.c @@ -333,6 +333,9 @@ static long do_fcntl(int fd, unsigned int cmd, unsigned long arg, case F_DUPFD_CLOEXEC: err = f_dupfd(arg, filp, O_CLOEXEC); break; + case F_DUPFD_CLOFORK: + err = f_dupfd(arg, filp, O_CLOFORK); + break; case F_GETFD: err = f_getfd(fd); break; @@ -437,6 +440,7 @@ static int check_fcntl_cmd(unsigned cmd) switch (cmd) { case F_DUPFD: case F_DUPFD_CLOEXEC: + case F_DUPFD_CLOFORK: case F_GETFD: case F_SETFD: case F_GETFL: diff --git a/include/uapi/linux/fcntl.h b/include/uapi/linux/fcntl.h index ca88b7bce553..9e1069ff3a22 100644 --- a/include/uapi/linux/fcntl.h +++ b/include/uapi/linux/fcntl.h @@ -55,6 +55,9 @@ #define F_GET_FILE_RW_HINT (F_LINUX_SPECIFIC_BASE + 13) #define F_SET_FILE_RW_HINT (F_LINUX_SPECIFIC_BASE + 14) +/* Create a file descriptor with FD_CLOFORK set. */ +#define F_DUPFD_CLOFORK (F_LINUX_SPECIFIC_BASE + 15) + /* * Valid hint values for F_{GET,SET}_RW_HINT. 0 is "not set", or can be * used to clear any hints previously set. diff --git a/tools/include/uapi/linux/fcntl.h b/tools/include/uapi/linux/fcntl.h index ca88b7bce553..9e1069ff3a22 100644 --- a/tools/include/uapi/linux/fcntl.h +++ b/tools/include/uapi/linux/fcntl.h @@ -55,6 +55,9 @@ #define F_GET_FILE_RW_HINT (F_LINUX_SPECIFIC_BASE + 13) #define F_SET_FILE_RW_HINT (F_LINUX_SPECIFIC_BASE + 14) +/* Create a file descriptor with FD_CLOFORK set. */ +#define F_DUPFD_CLOFORK (F_LINUX_SPECIFIC_BASE + 15) + /* * Valid hint values for F_{GET,SET}_RW_HINT. 0 is "not set", or can be * used to clear any hints previously set. From patchwork Fri May 15 15:23:21 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Nate Karstens X-Patchwork-Id: 1291423 X-Patchwork-Delegate: davem@davemloft.net Return-Path: X-Original-To: patchwork-incoming@ozlabs.org Delivered-To: patchwork-incoming@ozlabs.org Authentication-Results: ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=vger.kernel.org (client-ip=23.128.96.18; helo=vger.kernel.org; envelope-from=sparclinux-owner@vger.kernel.org; receiver=) Authentication-Results: ozlabs.org; dmarc=pass (p=quarantine dis=none) header.from=garmin.com Authentication-Results: ozlabs.org; dkim=pass (2048-bit key; unprotected) header.d=garmin.com header.i=@garmin.com header.a=rsa-sha256 header.s=selector1 header.b=I457xqBn; dkim-atps=neutral Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by ozlabs.org (Postfix) with ESMTP id 49Nsdp3DzSz9sVn for ; Sat, 16 May 2020 01:24:30 +1000 (AEST) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1727981AbgEOPYP (ORCPT ); Fri, 15 May 2020 11:24:15 -0400 Received: from mail-mw2nam12on2125.outbound.protection.outlook.com ([40.107.244.125]:36832 "EHLO NAM12-MW2-obe.outbound.protection.outlook.com" rhost-flags-OK-OK-OK-FAIL) by vger.kernel.org with ESMTP id S1727836AbgEOPYH (ORCPT ); Fri, 15 May 2020 11:24:07 -0400 ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=jKWk43z0x/KZF0sywx67657Mk/F8H2nUgKfPToS5d0m6mD3k5QjMX5xh0SDs4kKaTIEzZYCkSCHy8gISxLycUtgNH2bdO0s6+kYrxvjY3eBbKWlZc5MOSVwxiaygZeQHtiT0psOUceCmDENUOaTywAvCf8BO8+UDJH9KR6Akwc1BAhNMTvfDunFePyzMSvjKYYSLC5F8xrA3UOWoBdM4vMY8Jfe0gzOI24JP2dyQID4xvYNZQwrgiTbsK8qMe+JwQoUtwvrWigbuzz+wrDCwAm00IqQVR3VbstEr6VvBK3aQAy+Vf3Xo/3smpjYAdptiaK89lwzLIwoM0U+4kpbzBQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=microsoft.com; s=arcselector9901; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck; bh=4yYEsRUYimhigxmNAl7hxApckYLbS26D6tFLpPrG/lo=; b=l+ouHhsp451FHJBTOLo6AHmJn/Z8ZZ6pB15LJGDN4svF0t4K6WY6Ufv6xfV9bHz+I/Xb/bHKjCrIMOgWFLiXZY6gOtYTm6F/6mlRHaOw3B8cexM955slX/vEgyA6NB3ykzqa9w1WOnb8ZLpREgO1JLJ8O5llyKUvRSjE7LJfMRdNWUjIvjPOZiFSrzQgoG4s42qaGl9qeOCXupjb7EZQTmTnI0l46F3um6rkTjuzPm/26APxIG6CLx0nMllEp97Wmjx9SHHZfRXBdVcsVADTc4vZWzEjgOVxxDxootHkVVCJ5WXUzDtix3SPS/wahF8GG+nvqDEECJb+DCh4qjJdPQ== ARC-Authentication-Results: i=1; mx.microsoft.com 1; spf=pass (sender ip is 204.77.163.244) smtp.rcpttodomain=zeniv.linux.org.uk smtp.mailfrom=garmin.com; dmarc=pass (p=quarantine sp=quarantine pct=100) action=none header.from=garmin.com; dkim=none (message not signed); arc=none DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=garmin.com; s=selector1; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck; bh=4yYEsRUYimhigxmNAl7hxApckYLbS26D6tFLpPrG/lo=; b=I457xqBnoCfDZc1z/TFtT1RPicEoDHm/6daPC0MAomONzYLNPttcgdh1DVSV4dCi5QWkglYuWH2zjeRQLBgIVHo9XVI/Oo1iR1HJ6B2zKcHQJ5e5Pd6/rfHdyuP5a3hA0+IMj6Qf5AHje0lpCg5p6CgNNxm/OGSntK/I/gyiYMbfn24JCi5RKjXtxvj0xJ2W74Mr6OeUW8zjtLGBfNHLBxDfBxVYGxq0ptPhqPKYEOomcc1AOv280AEktZFIDq+CXTYxrVrLstnzPhHDv15fbuzpdM5d8giKRXfxxKDLfSlZf8cdAEfLUpb3Sx5r+Z/nIm/jvgzvk9fYZlYOaQGX+w== Received: from DM5PR04CA0059.namprd04.prod.outlook.com (2603:10b6:3:ef::21) by BN6PR04MB3714.namprd04.prod.outlook.com (2603:10b6:404:d5::12) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.3000.24; Fri, 15 May 2020 15:24:01 +0000 Received: from DM6NAM10FT013.eop-nam10.prod.protection.outlook.com (2603:10b6:3:ef:cafe::ca) by DM5PR04CA0059.outlook.office365.com (2603:10b6:3:ef::21) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.3000.20 via Frontend Transport; Fri, 15 May 2020 15:24:01 +0000 Authentication-Results: spf=pass (sender IP is 204.77.163.244) smtp.mailfrom=garmin.com; zeniv.linux.org.uk; dkim=none (message not signed) header.d=none;zeniv.linux.org.uk; dmarc=pass action=none header.from=garmin.com; Received-SPF: Pass (protection.outlook.com: domain of garmin.com designates 204.77.163.244 as permitted sender) receiver=protection.outlook.com; client-ip=204.77.163.244; helo=edgetransport.garmin.com; Received: from edgetransport.garmin.com (204.77.163.244) by DM6NAM10FT013.mail.protection.outlook.com (10.13.152.142) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.3000.19 via Frontend Transport; Fri, 15 May 2020 15:24:01 +0000 Received: from OLAWPA-EXMB7.ad.garmin.com (10.5.144.21) by olawpa-edge1.garmin.com (10.60.4.227) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_CBC_SHA256) id 15.1.1466.3; Fri, 15 May 2020 10:23:59 -0500 Received: from ola-d01c000-vm.ad.garmin.com (10.5.84.15) by OLAWPA-EXMB7.ad.garmin.com (10.5.144.21) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_CBC_SHA256_P256) id 15.1.1913.5; Fri, 15 May 2020 10:23:59 -0500 From: Nate Karstens To: Alexander Viro , Jeff Layton , "J. Bruce Fields" , Arnd Bergmann , Richard Henderson , Ivan Kokshaysky , Matt Turner , "James E.J. Bottomley" , Helge Deller , "David S. Miller" , Jakub Kicinski , Eric Dumazet , David Laight , , , , , , , CC: Changli Gao , Nate Karstens Subject: [PATCH v2 4/4] net: Add SOCK_CLOFORK Date: Fri, 15 May 2020 10:23:21 -0500 Message-ID: <20200515152321.9280-5-nate.karstens@garmin.com> X-Mailer: git-send-email 2.26.1 In-Reply-To: <20200515152321.9280-1-nate.karstens@garmin.com> References: <20200515152321.9280-1-nate.karstens@garmin.com> MIME-Version: 1.0 X-ClientProxiedBy: OLAWPA-EXMB3.ad.garmin.com (10.5.144.15) To OLAWPA-EXMB7.ad.garmin.com (10.5.144.21) X-TM-AS-Product-Ver: SMEX-12.5.0.1300-8.5.1020-25422.000 X-TM-AS-Result: No-5.988100-8.000000-10 X-TMASE-MatchedRID: KFRUM/mjxGuSsyjfsjrH/tKhw1CGAxrILoFHmcx3krwAIXlMppp3Xw5a yixA3COc1+Otxunw83huL3ESIrARlyHhSBQfglfsA9lly13c/gHaKQ0GLhRPDxh58BVvx3LmF5J Ui8H1I3XP8poBdrWc73VybJRFpSevgRZdz333xpBJUdgxNDUXWmf6wD367VgtDs0BGU1luwj6p1 jlhLAJAsAhMlHsyVwnkA7KM/+6n4wylv9EjaWo1Q97mDMXdNW3fS0Ip2eEHnz3IzXlXlpamPoLR 4+zsDTtifGCYEa4Fxczqf0EmDYqY85HeDGrYmKjUdmnIsreROaomPe8FsDc1A== X-TM-AS-User-Approved-Sender: No X-TM-AS-User-Blocked-Sender: No X-TMASE-Result: 10--5.988100-8.000000 X-TMASE-Version: SMEX-12.5.0.1300-8.5.1020-25422.000 X-EOPAttributedMessage: 0 X-MS-Office365-Filtering-HT: Tenant X-Forefront-Antispam-Report: CIP:204.77.163.244;CTRY:US;LANG:en;SCL:1;SRV:;IPV:CAL;SFV:NSPM;H:edgetransport.garmin.com;PTR:extedge.garmin.com;CAT:NONE;SFTY:;SFS:(39860400002)(136003)(376002)(396003)(346002)(46966005)(6666004)(47076004)(1076003)(356005)(2906002)(4326008)(82310400002)(54906003)(110136005)(36756003)(7636003)(5660300002)(107886003)(316002)(82740400003)(70206006)(426003)(8676002)(7416002)(336012)(7696005)(8936002)(26005)(186003)(86362001)(44832011)(70586007)(2616005)(478600001)(921003);DIR:OUT;SFP:1102; X-MS-PublicTrafficType: Email X-MS-Office365-Filtering-Correlation-Id: 4b1dcac2-3342-4c05-6a03-08d7f8e3fec2 X-MS-TrafficTypeDiagnostic: BN6PR04MB3714: X-Microsoft-Antispam-PRVS: X-MS-Oob-TLC-OOBClassifiers: OLM:6430; X-Forefront-PRVS: 04041A2886 X-MS-Exchange-SenderADCheck: 1 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: L8EAb2hOELFGUpmq8+gtw26g0bqFwWv6HdRImt5NfSPkxaxbn9e+49dQ88Spz+vequWoudfOinphxbm/wSw4FSPh4j3p9OCmtbTAF7JVxKVecUTSfIwzvsAWcR7IPUHXReftWswk5Mu/xU/2QaLe7Grp5KgLANV3fzuBF9VxKrdzVd5o1rb130542COHjBSHsaVBhhRNukZG2qKh7nuZiFK7EsEv+C6tHfg22h/hHzNm6uLlWEYH6fzaVMVP/pmSau4h2nl2lhlwnX9l7sygvS0bavNtbFk/n46g3cfMCtLVS4Ryoufr9GEuacOfDhbncYK75LrhO6L5gmlnysRHTXPidh2p7GXgL0ANXBPRVkNO6hrSGLHPD18yQj4aX0HUH2uVP2VqRWI3EjTLCA4bS35EasOX2EF8+HNFOkMR3IIcT285W+a/zHEnWeD93FvN1WKkhCDZ/jxIPAwNVUdilbpuXe1jC4ixok6xDRF/zH9KLu8+kAwQLWE7NTU0rM+ly5V9eX/g9XoO9dFjES1Q5Q== X-OriginatorOrg: garmin.com X-MS-Exchange-CrossTenant-OriginalArrivalTime: 15 May 2020 15:24:01.0673 (UTC) X-MS-Exchange-CrossTenant-Network-Message-Id: 4b1dcac2-3342-4c05-6a03-08d7f8e3fec2 X-MS-Exchange-CrossTenant-Id: 38d0d425-ba52-4c0a-a03e-2a65c8e82e2d X-MS-Exchange-CrossTenant-OriginalAttributedTenantConnectingIp: TenantId=38d0d425-ba52-4c0a-a03e-2a65c8e82e2d;Ip=[204.77.163.244];Helo=[edgetransport.garmin.com] X-MS-Exchange-CrossTenant-FromEntityHeader: HybridOnPrem X-MS-Exchange-Transport-CrossTenantHeadersStamped: BN6PR04MB3714 Sender: sparclinux-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: sparclinux@vger.kernel.org Implements a new socket flag that automatically sets the close-on-fork flag for sockets created using socket(2), socketpair(2), and accept4(2). Signed-off-by: Nate Karstens --- include/linux/net.h | 3 ++- net/socket.c | 14 ++++++++------ 2 files changed, 10 insertions(+), 7 deletions(-) diff --git a/include/linux/net.h b/include/linux/net.h index 6451425e828f..57663c9dc8c4 100644 --- a/include/linux/net.h +++ b/include/linux/net.h @@ -17,7 +17,7 @@ #include #include #include -#include /* For O_CLOEXEC and O_NONBLOCK */ +#include /* For O_CLOEXEC, O_CLOFORK, and O_NONBLOCK */ #include #include #include @@ -73,6 +73,7 @@ enum sock_type { /* Flags for socket, socketpair, accept4 */ #define SOCK_CLOEXEC O_CLOEXEC +#define SOCK_CLOFORK O_CLOFORK #ifndef SOCK_NONBLOCK #define SOCK_NONBLOCK O_NONBLOCK #endif diff --git a/net/socket.c b/net/socket.c index 2eecf1517f76..ba6e971c7e78 100644 --- a/net/socket.c +++ b/net/socket.c @@ -1511,12 +1511,14 @@ int __sys_socket(int family, int type, int protocol) /* Check the SOCK_* constants for consistency. */ BUILD_BUG_ON(SOCK_CLOEXEC != O_CLOEXEC); + BUILD_BUG_ON(SOCK_CLOFORK != O_CLOFORK); BUILD_BUG_ON((SOCK_MAX | SOCK_TYPE_MASK) != SOCK_TYPE_MASK); BUILD_BUG_ON(SOCK_CLOEXEC & SOCK_TYPE_MASK); + BUILD_BUG_ON(SOCK_CLOFORK & SOCK_TYPE_MASK); BUILD_BUG_ON(SOCK_NONBLOCK & SOCK_TYPE_MASK); flags = type & ~SOCK_TYPE_MASK; - if (flags & ~(SOCK_CLOEXEC | SOCK_NONBLOCK)) + if (flags & ~(SOCK_CLOEXEC | SOCK_CLOFORK | SOCK_NONBLOCK)) return -EINVAL; type &= SOCK_TYPE_MASK; @@ -1527,7 +1529,7 @@ int __sys_socket(int family, int type, int protocol) if (retval < 0) return retval; - return sock_map_fd(sock, flags & (O_CLOEXEC | O_NONBLOCK)); + return sock_map_fd(sock, flags & (O_CLOEXEC | O_CLOFORK | O_NONBLOCK)); } SYSCALL_DEFINE3(socket, int, family, int, type, int, protocol) @@ -1547,7 +1549,7 @@ int __sys_socketpair(int family, int type, int protocol, int __user *usockvec) int flags; flags = type & ~SOCK_TYPE_MASK; - if (flags & ~(SOCK_CLOEXEC | SOCK_NONBLOCK)) + if (flags & ~(SOCK_CLOEXEC | SOCK_CLOFORK | SOCK_NONBLOCK)) return -EINVAL; type &= SOCK_TYPE_MASK; @@ -1715,7 +1717,7 @@ int __sys_accept4_file(struct file *file, unsigned file_flags, int err, len, newfd; struct sockaddr_storage address; - if (flags & ~(SOCK_CLOEXEC | SOCK_NONBLOCK)) + if (flags & ~(SOCK_CLOEXEC | SOCK_CLOFORK | SOCK_NONBLOCK)) return -EINVAL; if (SOCK_NONBLOCK != O_NONBLOCK && (flags & SOCK_NONBLOCK)) @@ -3628,8 +3630,8 @@ EXPORT_SYMBOL(kernel_listen); * @newsock: new connected socket * @flags: flags * - * @flags must be SOCK_CLOEXEC, SOCK_NONBLOCK or 0. - * If it fails, @newsock is guaranteed to be %NULL. + * @flags must be SOCK_CLOEXEC, SOCK_CLOFORK, SOCK_NONBLOCK, + * or 0. If it fails, @newsock is guaranteed to be %NULL. * Returns 0 or an error. */