Patch Detail
get:
Show a patch.
patch:
Update a patch.
put:
Update a patch.
GET /api/patches/2217415/?format=api
{ "id": 2217415, "url": "http://patchwork.ozlabs.org/api/patches/2217415/?format=api", "web_url": "http://patchwork.ozlabs.org/project/linux-cifs-client/patch/20260328172314.45807-2-dorjoychy111@gmail.com/", "project": { "id": 12, "url": "http://patchwork.ozlabs.org/api/projects/12/?format=api", "name": "Linux CIFS Client", "link_name": "linux-cifs-client", "list_id": "linux-cifs.vger.kernel.org", "list_email": "linux-cifs@vger.kernel.org", "web_url": "", "scm_url": "", "webscm_url": "", "list_archive_url": "", "list_archive_url_format": "", "commit_url_format": "" }, "msgid": "<20260328172314.45807-2-dorjoychy111@gmail.com>", "list_archive_url": null, "date": "2026-03-28T17:22:22", "name": "[v6,1/4] openat2: new OPENAT2_REGULAR flag support", "commit_ref": null, "pull_url": null, "state": "new", "archived": false, "hash": "5bc9c67743767db9821cda087acb4525190d4fb7", "submitter": { "id": 88386, "url": "http://patchwork.ozlabs.org/api/people/88386/?format=api", "name": "Dorjoy Chowdhury", "email": "dorjoychy111@gmail.com" }, "delegate": null, "mbox": "http://patchwork.ozlabs.org/project/linux-cifs-client/patch/20260328172314.45807-2-dorjoychy111@gmail.com/mbox/", "series": [ { "id": 497884, "url": "http://patchwork.ozlabs.org/api/series/497884/?format=api", "web_url": "http://patchwork.ozlabs.org/project/linux-cifs-client/list/?series=497884", "date": "2026-03-28T17:22:21", "name": "OPENAT2_REGULAR flag support for openat2", "version": 6, "mbox": "http://patchwork.ozlabs.org/series/497884/mbox/" } ], "comments": "http://patchwork.ozlabs.org/api/patches/2217415/comments/", "check": "pending", "checks": "http://patchwork.ozlabs.org/api/patches/2217415/checks/", "tags": {}, "related": [], "headers": { "Return-Path": "\n <linux-cifs+bounces-10563-incoming=patchwork.ozlabs.org@vger.kernel.org>", "X-Original-To": [ "incoming@patchwork.ozlabs.org", "linux-cifs@vger.kernel.org" ], "Delivered-To": "patchwork-incoming@legolas.ozlabs.org", "Authentication-Results": [ "legolas.ozlabs.org;\n\tdkim=pass (2048-bit key;\n unprotected) header.d=gmail.com header.i=@gmail.com header.a=rsa-sha256\n header.s=20251104 header.b=D5WtCyMH;\n\tdkim-atps=neutral", "legolas.ozlabs.org;\n spf=pass (sender SPF authorized) smtp.mailfrom=vger.kernel.org\n (client-ip=172.234.253.10; helo=sea.lore.kernel.org;\n envelope-from=linux-cifs+bounces-10563-incoming=patchwork.ozlabs.org@vger.kernel.org;\n receiver=patchwork.ozlabs.org)", "smtp.subspace.kernel.org;\n\tdkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com\n header.b=\"D5WtCyMH\"", "smtp.subspace.kernel.org;\n arc=none smtp.client-ip=209.85.216.53", "smtp.subspace.kernel.org;\n dmarc=pass (p=none dis=none) header.from=gmail.com", "smtp.subspace.kernel.org;\n spf=pass smtp.mailfrom=gmail.com" ], "Received": [ "from sea.lore.kernel.org (sea.lore.kernel.org [172.234.253.10])\n\t(using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits)\n\t key-exchange x25519 server-signature ECDSA (secp384r1) server-digest SHA384)\n\t(No client certificate requested)\n\tby legolas.ozlabs.org (Postfix) with ESMTPS id 4fjktJ5Phbz1y1x\n\tfor <incoming@patchwork.ozlabs.org>; Sun, 29 Mar 2026 04:25:28 +1100 (AEDT)", "from smtp.subspace.kernel.org (conduit.subspace.kernel.org\n [100.90.174.1])\n\tby sea.lore.kernel.org (Postfix) with ESMTP id D0C64302AC1E\n\tfor <incoming@patchwork.ozlabs.org>; Sat, 28 Mar 2026 17:23:58 +0000 (UTC)", "from localhost.localdomain (localhost.localdomain [127.0.0.1])\n\tby smtp.subspace.kernel.org (Postfix) with ESMTP id 303323A4523;\n\tSat, 28 Mar 2026 17:23:58 +0000 (UTC)", "from mail-pj1-f53.google.com (mail-pj1-f53.google.com\n [209.85.216.53])\n\t(using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits))\n\t(No client certificate requested)\n\tby smtp.subspace.kernel.org (Postfix) with ESMTPS id 43A4E359714\n\tfor <linux-cifs@vger.kernel.org>; Sat, 28 Mar 2026 17:23:56 +0000 (UTC)", "by mail-pj1-f53.google.com with SMTP id\n 98e67ed59e1d1-35c2fe0d90fso1038292a91.1\n for <linux-cifs@vger.kernel.org>;\n Sat, 28 Mar 2026 10:23:56 -0700 (PDT)", "from toolbx ([103.103.35.11])\n by smtp.gmail.com with ESMTPSA id\n 98e67ed59e1d1-35c22a5570esm10513773a91.3.2026.03.28.10.23.41\n (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256);\n Sat, 28 Mar 2026 10:23:55 -0700 (PDT)" ], "ARC-Seal": "i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116;\n\tt=1774718638; cv=none;\n b=PKmITnstnnj4hTdWeLfdcPtQ/d/QADVb18ZTBuALiJiEz31nzAlHnE3rhnUz6plsa+BQ7brJPH5M5sg0Cq9S732ttWjRGJHC80EqC0eBm+U10wF5xFuaOxPXh5iNxu0wKwsZsEJwjY7m4YSpvW/LwLUS1I+qNQX+3RqD33I+V5s=", "ARC-Message-Signature": "i=1; a=rsa-sha256; d=subspace.kernel.org;\n\ts=arc-20240116; t=1774718638; c=relaxed/simple;\n\tbh=uOVzfWG1cEqPUu6ILHQ5GnAuA4A8tWSLFbiZYE0vCEI=;\n\th=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References:\n\t MIME-Version;\n b=hIGuHYVe+NATNyoSjD1i6AgjRtheJZKW06Ov8RrWWdTa0+TeyyUTVMM8FNVEfTtjJHeolfinrrhtm0UtCQp1ead2YOlKGY6+HPy0IjHumIwBNs2KywwnHnGNlxwjUz07SBmIMGP1FTk0j605R0oRd5BsC0xY1iCo6FGtcefxZ8E=", "ARC-Authentication-Results": "i=1; smtp.subspace.kernel.org;\n dmarc=pass (p=none dis=none) header.from=gmail.com;\n spf=pass smtp.mailfrom=gmail.com;\n dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com\n header.b=D5WtCyMH; arc=none smtp.client-ip=209.85.216.53", "DKIM-Signature": "v=1; a=rsa-sha256; c=relaxed/relaxed;\n d=gmail.com; s=20251104; t=1774718635; x=1775323435;\n darn=vger.kernel.org;\n h=content-transfer-encoding:mime-version:references:in-reply-to\n :message-id:date:subject:cc:to:from:from:to:cc:subject:date\n :message-id:reply-to;\n bh=zbnvXfR2LaRdidXXHDujD9nIDm40TWJH2LHLfYsO5m4=;\n b=D5WtCyMHiOUwJ/1EQUM0mTQ7muTam9ZHjv5jlgzW4sQx+kYd0dgFyxYI6F6wnIndMI\n 2OoIT5zVXOVOBXkdGg1gbKzoSKPYHBUIQdcMp8PlGNAYMMTqNYQDL2QKizxwHu5vjbZq\n 9qIsoc7pGUFK4IyK10lB8xzqcGrUjantkwM17lnwQDe83RRIBGyNrx+GFUCsConYk6Dp\n B39nxBaE8+0lGxbuOVItBmL42cO/5elBpRJPrWcC6M6O1EGDKH3h21Mrd3YS6suKfrvb\n PXeviOhvsrX+Dpbd0jsXWgDUrW+PJizPBIk0Ha8HbPJRH8u0yGxCL8udoowBEzxRekmO\n 26/Q==", "X-Google-DKIM-Signature": "v=1; a=rsa-sha256; c=relaxed/relaxed;\n d=1e100.net; s=20251104; t=1774718635; x=1775323435;\n h=content-transfer-encoding:mime-version:references:in-reply-to\n :message-id:date:subject:cc:to:from:x-gm-gg:x-gm-message-state:from\n :to:cc:subject:date:message-id:reply-to;\n bh=zbnvXfR2LaRdidXXHDujD9nIDm40TWJH2LHLfYsO5m4=;\n b=jUeYO29ZwtBZvwJaJAwnZG29vKVh0JTOoz2Lz0KLoyGWVRcvV5RrmMj+Q2og1Uzg9A\n wvukgz0U9DzObl65A4Mr0ngDXWFOnSFiYCgQkGFAhXDG3mjXtBZJ7nsEAOEhysPREqpV\n 5mz7e43gDxrVMTtJXCXii0SPfZTUZoeXjiP1CxPYOaOiLUVTFYksU8+O1Ve0MLVbmauV\n ihCbEnfIvkrvNTjWviI+VSi8T0fVYWx4WPfVMMz9/u3PIF0c3ju9+w5CN0gfEM3sHLf+\n IvCieapHkg5UR79clfvTfoSbkPrH+KD7mQEDM+9EARGeqe65Jdoz5X27BxBb5ZoooEH9\n uktg==", "X-Forwarded-Encrypted": "i=1;\n AJvYcCVKn0Tbg2sgyx5gBsMoLoNvvVxnnejywf5DAdi4ENVpCQKtYNWZr3UmKxtvCvXyTHqTvbBSHFQV4jRI@vger.kernel.org", "X-Gm-Message-State": "AOJu0YxP+EzWfc1arBDHcj9lmGbPwMgM/nUPvaOLAFJPSFDkfcLkBapw\n\t4wTtRaljTNR5S9YNxcG5xtcGspS7Us0quCgc/o11CnCEcVA8O4xGU606", "X-Gm-Gg": "ATEYQzzty2jD4yzYQMSB9ejqUiPPLNe7WNn3KIaYA3Gte7SxhTxXp39Qfz0bk0KCuw8\n\t2Xjo1YBoxWMKDF3xlus+xtZot4UASBgDIZWmyWi6OOeE26fBCj4BO9jwyFXp5DE5vrx8P7CRW4d\n\tYO8UPBxrWHrTSsuqrvz+e3U3gcjl4fGBrEw2K08WT6zyuEolsxVmMYbtRnTbz7/3fZpdb8gjyDM\n\t3g5sjR/8adQJRErzPDX9Rq+OGM8uGEajLncHOab4UvMbZckKgtQJY8wjtK3/Mfmmm4k6LBnT/Lx\n\teohFOwNQk+YRbWjbGmTPp8NUNCLCEokzrsRgb1mKnbH9avIf8OWueLHMxU+g5GmYoTpgTdkWB5g\n\t0GuK83z9L5J09S1a94KXHtAM9RV7FWgQ1zFq99Ts+uyseTWeyLwiYT8PBkM51leba4VTF73ts5F\n\t67539JFHkcsLS5oMXS1hTrxuQVf4GTlrZbJPhrxk18lnrscvxfjEuMCnQ=", "X-Received": "by 2002:a17:90b:2787:b0:35b:e4d5:dc71 with SMTP id\n 98e67ed59e1d1-35c2ffa9e40mr6824533a91.14.1774718635343;\n Sat, 28 Mar 2026 10:23:55 -0700 (PDT)", "From": "Dorjoy Chowdhury <dorjoychy111@gmail.com>", "To": "linux-fsdevel@vger.kernel.org", "Cc": "linux-kernel@vger.kernel.org,\n\tlinux-api@vger.kernel.org,\n\tceph-devel@vger.kernel.org,\n\tgfs2@lists.linux.dev,\n\tlinux-nfs@vger.kernel.org,\n\tlinux-cifs@vger.kernel.org,\n\tv9fs@lists.linux.dev,\n\tlinux-kselftest@vger.kernel.org,\n\tviro@zeniv.linux.org.uk,\n\tbrauner@kernel.org,\n\tjack@suse.cz,\n\tjlayton@kernel.org,\n\tchuck.lever@oracle.com,\n\talex.aring@gmail.com,\n\tarnd@arndb.de,\n\tadilger@dilger.ca,\n\tmjguzik@gmail.com,\n\tsmfrench@gmail.com,\n\trichard.henderson@linaro.org,\n\tmattst88@gmail.com,\n\tlinmag7@gmail.com,\n\ttsbogend@alpha.franken.de,\n\tJames.Bottomley@HansenPartnership.com,\n\tdeller@gmx.de,\n\tdavem@davemloft.net,\n\tandreas@gaisler.com,\n\tidryomov@gmail.com,\n\tamarkuze@redhat.com,\n\tslava@dubeyko.com,\n\tagruenba@redhat.com,\n\ttrondmy@kernel.org,\n\tanna@kernel.org,\n\tsfrench@samba.org,\n\tpc@manguebit.org,\n\tronniesahlberg@gmail.com,\n\tsprasad@microsoft.com,\n\ttom@talpey.com,\n\tbharathsm@microsoft.com,\n\tshuah@kernel.org,\n\tmiklos@szeredi.hu,\n\thansg@kernel.org", "Subject": "[PATCH v6 1/4] openat2: new OPENAT2_REGULAR flag support", "Date": "Sat, 28 Mar 2026 23:22:22 +0600", "Message-ID": "<20260328172314.45807-2-dorjoychy111@gmail.com>", "X-Mailer": "git-send-email 2.53.0", "In-Reply-To": "<20260328172314.45807-1-dorjoychy111@gmail.com>", "References": "<20260328172314.45807-1-dorjoychy111@gmail.com>", "Precedence": "bulk", "X-Mailing-List": "linux-cifs@vger.kernel.org", "List-Id": "<linux-cifs.vger.kernel.org>", "List-Subscribe": "<mailto:linux-cifs+subscribe@vger.kernel.org>", "List-Unsubscribe": "<mailto:linux-cifs+unsubscribe@vger.kernel.org>", "MIME-Version": "1.0", "Content-Transfer-Encoding": "8bit" }, "content": "This flag indicates the path should be opened if it's a regular file.\nThis is useful to write secure programs that want to avoid being\ntricked into opening device nodes with special semantics while thinking\nthey operate on regular files. This is a requested feature from the\nuapi-group[1].\n\nA corresponding error code EFTYPE has been introduced. For example, if\nopenat2 is called on path /dev/null with OPENAT2_REGULAR in the flag\nparam, it will return -EFTYPE. EFTYPE is already used in BSD systems\nlike FreeBSD, macOS.\n\nWhen used in combination with O_CREAT, either the regular file is\ncreated, or if the path already exists, it is opened if it's a regular\nfile. Otherwise, -EFTYPE is returned.\n\nWhen OPENAT2_REGULAR is combined with O_DIRECTORY, -EINVAL is returned\nas it doesn't make sense to open a path that is both a directory and a\nregular file.\n\n[1]: https://uapi-group.org/kernel-features/#ability-to-only-open-regular-files\n\nSigned-off-by: Dorjoy Chowdhury <dorjoychy111@gmail.com>\n---\n arch/alpha/include/uapi/asm/errno.h | 2 ++\n arch/alpha/include/uapi/asm/fcntl.h | 1 +\n arch/mips/include/uapi/asm/errno.h | 2 ++\n arch/parisc/include/uapi/asm/errno.h | 2 ++\n arch/parisc/include/uapi/asm/fcntl.h | 1 +\n arch/sparc/include/uapi/asm/errno.h | 2 ++\n arch/sparc/include/uapi/asm/fcntl.h | 1 +\n fs/ceph/file.c | 4 ++++\n fs/fcntl.c | 4 ++--\n fs/gfs2/inode.c | 6 ++++++\n fs/namei.c | 4 ++++\n fs/nfs/dir.c | 4 ++++\n fs/open.c | 8 +++++---\n fs/smb/client/dir.c | 14 +++++++++++++-\n include/linux/fcntl.h | 2 ++\n include/uapi/asm-generic/errno.h | 2 ++\n include/uapi/asm-generic/fcntl.h | 4 ++++\n tools/arch/alpha/include/uapi/asm/errno.h | 2 ++\n tools/arch/mips/include/uapi/asm/errno.h | 2 ++\n tools/arch/parisc/include/uapi/asm/errno.h | 2 ++\n tools/arch/sparc/include/uapi/asm/errno.h | 2 ++\n tools/include/uapi/asm-generic/errno.h | 2 ++\n 22 files changed, 67 insertions(+), 6 deletions(-)", "diff": "diff --git a/arch/alpha/include/uapi/asm/errno.h b/arch/alpha/include/uapi/asm/errno.h\nindex 6791f6508632..1a99f38813c7 100644\n--- a/arch/alpha/include/uapi/asm/errno.h\n+++ b/arch/alpha/include/uapi/asm/errno.h\n@@ -127,4 +127,6 @@\n \n #define EHWPOISON\t139\t/* Memory page has hardware error */\n \n+#define EFTYPE\t\t140\t/* Wrong file type for the intended operation */\n+\n #endif\ndiff --git a/arch/alpha/include/uapi/asm/fcntl.h b/arch/alpha/include/uapi/asm/fcntl.h\nindex 50bdc8e8a271..fe488bf7c18e 100644\n--- a/arch/alpha/include/uapi/asm/fcntl.h\n+++ b/arch/alpha/include/uapi/asm/fcntl.h\n@@ -34,6 +34,7 @@\n \n #define O_PATH\t\t040000000\n #define __O_TMPFILE\t0100000000\n+#define OPENAT2_REGULAR\t0200000000\n \n #define F_GETLK\t\t7\n #define F_SETLK\t\t8\ndiff --git a/arch/mips/include/uapi/asm/errno.h b/arch/mips/include/uapi/asm/errno.h\nindex c01ed91b1ef4..1835a50b69ce 100644\n--- a/arch/mips/include/uapi/asm/errno.h\n+++ b/arch/mips/include/uapi/asm/errno.h\n@@ -126,6 +126,8 @@\n \n #define EHWPOISON\t168\t/* Memory page has hardware error */\n \n+#define EFTYPE\t\t169\t/* Wrong file type for the intended operation */\n+\n #define EDQUOT\t\t1133\t/* Quota exceeded */\n \n \ndiff --git a/arch/parisc/include/uapi/asm/errno.h b/arch/parisc/include/uapi/asm/errno.h\nindex 8cbc07c1903e..93194fbb0a80 100644\n--- a/arch/parisc/include/uapi/asm/errno.h\n+++ b/arch/parisc/include/uapi/asm/errno.h\n@@ -124,4 +124,6 @@\n \n #define EHWPOISON\t257\t/* Memory page has hardware error */\n \n+#define EFTYPE\t\t258\t/* Wrong file type for the intended operation */\n+\n #endif\ndiff --git a/arch/parisc/include/uapi/asm/fcntl.h b/arch/parisc/include/uapi/asm/fcntl.h\nindex 03dee816cb13..d46812f2f0f4 100644\n--- a/arch/parisc/include/uapi/asm/fcntl.h\n+++ b/arch/parisc/include/uapi/asm/fcntl.h\n@@ -19,6 +19,7 @@\n \n #define O_PATH\t\t020000000\n #define __O_TMPFILE\t040000000\n+#define OPENAT2_REGULAR\t0100000000\n \n #define F_GETLK64\t8\n #define F_SETLK64\t9\ndiff --git a/arch/sparc/include/uapi/asm/errno.h b/arch/sparc/include/uapi/asm/errno.h\nindex 4a41e7835fd5..71940ec9130b 100644\n--- a/arch/sparc/include/uapi/asm/errno.h\n+++ b/arch/sparc/include/uapi/asm/errno.h\n@@ -117,4 +117,6 @@\n \n #define EHWPOISON\t135\t/* Memory page has hardware error */\n \n+#define EFTYPE\t\t136\t/* Wrong file type for the intended operation */\n+\n #endif\ndiff --git a/arch/sparc/include/uapi/asm/fcntl.h b/arch/sparc/include/uapi/asm/fcntl.h\nindex 67dae75e5274..bb6e9fa94bc9 100644\n--- a/arch/sparc/include/uapi/asm/fcntl.h\n+++ b/arch/sparc/include/uapi/asm/fcntl.h\n@@ -37,6 +37,7 @@\n \n #define O_PATH\t\t0x1000000\n #define __O_TMPFILE\t0x2000000\n+#define OPENAT2_REGULAR\t0x4000000\n \n #define F_GETOWN\t5\t/* for sockets. */\n #define F_SETOWN\t6\t/* for sockets. */\ndiff --git a/fs/ceph/file.c b/fs/ceph/file.c\nindex 66bbf6d517a9..6d8d4c7765e6 100644\n--- a/fs/ceph/file.c\n+++ b/fs/ceph/file.c\n@@ -977,6 +977,10 @@ int ceph_atomic_open(struct inode *dir, struct dentry *dentry,\n \t\t\tceph_init_inode_acls(newino, &as_ctx);\n \t\t\tfile->f_mode |= FMODE_CREATED;\n \t\t}\n+\t\tif ((flags & OPENAT2_REGULAR) && !d_is_reg(dentry)) {\n+\t\t\terr = -EFTYPE;\n+\t\t\tgoto out_req;\n+\t\t}\n \t\terr = finish_open(file, dentry, ceph_open);\n \t}\n out_req:\ndiff --git a/fs/fcntl.c b/fs/fcntl.c\nindex beab8080badf..240bb511557a 100644\n--- a/fs/fcntl.c\n+++ b/fs/fcntl.c\n@@ -1169,9 +1169,9 @@ static int __init fcntl_init(void)\n \t * Exceptions: O_NONBLOCK is a two bit define on parisc; O_NDELAY\n \t * is defined as O_NONBLOCK on some platforms and not on others.\n \t */\n-\tBUILD_BUG_ON(20 - 1 /* for O_RDONLY being 0 */ !=\n+\tBUILD_BUG_ON(21 - 1 /* for O_RDONLY being 0 */ !=\n \t\tHWEIGHT32(\n-\t\t\t(VALID_OPEN_FLAGS & ~(O_NONBLOCK | O_NDELAY)) |\n+\t\t\t(VALID_OPENAT2_FLAGS & ~(O_NONBLOCK | O_NDELAY)) |\n \t\t\t__FMODE_EXEC));\n \n \tfasync_cache = kmem_cache_create(\"fasync_cache\",\ndiff --git a/fs/gfs2/inode.c b/fs/gfs2/inode.c\nindex 8344040ecaf7..4604e2e8a9cc 100644\n--- a/fs/gfs2/inode.c\n+++ b/fs/gfs2/inode.c\n@@ -738,6 +738,12 @@ static int gfs2_create_inode(struct inode *dir, struct dentry *dentry,\n \tinode = gfs2_dir_search(dir, &dentry->d_name, !S_ISREG(mode) || excl);\n \terror = PTR_ERR(inode);\n \tif (!IS_ERR(inode)) {\n+\t\tif (file && (file->f_flags & OPENAT2_REGULAR) && !S_ISREG(inode->i_mode)) {\n+\t\t\tiput(inode);\n+\t\t\tinode = NULL;\n+\t\t\terror = -EFTYPE;\n+\t\t\tgoto fail_gunlock;\n+\t\t}\n \t\tif (S_ISDIR(inode->i_mode)) {\n \t\t\tiput(inode);\n \t\t\tinode = NULL;\ndiff --git a/fs/namei.c b/fs/namei.c\nindex 2113958c3b7a..e557c538c238 100644\n--- a/fs/namei.c\n+++ b/fs/namei.c\n@@ -4679,6 +4679,10 @@ static int do_open(struct nameidata *nd,\n \t\tif (unlikely(error))\n \t\t\treturn error;\n \t}\n+\n+\tif ((open_flag & OPENAT2_REGULAR) && !d_is_reg(nd->path.dentry))\n+\t\treturn -EFTYPE;\n+\n \tif ((nd->flags & LOOKUP_DIRECTORY) && !d_can_lookup(nd->path.dentry))\n \t\treturn -ENOTDIR;\n \ndiff --git a/fs/nfs/dir.c b/fs/nfs/dir.c\nindex ddc3789363a5..bfe9470327c8 100644\n--- a/fs/nfs/dir.c\n+++ b/fs/nfs/dir.c\n@@ -2195,6 +2195,10 @@ int nfs_atomic_open(struct inode *dir, struct dentry *dentry,\n \t\t\tbreak;\n \t\tcase -EISDIR:\n \t\tcase -ENOTDIR:\n+\t\t\tif (open_flags & OPENAT2_REGULAR) {\n+\t\t\t\terr = -EFTYPE;\n+\t\t\t\tbreak;\n+\t\t\t}\n \t\t\tgoto no_open;\n \t\tcase -ELOOP:\n \t\t\tif (!(open_flags & O_NOFOLLOW))\ndiff --git a/fs/open.c b/fs/open.c\nindex 681d405bc61e..a6f445f72181 100644\n--- a/fs/open.c\n+++ b/fs/open.c\n@@ -960,7 +960,7 @@ static int do_dentry_open(struct file *f,\n \tif (f->f_mapping->a_ops && f->f_mapping->a_ops->direct_IO)\n \t\tf->f_mode |= FMODE_CAN_ODIRECT;\n \n-\tf->f_flags &= ~(O_CREAT | O_EXCL | O_NOCTTY | O_TRUNC);\n+\tf->f_flags &= ~(O_CREAT | O_EXCL | O_NOCTTY | O_TRUNC | OPENAT2_REGULAR);\n \tf->f_iocb_flags = iocb_flags(f);\n \n \tfile_ra_state_init(&f->f_ra, f->f_mapping->host->i_mapping);\n@@ -1183,7 +1183,7 @@ inline int build_open_flags(const struct open_how *how, struct open_flags *op)\n \tint lookup_flags = 0;\n \tint acc_mode = ACC_MODE(flags);\n \n-\tBUILD_BUG_ON_MSG(upper_32_bits(VALID_OPEN_FLAGS),\n+\tBUILD_BUG_ON_MSG(upper_32_bits(VALID_OPENAT2_FLAGS),\n \t\t\t \"struct open_flags doesn't yet handle flags > 32 bits\");\n \n \t/*\n@@ -1196,7 +1196,7 @@ inline int build_open_flags(const struct open_how *how, struct open_flags *op)\n \t * values before calling build_open_flags(), but openat2(2) checks all\n \t * of its arguments.\n \t */\n-\tif (flags & ~VALID_OPEN_FLAGS)\n+\tif (flags & ~VALID_OPENAT2_FLAGS)\n \t\treturn -EINVAL;\n \tif (how->resolve & ~VALID_RESOLVE_FLAGS)\n \t\treturn -EINVAL;\n@@ -1235,6 +1235,8 @@ inline int build_open_flags(const struct open_how *how, struct open_flags *op)\n \t\t\treturn -EINVAL;\n \t\tif (!(acc_mode & MAY_WRITE))\n \t\t\treturn -EINVAL;\n+\t} else if ((flags & O_DIRECTORY) && (flags & OPENAT2_REGULAR)) {\n+\t\treturn -EINVAL;\n \t}\n \tif (flags & O_PATH) {\n \t\t/* O_PATH only permits certain other flags to be set. */\ndiff --git a/fs/smb/client/dir.c b/fs/smb/client/dir.c\nindex 953f1fee8cb8..355681ebacf1 100644\n--- a/fs/smb/client/dir.c\n+++ b/fs/smb/client/dir.c\n@@ -222,6 +222,13 @@ static int cifs_do_create(struct inode *inode, struct dentry *direntry, unsigned\n \t\t\t\tgoto cifs_create_get_file_info;\n \t\t\t}\n \n+\t\t\tif ((oflags & OPENAT2_REGULAR) && !S_ISREG(newinode->i_mode)) {\n+\t\t\t\tCIFSSMBClose(xid, tcon, fid->netfid);\n+\t\t\t\tiput(newinode);\n+\t\t\t\trc = -EFTYPE;\n+\t\t\t\tgoto out;\n+\t\t\t}\n+\n \t\t\tif (S_ISDIR(newinode->i_mode)) {\n \t\t\t\tCIFSSMBClose(xid, tcon, fid->netfid);\n \t\t\t\tiput(newinode);\n@@ -436,11 +443,16 @@ static int cifs_do_create(struct inode *inode, struct dentry *direntry, unsigned\n \t\tgoto out_err;\n \t}\n \n-\tif (newinode)\n+\tif (newinode) {\n+\t\tif ((oflags & OPENAT2_REGULAR) && !S_ISREG(newinode->i_mode)) {\n+\t\t\trc = -EFTYPE;\n+\t\t\tgoto out_err;\n+\t\t}\n \t\tif (S_ISDIR(newinode->i_mode)) {\n \t\t\trc = -EISDIR;\n \t\t\tgoto out_err;\n \t\t}\n+\t}\n \n \td_drop(direntry);\n \td_add(direntry, newinode);\ndiff --git a/include/linux/fcntl.h b/include/linux/fcntl.h\nindex a332e79b3207..a80026718217 100644\n--- a/include/linux/fcntl.h\n+++ b/include/linux/fcntl.h\n@@ -12,6 +12,8 @@\n \t FASYNC\t| O_DIRECT | O_LARGEFILE | O_DIRECTORY | O_NOFOLLOW | \\\n \t O_NOATIME | O_CLOEXEC | O_PATH | __O_TMPFILE)\n \n+#define VALID_OPENAT2_FLAGS (VALID_OPEN_FLAGS | OPENAT2_REGULAR)\n+\n /* List of all valid flags for the how->resolve argument: */\n #define VALID_RESOLVE_FLAGS \\\n \t(RESOLVE_NO_XDEV | RESOLVE_NO_MAGICLINKS | RESOLVE_NO_SYMLINKS | \\\ndiff --git a/include/uapi/asm-generic/errno.h b/include/uapi/asm-generic/errno.h\nindex 92e7ae493ee3..bd78e69e0a43 100644\n--- a/include/uapi/asm-generic/errno.h\n+++ b/include/uapi/asm-generic/errno.h\n@@ -122,4 +122,6 @@\n \n #define EHWPOISON\t133\t/* Memory page has hardware error */\n \n+#define EFTYPE\t\t134\t/* Wrong file type for the intended operation */\n+\n #endif\ndiff --git a/include/uapi/asm-generic/fcntl.h b/include/uapi/asm-generic/fcntl.h\nindex 613475285643..b2c2ddd0edc0 100644\n--- a/include/uapi/asm-generic/fcntl.h\n+++ b/include/uapi/asm-generic/fcntl.h\n@@ -88,6 +88,10 @@\n #define __O_TMPFILE\t020000000\n #endif\n \n+#ifndef OPENAT2_REGULAR\n+#define OPENAT2_REGULAR\t040000000\n+#endif\n+\n /* a horrid kludge trying to make sure that this will fail on old kernels */\n #define O_TMPFILE (__O_TMPFILE | O_DIRECTORY)\n \ndiff --git a/tools/arch/alpha/include/uapi/asm/errno.h b/tools/arch/alpha/include/uapi/asm/errno.h\nindex 6791f6508632..1a99f38813c7 100644\n--- a/tools/arch/alpha/include/uapi/asm/errno.h\n+++ b/tools/arch/alpha/include/uapi/asm/errno.h\n@@ -127,4 +127,6 @@\n \n #define EHWPOISON\t139\t/* Memory page has hardware error */\n \n+#define EFTYPE\t\t140\t/* Wrong file type for the intended operation */\n+\n #endif\ndiff --git a/tools/arch/mips/include/uapi/asm/errno.h b/tools/arch/mips/include/uapi/asm/errno.h\nindex c01ed91b1ef4..1835a50b69ce 100644\n--- a/tools/arch/mips/include/uapi/asm/errno.h\n+++ b/tools/arch/mips/include/uapi/asm/errno.h\n@@ -126,6 +126,8 @@\n \n #define EHWPOISON\t168\t/* Memory page has hardware error */\n \n+#define EFTYPE\t\t169\t/* Wrong file type for the intended operation */\n+\n #define EDQUOT\t\t1133\t/* Quota exceeded */\n \n \ndiff --git a/tools/arch/parisc/include/uapi/asm/errno.h b/tools/arch/parisc/include/uapi/asm/errno.h\nindex 8cbc07c1903e..93194fbb0a80 100644\n--- a/tools/arch/parisc/include/uapi/asm/errno.h\n+++ b/tools/arch/parisc/include/uapi/asm/errno.h\n@@ -124,4 +124,6 @@\n \n #define EHWPOISON\t257\t/* Memory page has hardware error */\n \n+#define EFTYPE\t\t258\t/* Wrong file type for the intended operation */\n+\n #endif\ndiff --git a/tools/arch/sparc/include/uapi/asm/errno.h b/tools/arch/sparc/include/uapi/asm/errno.h\nindex 4a41e7835fd5..71940ec9130b 100644\n--- a/tools/arch/sparc/include/uapi/asm/errno.h\n+++ b/tools/arch/sparc/include/uapi/asm/errno.h\n@@ -117,4 +117,6 @@\n \n #define EHWPOISON\t135\t/* Memory page has hardware error */\n \n+#define EFTYPE\t\t136\t/* Wrong file type for the intended operation */\n+\n #endif\ndiff --git a/tools/include/uapi/asm-generic/errno.h b/tools/include/uapi/asm-generic/errno.h\nindex 92e7ae493ee3..bd78e69e0a43 100644\n--- a/tools/include/uapi/asm-generic/errno.h\n+++ b/tools/include/uapi/asm-generic/errno.h\n@@ -122,4 +122,6 @@\n \n #define EHWPOISON\t133\t/* Memory page has hardware error */\n \n+#define EFTYPE\t\t134\t/* Wrong file type for the intended operation */\n+\n #endif\n", "prefixes": [ "v6", "1/4" ] }