From patchwork Tue Jul 6 12:48:52 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Dmitry Kadashev X-Patchwork-Id: 12360523 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-15.7 required=3.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,FREEMAIL_FORGED_FROMDOMAIN,FREEMAIL_FROM, HEADER_FROM_DIFFERENT_DOMAINS,INCLUDES_CR_TRAILER,INCLUDES_PATCH, MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS,URIBL_BLOCKED,USER_AGENT_GIT autolearn=ham autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id D32CBC11F66 for ; Tue, 6 Jul 2021 12:49:39 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id AF6AA601FD for ; Tue, 6 Jul 2021 12:49:39 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S241933AbhGFMwR (ORCPT ); Tue, 6 Jul 2021 08:52:17 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:35780 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S241502AbhGFMwC (ORCPT ); Tue, 6 Jul 2021 08:52:02 -0400 Received: from mail-lj1-x22a.google.com (mail-lj1-x22a.google.com [IPv6:2a00:1450:4864:20::22a]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id B1EC1C061768; Tue, 6 Jul 2021 05:49:22 -0700 (PDT) Received: by mail-lj1-x22a.google.com with SMTP id q4so28930708ljp.13; Tue, 06 Jul 2021 05:49:22 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=gokPHawoPLTY7lmBlEah/J0yiKgx3oWjxOPrR9t5IgU=; b=MqXgNCdr+kZhNTjqZVDlKAKMa5+TLT1szNdAUkPLEYxYyZtS3gAYcEAwZltk3fYFEq 2McJqPRqeIesDJ2dXRFY01pR1wN/Jaw3PLESKqWg6G5QxHJ7+mQ6545auM1B05JFfa9Z 5vqhvCSxVfI5bW3bQhlmiN1exmN9yUL4BtI8tcseUa/0GwV+5arBoeq2aBrZulODf44i LHp8lznVyi24hLRnp5jgzUzdcEBXkEhQVJLRXC568gNy0fRurERZzyp9u9VcOM89wu6K XTcL/CTOAisoSJxgXs9zaGQhcrG9Pq7/V0qiEkrlOieIbpSLm8e5TciPZGgNaS04Bak1 eQdQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=gokPHawoPLTY7lmBlEah/J0yiKgx3oWjxOPrR9t5IgU=; b=jqo7Rks1X3oPqZpbOMVl0nStAczvXNJud4O/8CFteqWMVk23Wguxi/kxrdqd9RnJy7 VKoMTy6rWHiD4ZS//seB/JT0pUKWP7SAmViOW4LYp8rOtYQhYOHwedpwIg0xUezGEFyk xf1VytTXRLiqewbU87LB/mtFyuinI3BGCZAd9cGzkL/ckkpi/Yxra6E6L7HjzlN0qGFl FadkqFwuAqD5CqpC4FrJAxzKzndQdnl2//HymcFbDMejiTZxDe+qg8Fvo7ihWIuSH4iO DrqIIn297OCMyuj9tarq+WQooJrqI759q3kAg1fbNKNaqjUy1DmR/zAoryfOZ9G1JTFF NvRg== X-Gm-Message-State: AOAM532O0uvFgjW0fU+aUos0f4HtqGTDyllTIYLgZUAsiIzSTNf4G7yd 1vdEWBvEO4nYKcFeq7RW9jY= X-Google-Smtp-Source: ABdhPJzqe5nGomo9mScYt++JBnJqdZzufy5Q2ROyfA97txyzBIGWS7LsGImyN1qS1V4cTzRMvZqluQ== X-Received: by 2002:a2e:a30b:: with SMTP id l11mr14723382lje.453.1625575761106; Tue, 06 Jul 2021 05:49:21 -0700 (PDT) Received: from carbon.v ([94.143.149.146]) by smtp.googlemail.com with ESMTPSA id r18sm139519ljc.120.2021.07.06.05.49.19 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 06 Jul 2021 05:49:20 -0700 (PDT) From: Dmitry Kadashev To: Jens Axboe , Alexander Viro , Christian Brauner , Linus Torvalds Cc: Pavel Begunkov , linux-fsdevel@vger.kernel.org, io-uring@vger.kernel.org, Dmitry Kadashev Subject: [PATCH v7 01/10] namei: ignore ERR/NULL names in putname() Date: Tue, 6 Jul 2021 19:48:52 +0700 Message-Id: <20210706124901.1360377-2-dkadashev@gmail.com> X-Mailer: git-send-email 2.30.2 In-Reply-To: <20210706124901.1360377-1-dkadashev@gmail.com> References: <20210706124901.1360377-1-dkadashev@gmail.com> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: linux-fsdevel@vger.kernel.org Supporting ERR/NULL names in putname() makes callers code cleaner, and is what some other path walking functions already support for the same reason. This also removes a few existing IS_ERR checks before putname(). Suggested-by: Linus Torvalds Link: https://lore.kernel.org/io-uring/CAHk-=wgCac9hBsYzKMpHk0EbLgQaXR=OUAjHaBtaY+G8A9KhFg@mail.gmail.com/ Cc: Linus Torvalds Cc: Al Viro Cc: Christian Brauner Signed-off-by: Dmitry Kadashev --- fs/namei.c | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/fs/namei.c b/fs/namei.c index 79b0ff9b151e..70caf4ef1134 100644 --- a/fs/namei.c +++ b/fs/namei.c @@ -247,6 +247,9 @@ getname_kernel(const char * filename) void putname(struct filename *name) { + if (IS_ERR_OR_NULL(name)) + return; + BUG_ON(name->refcnt <= 0); if (--name->refcnt > 0) @@ -4718,11 +4721,9 @@ int do_renameat2(int olddfd, struct filename *from, int newdfd, goto retry; } put_both: - if (!IS_ERR(from)) - putname(from); + putname(from); put_new: - if (!IS_ERR(to)) - putname(to); + putname(to); return error; } From patchwork Tue Jul 6 12:48:53 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Dmitry Kadashev X-Patchwork-Id: 12360527 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-15.7 required=3.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,FREEMAIL_FORGED_FROMDOMAIN,FREEMAIL_FROM, HEADER_FROM_DIFFERENT_DOMAINS,INCLUDES_CR_TRAILER,INCLUDES_PATCH, MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS,URIBL_BLOCKED,USER_AGENT_GIT autolearn=ham autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 1D7BBC07E9C for ; Tue, 6 Jul 2021 12:49:43 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 0CD0D61166 for ; Tue, 6 Jul 2021 12:49:43 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S241953AbhGFMwU (ORCPT ); Tue, 6 Jul 2021 08:52:20 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:35896 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S237916AbhGFMwD (ORCPT ); Tue, 6 Jul 2021 08:52:03 -0400 Received: from mail-lf1-x12b.google.com (mail-lf1-x12b.google.com [IPv6:2a00:1450:4864:20::12b]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id DCCA8C061574; Tue, 6 Jul 2021 05:49:23 -0700 (PDT) Received: by mail-lf1-x12b.google.com with SMTP id p16so10641902lfc.5; Tue, 06 Jul 2021 05:49:23 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=S98nHxfTo5m/JgcsnAfUg1Ygblw/JMoWygfYueM6Umc=; b=MrXt27BmxMOQBKAlAqT0zPGmdNfqPvSARxppy+4+IDTnT737+TBI8mmTKOAWvd2VIT lyuD3a9ZiBQnJTzeAMmlE2lTO7s/u6+t0x13vce5CBOjD7Hy9C/CkKT2EIwxQKoAWujr MSyY4jyHhNitVW02QLh9F8+s5hN7dN7dM1ylVty1RgeYtcxMUOTyduFGxXEniIznS6sM 226v8JHygEY4FvMMlG1VMpciuEekaliWdd4hzlmRAyGY3Pu0CF8rF8qVvlme7808T4zF WYqQ4FaV0dT+GU8njVx0PcLF+IVLvqOpiSUTXZ4HOJJReD4luPo5wpkE46N8QNnr4M8N t8VA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=S98nHxfTo5m/JgcsnAfUg1Ygblw/JMoWygfYueM6Umc=; b=PxHQIujmy5MNZAOvdSpgqWgEVGuJsnadtjZdgAKYSLbuhYys8GCkfOiXJJDpA+L3Tu BYOiMC8qIHIh/Y++NJ/Fxt3a5S+3g332u8HoEtXEnqF4etHyAklwzmubeH2oiJKb/N3W yPrSHe5MX2iOo+2jv8VjEs3COyFjNiIMmYakio83hceWMlDLSMzxtWLq9UaoglnpC+G2 SyNk7JKunCfulouEDUgjMT7Z5De1QuAtBQKJBvF6IU+5GmmU+tZSxbOEBLSxW2dn462x favBtyOV1e3Xl4UT+VVCO+P81LRfUMQ0H+P2U/N6KNxkKR67ZDSoS5mA4WegwBhNal8Y EJcg== X-Gm-Message-State: AOAM532bkHXoZmFjSLWSW8A/Yasdj/NLBmpwzMFkZgCNm3neEmJvDPaT 3hKgTUzqDJSO3PuVH6ksMrE= X-Google-Smtp-Source: ABdhPJyqG6uE+oEJyNDPBOCXGOTQ7BN8D38K+NuQ9VGC1Pm5BilcmCzmxNNPsWg8GOthftIjx4hjww== X-Received: by 2002:a05:6512:3582:: with SMTP id m2mr15569530lfr.532.1625575762313; Tue, 06 Jul 2021 05:49:22 -0700 (PDT) Received: from carbon.v ([94.143.149.146]) by smtp.googlemail.com with ESMTPSA id r18sm139519ljc.120.2021.07.06.05.49.21 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 06 Jul 2021 05:49:21 -0700 (PDT) From: Dmitry Kadashev To: Jens Axboe , Alexander Viro , Christian Brauner , Linus Torvalds Cc: Pavel Begunkov , linux-fsdevel@vger.kernel.org, io-uring@vger.kernel.org, Dmitry Kadashev Subject: [PATCH v7 02/10] fs: make do_mkdirat() take struct filename Date: Tue, 6 Jul 2021 19:48:53 +0700 Message-Id: <20210706124901.1360377-3-dkadashev@gmail.com> X-Mailer: git-send-email 2.30.2 In-Reply-To: <20210706124901.1360377-1-dkadashev@gmail.com> References: <20210706124901.1360377-1-dkadashev@gmail.com> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: linux-fsdevel@vger.kernel.org Pass in the struct filename pointers instead of the user string, and update the three callers to do the same. This is heavily based on commit dbea8d345177 ("fs: make do_renameat2() take struct filename"). This behaves like do_unlinkat() and do_renameat2(). Cc: Al Viro Cc: Linus Torvalds Signed-off-by: Dmitry Kadashev Acked-by: Christian Brauner --- fs/internal.h | 1 + fs/namei.c | 22 ++++++++++++++++------ 2 files changed, 17 insertions(+), 6 deletions(-) diff --git a/fs/internal.h b/fs/internal.h index 6aeae7ef3380..848e165ef0f1 100644 --- a/fs/internal.h +++ b/fs/internal.h @@ -77,6 +77,7 @@ long do_unlinkat(int dfd, struct filename *name); int may_linkat(struct user_namespace *mnt_userns, struct path *link); int do_renameat2(int olddfd, struct filename *oldname, int newdfd, struct filename *newname, unsigned int flags); +long do_mkdirat(int dfd, struct filename *name, umode_t mode); /* * namespace.c diff --git a/fs/namei.c b/fs/namei.c index 70caf4ef1134..8bc65fd357ad 100644 --- a/fs/namei.c +++ b/fs/namei.c @@ -3559,7 +3559,7 @@ struct file *do_file_open_root(struct dentry *dentry, struct vfsmount *mnt, return file; } -static struct dentry *filename_create(int dfd, struct filename *name, +static struct dentry *__filename_create(int dfd, struct filename *name, struct path *path, unsigned int lookup_flags) { struct dentry *dentry = ERR_PTR(-EEXIST); @@ -3615,7 +3615,6 @@ static struct dentry *filename_create(int dfd, struct filename *name, error = err2; goto fail; } - putname(name); return dentry; fail: dput(dentry); @@ -3630,6 +3629,16 @@ static struct dentry *filename_create(int dfd, struct filename *name, return dentry; } +static inline struct dentry *filename_create(int dfd, struct filename *name, + struct path *path, unsigned int lookup_flags) +{ + struct dentry *res = __filename_create(dfd, name, path, lookup_flags); + + if (!IS_ERR(res)) + putname(name); + return res; +} + struct dentry *kern_path_create(int dfd, const char *pathname, struct path *path, unsigned int lookup_flags) { @@ -3820,7 +3829,7 @@ int vfs_mkdir(struct user_namespace *mnt_userns, struct inode *dir, } EXPORT_SYMBOL(vfs_mkdir); -static long do_mkdirat(int dfd, const char __user *pathname, umode_t mode) +long do_mkdirat(int dfd, struct filename *name, umode_t mode) { struct dentry *dentry; struct path path; @@ -3828,7 +3837,7 @@ static long do_mkdirat(int dfd, const char __user *pathname, umode_t mode) unsigned int lookup_flags = LOOKUP_DIRECTORY; retry: - dentry = user_path_create(dfd, pathname, &path, lookup_flags); + dentry = __filename_create(dfd, name, &path, lookup_flags); if (IS_ERR(dentry)) return PTR_ERR(dentry); @@ -3846,17 +3855,18 @@ static long do_mkdirat(int dfd, const char __user *pathname, umode_t mode) lookup_flags |= LOOKUP_REVAL; goto retry; } + putname(name); return error; } SYSCALL_DEFINE3(mkdirat, int, dfd, const char __user *, pathname, umode_t, mode) { - return do_mkdirat(dfd, pathname, mode); + return do_mkdirat(dfd, getname(pathname), mode); } SYSCALL_DEFINE2(mkdir, const char __user *, pathname, umode_t, mode) { - return do_mkdirat(AT_FDCWD, pathname, mode); + return do_mkdirat(AT_FDCWD, getname(pathname), mode); } /** From patchwork Tue Jul 6 12:48:54 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Dmitry Kadashev X-Patchwork-Id: 12360529 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-12.9 required=3.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,FREEMAIL_FORGED_FROMDOMAIN,FREEMAIL_FROM, HEADER_FROM_DIFFERENT_DOMAINS,INCLUDES_CR_TRAILER,INCLUDES_PATCH, MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS,UNWANTED_LANGUAGE_BODY, URIBL_BLOCKED,USER_AGENT_GIT autolearn=ham autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 3818DC07E9E for ; Tue, 6 Jul 2021 12:49:44 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 215AB601FD for ; Tue, 6 Jul 2021 12:49:44 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S238884AbhGFMwV (ORCPT ); Tue, 6 Jul 2021 08:52:21 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:35832 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S241504AbhGFMwE (ORCPT ); Tue, 6 Jul 2021 08:52:04 -0400 Received: from mail-lf1-x12a.google.com (mail-lf1-x12a.google.com [IPv6:2a00:1450:4864:20::12a]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 38B96C0613DB; Tue, 6 Jul 2021 05:49:25 -0700 (PDT) Received: by mail-lf1-x12a.google.com with SMTP id r26so20584299lfp.2; Tue, 06 Jul 2021 05:49:25 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=9/0TTPk6QlPnPGwUZocYubZLcVhXXsqyK1OSZQGMszw=; b=maAgfnQQhcmybjersNcyDtz5dEf3hwUIni7IiCoOxQALsntxRyzOdaTQ25cDyg0Z0x hvIHI1waz0dKchNgPyqiEjVldS/YojMuyPZS7Gwy3xL1M98Pr6pCmHOG9q8YXoVIKlxj s5ZipOnwL3/hNr1AN/2WJFe1cY1dpfNkouMCUuMdPY4Ai5Qc/1gWamvRHgxGDKZc5pDj CfOJ0hGlYzckrILC977J65CyXBUAorCy0RysSpBPVYA3Hc9v0GGoGS6A7XfBe/X/e23u bNujsIdwgycmCIVh/Z176pyzSlgTpTYRSRmnS9iFaCxwZPHOLT/P/kH/Inca98fRET77 bpzQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=9/0TTPk6QlPnPGwUZocYubZLcVhXXsqyK1OSZQGMszw=; b=irarXY88Wo8XcVDfr9Ihr5zAMWVsh98B6/veuA9kZXwa6+GJJ5I3SVGX8rPJIJ6Wto DdrRP+fDee/TS/XrEYwqAjJ4/7U93exjg9eef1YxLhidTmuh/oIbCUnM0Fv/pTT/B4LP E5d0GCN7LCXT4HxifNdFzGGip3LDVn4lRWhkT8MwNEw+5+IImabjnuUE/NW0G58a/raC HKCci7c9U2OWjZ5Ok8blpwdTIREDHL3xly4Sj9MeD2YVxqao15gcLai5aCAagE6HqQlq vBaLBISdw3ktXxUUi63uuU+5NlmJF5uydEQRq1KcNOgm/LWI+Q1wJg0upmi+yyY1l9xC mm/Q== X-Gm-Message-State: AOAM531T9iuYRPQIXVbwz2Qohew0M8Guc5SJ44VhK0SzMfj0NmtoqXkV PCJev0MdspUX15AV1dV5KOc= X-Google-Smtp-Source: ABdhPJwD3UDi088NAuuJeqDuzwEA9UnwEbXwEyOWWMjUmwvtqsM26Y6xx4brIpo9/ONbWss0oQW9bg== X-Received: by 2002:ac2:54a4:: with SMTP id w4mr5012072lfk.100.1625575763634; Tue, 06 Jul 2021 05:49:23 -0700 (PDT) Received: from carbon.v ([94.143.149.146]) by smtp.googlemail.com with ESMTPSA id r18sm139519ljc.120.2021.07.06.05.49.22 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 06 Jul 2021 05:49:23 -0700 (PDT) From: Dmitry Kadashev To: Jens Axboe , Alexander Viro , Christian Brauner , Linus Torvalds Cc: Pavel Begunkov , linux-fsdevel@vger.kernel.org, io-uring@vger.kernel.org, Dmitry Kadashev Subject: [PATCH v7 03/10] io_uring: add support for IORING_OP_MKDIRAT Date: Tue, 6 Jul 2021 19:48:54 +0700 Message-Id: <20210706124901.1360377-4-dkadashev@gmail.com> X-Mailer: git-send-email 2.30.2 In-Reply-To: <20210706124901.1360377-1-dkadashev@gmail.com> References: <20210706124901.1360377-1-dkadashev@gmail.com> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: linux-fsdevel@vger.kernel.org IORING_OP_MKDIRAT behaves like mkdirat(2) and takes the same flags and arguments. Cc: Linus Torvalds Signed-off-by: Dmitry Kadashev Acked-by: Christian Brauner --- fs/io_uring.c | 59 +++++++++++++++++++++++++++++++++++ include/uapi/linux/io_uring.h | 1 + 2 files changed, 60 insertions(+) diff --git a/fs/io_uring.c b/fs/io_uring.c index 5b840bb1e8ec..42d54f9bbbb2 100644 --- a/fs/io_uring.c +++ b/fs/io_uring.c @@ -674,6 +674,13 @@ struct io_unlink { struct filename *filename; }; +struct io_mkdir { + struct file *file; + int dfd; + umode_t mode; + struct filename *filename; +}; + struct io_completion { struct file *file; struct list_head list; @@ -831,6 +838,7 @@ struct io_kiocb { struct io_shutdown shutdown; struct io_rename rename; struct io_unlink unlink; + struct io_mkdir mkdir; /* use only after cleaning per-op data, see io_clean_op() */ struct io_completion compl; }; @@ -1042,6 +1050,7 @@ static const struct io_op_def io_op_defs[] = { }, [IORING_OP_RENAMEAT] = {}, [IORING_OP_UNLINKAT] = {}, + [IORING_OP_MKDIRAT] = {}, }; static bool io_disarm_next(struct io_kiocb *req); @@ -3545,6 +3554,48 @@ static int io_unlinkat(struct io_kiocb *req, unsigned int issue_flags) return 0; } +static int io_mkdirat_prep(struct io_kiocb *req, + const struct io_uring_sqe *sqe) +{ + struct io_mkdir *mkd = &req->mkdir; + const char __user *fname; + + if (unlikely(req->ctx->flags & IORING_SETUP_IOPOLL)) + return -EINVAL; + if (sqe->ioprio || sqe->off || sqe->rw_flags || sqe->buf_index) + return -EINVAL; + if (unlikely(req->flags & REQ_F_FIXED_FILE)) + return -EBADF; + + mkd->dfd = READ_ONCE(sqe->fd); + mkd->mode = READ_ONCE(sqe->len); + + fname = u64_to_user_ptr(READ_ONCE(sqe->addr)); + mkd->filename = getname(fname); + if (IS_ERR(mkd->filename)) + return PTR_ERR(mkd->filename); + + req->flags |= REQ_F_NEED_CLEANUP; + return 0; +} + +static int io_mkdirat(struct io_kiocb *req, int issue_flags) +{ + struct io_mkdir *mkd = &req->mkdir; + int ret; + + if (issue_flags & IO_URING_F_NONBLOCK) + return -EAGAIN; + + ret = do_mkdirat(mkd->dfd, mkd->filename, mkd->mode); + + req->flags &= ~REQ_F_NEED_CLEANUP; + if (ret < 0) + req_set_fail(req); + io_req_complete(req, ret); + return 0; +} + static int io_shutdown_prep(struct io_kiocb *req, const struct io_uring_sqe *sqe) { @@ -5953,6 +6004,8 @@ static int io_req_prep(struct io_kiocb *req, const struct io_uring_sqe *sqe) return io_renameat_prep(req, sqe); case IORING_OP_UNLINKAT: return io_unlinkat_prep(req, sqe); + case IORING_OP_MKDIRAT: + return io_mkdirat_prep(req, sqe); } printk_once(KERN_WARNING "io_uring: unhandled opcode %d\n", @@ -6114,6 +6167,9 @@ static void io_clean_op(struct io_kiocb *req) case IORING_OP_UNLINKAT: putname(req->unlink.filename); break; + case IORING_OP_MKDIRAT: + putname(req->mkdir.filename); + break; } } if ((req->flags & REQ_F_POLLED) && req->apoll) { @@ -6242,6 +6298,9 @@ static int io_issue_sqe(struct io_kiocb *req, unsigned int issue_flags) case IORING_OP_UNLINKAT: ret = io_unlinkat(req, issue_flags); break; + case IORING_OP_MKDIRAT: + ret = io_mkdirat(req, issue_flags); + break; default: ret = -EINVAL; break; diff --git a/include/uapi/linux/io_uring.h b/include/uapi/linux/io_uring.h index 79126d5cd289..a926407c230e 100644 --- a/include/uapi/linux/io_uring.h +++ b/include/uapi/linux/io_uring.h @@ -133,6 +133,7 @@ enum { IORING_OP_SHUTDOWN, IORING_OP_RENAMEAT, IORING_OP_UNLINKAT, + IORING_OP_MKDIRAT, /* this goes last, obviously */ IORING_OP_LAST, From patchwork Tue Jul 6 12:48:55 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Dmitry Kadashev X-Patchwork-Id: 12360531 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-12.9 required=3.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,FREEMAIL_FORGED_FROMDOMAIN,FREEMAIL_FROM, HEADER_FROM_DIFFERENT_DOMAINS,INCLUDES_CR_TRAILER,INCLUDES_PATCH, MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS,UNWANTED_LANGUAGE_BODY, URIBL_BLOCKED,USER_AGENT_GIT autolearn=unavailable autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 14931C07E9B for ; Tue, 6 Jul 2021 12:49:53 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id E7C5C61166 for ; Tue, 6 Jul 2021 12:49:52 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S232420AbhGFMwa (ORCPT ); Tue, 6 Jul 2021 08:52:30 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:35908 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S238698AbhGFMwF (ORCPT ); Tue, 6 Jul 2021 08:52:05 -0400 Received: from mail-lf1-x134.google.com (mail-lf1-x134.google.com [IPv6:2a00:1450:4864:20::134]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 61FE5C06175F; Tue, 6 Jul 2021 05:49:26 -0700 (PDT) Received: by mail-lf1-x134.google.com with SMTP id v14so12545588lfb.4; Tue, 06 Jul 2021 05:49:26 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=tPu24Nbaaffql0eGi2id6DLtb7/OVopMbz8ZSt5K/Is=; b=ZzdIkUSPvVhkHZofM1ZoQKjurItoIqOj5KagBMunGxG6rrjVs48Wt1qWU5d+mp8IJY lDApPYV+us25Js5hUqZDyHSMY+fEpIBZuxbvly6vnjrZWKvbmVO/NS9XpCSI7zHFohGF UpT2nK9jQ+sbftz/KqLfxEoaKdRSLFnWlw2fOPUCeCt0AGT9Z79Pb9OJBY4UH5hZyNgI TLoY0aTZSNUiDBjFyMUK5CrC6hBONhYR/8L5CyifSO43tnA7WfHDZ/hfatPpehZa45ep C/mI6EH1GdUIv7wF+CofJm8Ng8iXFegd54r7gVL7DAS96KXvK7WBlAEzYdgZekU2EVHQ XsNg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=tPu24Nbaaffql0eGi2id6DLtb7/OVopMbz8ZSt5K/Is=; b=eqEaHS2eC/eL+/ytMAUmigdIvKvPrAGRpWLsbxQZUwoa1+FRTh2AKeewP+VM4TbT7a Mz+ZrrZmtiynQnl4lANvwrdca1O2pBeCBtqbok+u6VMnv8ZOh85gHeoNnV00bfPRnCsD UoA9Kwiz5sUVBoTqpvElYinyEdqtaX6ZUK465kq/SL7Fst1LPt5BLZuRvnIPnyfH1Css qkOypEtXDuX6tL+kJHfMZLsChZeME+NHwnCbDuP8xY+1JMqtSioQ0MWQFoalkzPQIbei IHkGOVdFNrZYv1ax0BRwT8Y5ZHKsTSPn3JRiLfty3fPAvSOkPFx38wykOxaKHC9EFF9I m6bQ== X-Gm-Message-State: AOAM5328XMfTlMOHDyK+wvjKrJhVbBLrDmChna43sjl4aASfmq6LmPD5 xJ8jREUyG/Jan79ShQesXTE= X-Google-Smtp-Source: ABdhPJy9RjJaIlXnnq+e5caG5Ty58BQnMfnuVjcKGt7wY0gSHE06DjE66VY1gPXCAe+ow+7IkDmzVw== X-Received: by 2002:a05:6512:22d5:: with SMTP id g21mr2986535lfu.391.1625575764811; Tue, 06 Jul 2021 05:49:24 -0700 (PDT) Received: from carbon.v ([94.143.149.146]) by smtp.googlemail.com with ESMTPSA id r18sm139519ljc.120.2021.07.06.05.49.23 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 06 Jul 2021 05:49:24 -0700 (PDT) From: Dmitry Kadashev To: Jens Axboe , Alexander Viro , Christian Brauner , Linus Torvalds Cc: Pavel Begunkov , linux-fsdevel@vger.kernel.org, io-uring@vger.kernel.org, Dmitry Kadashev Subject: [PATCH v7 04/10] fs: make do_mknodat() take struct filename Date: Tue, 6 Jul 2021 19:48:55 +0700 Message-Id: <20210706124901.1360377-5-dkadashev@gmail.com> X-Mailer: git-send-email 2.30.2 In-Reply-To: <20210706124901.1360377-1-dkadashev@gmail.com> References: <20210706124901.1360377-1-dkadashev@gmail.com> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: linux-fsdevel@vger.kernel.org Pass in the struct filename pointers instead of the user string, for uniformity with the recently converted do_unlinkat(), do_renameat(), do_mkdirat(). Cc: Linus Torvalds Cc: Al Viro Cc: Christian Brauner Link: https://lore.kernel.org/io-uring/20210330071700.kpjoyp5zlni7uejm@wittgenstein/ Signed-off-by: Dmitry Kadashev Acked-by: Christian Brauner --- fs/namei.c | 16 +++++++++------- 1 file changed, 9 insertions(+), 7 deletions(-) diff --git a/fs/namei.c b/fs/namei.c index 8bc65fd357ad..34b8968dec92 100644 --- a/fs/namei.c +++ b/fs/namei.c @@ -3727,7 +3727,7 @@ static int may_mknod(umode_t mode) } } -static long do_mknodat(int dfd, const char __user *filename, umode_t mode, +static long do_mknodat(int dfd, struct filename *name, umode_t mode, unsigned int dev) { struct user_namespace *mnt_userns; @@ -3738,9 +3738,9 @@ static long do_mknodat(int dfd, const char __user *filename, umode_t mode, error = may_mknod(mode); if (error) - return error; + goto out1; retry: - dentry = user_path_create(dfd, filename, &path, lookup_flags); + dentry = __filename_create(dfd, name, &path, lookup_flags); if (IS_ERR(dentry)) return PTR_ERR(dentry); @@ -3748,7 +3748,7 @@ static long do_mknodat(int dfd, const char __user *filename, umode_t mode, mode &= ~current_umask(); error = security_path_mknod(&path, dentry, mode, dev); if (error) - goto out; + goto out2; mnt_userns = mnt_user_ns(path.mnt); switch (mode & S_IFMT) { @@ -3767,24 +3767,26 @@ static long do_mknodat(int dfd, const char __user *filename, umode_t mode, dentry, mode, 0); break; } -out: +out2: done_path_create(&path, dentry); if (retry_estale(error, lookup_flags)) { lookup_flags |= LOOKUP_REVAL; goto retry; } +out1: + putname(name); return error; } SYSCALL_DEFINE4(mknodat, int, dfd, const char __user *, filename, umode_t, mode, unsigned int, dev) { - return do_mknodat(dfd, filename, mode, dev); + return do_mknodat(dfd, getname(filename), mode, dev); } SYSCALL_DEFINE3(mknod, const char __user *, filename, umode_t, mode, unsigned, dev) { - return do_mknodat(AT_FDCWD, filename, mode, dev); + return do_mknodat(AT_FDCWD, getname(filename), mode, dev); } /** From patchwork Tue Jul 6 12:48:56 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Dmitry Kadashev X-Patchwork-Id: 12360533 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-15.7 required=3.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,FREEMAIL_FORGED_FROMDOMAIN,FREEMAIL_FROM, HEADER_FROM_DIFFERENT_DOMAINS,INCLUDES_CR_TRAILER,INCLUDES_PATCH, MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS,URIBL_BLOCKED,USER_AGENT_GIT autolearn=ham autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id B6508C07E9E for ; Tue, 6 Jul 2021 12:49:53 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id A3763601FD for ; Tue, 6 Jul 2021 12:49:53 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S233146AbhGFMwb (ORCPT ); Tue, 6 Jul 2021 08:52:31 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:35914 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S241542AbhGFMwI (ORCPT ); Tue, 6 Jul 2021 08:52:08 -0400 Received: from mail-lj1-x22a.google.com (mail-lj1-x22a.google.com [IPv6:2a00:1450:4864:20::22a]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id A0FA4C0613DC; Tue, 6 Jul 2021 05:49:27 -0700 (PDT) Received: by mail-lj1-x22a.google.com with SMTP id s18so7172871ljg.7; Tue, 06 Jul 2021 05:49:27 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=A3R2pVP2sKQYuRMhVaQbdCO9y7ULwCGT8uQ0UDTT414=; b=p6FloF2pJGN0SMloBnyXy1dnp9Of0CbXi0qBHXcWFBdidOTaxneAaMxisRrQkkttQQ jqBCLoDSjF9SQW8S0qPDkDzIdIlVwo5k6i7wWeMFzpCrA1WDNKo8h0tvyQ741ifDKwcG dbd19QXsFs4qnhEwHbaBlxmu3ltEQKQGtdxrRhmLOAVWBJd/P3hMY/yxj8H3WVX79BQE V8ylKU7swTfOwAN19tqLEa1dc8c+FuPWLG7NAu5W/dCnml/pSeCKFL3UlEarVVLIC/Eo 88zBQZuShiU/ZldfIMc99Bl6QddlMn2d0xoLAkSZFPI+PheJJqf1vqz5ssqqH59ajaWE ue/Q== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=A3R2pVP2sKQYuRMhVaQbdCO9y7ULwCGT8uQ0UDTT414=; b=Ph2V8jR1CggtmcGgIzW9qh4//pcpGdsy4J6/NvdyDj0S4wriFwU2dxNJMxaTtxD5OG gQZjjFKCa/MAZY4gw24EgOhO6H7IqspmND4cfFqsjO1CDFxkvxxQWTqJzTPAltSpBKr2 62/pEIt15kn8jXaFcAHFIiof7Km84sjTgLg8ZSRr3vooIjkHhUwYywSVuA/JFPvL6MiZ N8verzyw94hB/OHR/mXOuAnNXUxBdN8CF3+NLMbwOLNSOT0oNKmiP7QerAYH1lc0x6Gh zjdS/afj+KIDocnHOz30K/CMyw7asEN85rE9J2EQdxxl2iYtoJkgjrkgOVVEndbHu17p cVyQ== X-Gm-Message-State: AOAM532X1XU+NQjYM+aqxJK7SzEiURGS4tZiEU0Mq4S402hvDjQYmODN +t8eOl7X4jGfoYn388peKxw= X-Google-Smtp-Source: ABdhPJxocVVf3x4e1yBMfjSkmBP4JmezSgnu8VIiZVmE5LEL3tUFeo4qkao4NxDl5lMZslElppcu6g== X-Received: by 2002:a2e:9759:: with SMTP id f25mr7490855ljj.15.1625575766068; Tue, 06 Jul 2021 05:49:26 -0700 (PDT) Received: from carbon.v ([94.143.149.146]) by smtp.googlemail.com with ESMTPSA id r18sm139519ljc.120.2021.07.06.05.49.24 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 06 Jul 2021 05:49:25 -0700 (PDT) From: Dmitry Kadashev To: Jens Axboe , Alexander Viro , Christian Brauner , Linus Torvalds Cc: Pavel Begunkov , linux-fsdevel@vger.kernel.org, io-uring@vger.kernel.org, Dmitry Kadashev Subject: [PATCH v7 05/10] fs: make do_symlinkat() take struct filename Date: Tue, 6 Jul 2021 19:48:56 +0700 Message-Id: <20210706124901.1360377-6-dkadashev@gmail.com> X-Mailer: git-send-email 2.30.2 In-Reply-To: <20210706124901.1360377-1-dkadashev@gmail.com> References: <20210706124901.1360377-1-dkadashev@gmail.com> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: linux-fsdevel@vger.kernel.org Pass in the struct filename pointers instead of the user string, for uniformity with the recently converted do_mkdnodat(), do_unlinkat(), do_renameat(), do_mkdirat(). Cc: Linus Torvalds Cc: Al Viro Cc: Christian Brauner Link: https://lore.kernel.org/io-uring/20210330071700.kpjoyp5zlni7uejm@wittgenstein/ Signed-off-by: Dmitry Kadashev Acked-by: Christian Brauner --- fs/namei.c | 24 +++++++++++++----------- 1 file changed, 13 insertions(+), 11 deletions(-) diff --git a/fs/namei.c b/fs/namei.c index 34b8968dec92..57170d57e84d 100644 --- a/fs/namei.c +++ b/fs/namei.c @@ -4191,23 +4191,23 @@ int vfs_symlink(struct user_namespace *mnt_userns, struct inode *dir, } EXPORT_SYMBOL(vfs_symlink); -static long do_symlinkat(const char __user *oldname, int newdfd, - const char __user *newname) +static long do_symlinkat(struct filename *from, int newdfd, + struct filename *to) { int error; - struct filename *from; struct dentry *dentry; struct path path; unsigned int lookup_flags = 0; - from = getname(oldname); - if (IS_ERR(from)) - return PTR_ERR(from); + if (IS_ERR(from)) { + error = PTR_ERR(from); + goto out_putboth; + } retry: - dentry = user_path_create(newdfd, newname, &path, lookup_flags); + dentry = __filename_create(newdfd, to, &path, lookup_flags); error = PTR_ERR(dentry); if (IS_ERR(dentry)) - goto out_putname; + goto out_putfrom; error = security_path_symlink(&path, dentry, from->name); if (!error) { @@ -4222,7 +4222,9 @@ static long do_symlinkat(const char __user *oldname, int newdfd, lookup_flags |= LOOKUP_REVAL; goto retry; } -out_putname: +out_putboth: + putname(to); +out_putfrom: putname(from); return error; } @@ -4230,12 +4232,12 @@ static long do_symlinkat(const char __user *oldname, int newdfd, SYSCALL_DEFINE3(symlinkat, const char __user *, oldname, int, newdfd, const char __user *, newname) { - return do_symlinkat(oldname, newdfd, newname); + return do_symlinkat(getname(oldname), newdfd, getname(newname)); } SYSCALL_DEFINE2(symlink, const char __user *, oldname, const char __user *, newname) { - return do_symlinkat(oldname, AT_FDCWD, newname); + return do_symlinkat(getname(oldname), AT_FDCWD, getname(newname)); } /** From patchwork Tue Jul 6 12:48:57 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Dmitry Kadashev X-Patchwork-Id: 12360535 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-15.7 required=3.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,FREEMAIL_FORGED_FROMDOMAIN,FREEMAIL_FROM, HEADER_FROM_DIFFERENT_DOMAINS,INCLUDES_CR_TRAILER,INCLUDES_PATCH, MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS,URIBL_BLOCKED,USER_AGENT_GIT autolearn=unavailable autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id A68F1C07E96 for ; Tue, 6 Jul 2021 12:49:54 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 944BF61166 for ; Tue, 6 Jul 2021 12:49:54 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S232357AbhGFMwb (ORCPT ); Tue, 6 Jul 2021 08:52:31 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:35920 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S241547AbhGFMwI (ORCPT ); Tue, 6 Jul 2021 08:52:08 -0400 Received: from mail-lf1-x135.google.com (mail-lf1-x135.google.com [IPv6:2a00:1450:4864:20::135]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id D1755C0613DD; Tue, 6 Jul 2021 05:49:28 -0700 (PDT) Received: by mail-lf1-x135.google.com with SMTP id v14so12545826lfb.4; Tue, 06 Jul 2021 05:49:28 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=WkJGb3hmdHjOYQaewm0wQtiLEaHfags/GYZjg3z/bDI=; b=EyOdTcjQ+QBwPYgeuX4oERwhVfM1TIKGrAJRzaApFVmMX/2sETmVVCRjLivCir1561 VfNqZBqRYAwRaOT16RD8zJue5I9wq3fN/+Hhz61/y2JkKSMBW0uFEUCl8UkhcfmK0qYw GWBoZj8SlL2uOCU5JjnHFZgrSGPmQS6lgLSJ+I2S4t4HWEZBxhPD8Ij8iXZkL7jwrAQM 5mnEa6lgk0DMhQb2GXZWl0QQLj/Pcnno5EDuKpirLd2VYpfcYeWFsREvKKhGvTEbwwct sSrfIGdlVW44DRpouWISNbcHC37I6gdxAoMV5waKBtZ4F6TO6dmfWnBwPmzCPX5bGocl kN6Q== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=WkJGb3hmdHjOYQaewm0wQtiLEaHfags/GYZjg3z/bDI=; b=eqmbnQ+9wYFSNQoakigAeckaOIRW2ofBLbXCdnTYYniJODctY0ifpnB6EXSqAZgD// N/fnJPB0Mu+sLKDoXf5fexQHhd2IKANxwrSrrs6vfA3MQEj1l/DiJIqc6bhq9eY0EsX6 YQZV7CM7gEznSXJWs0J4PVOTXlTRwe+3zg2ne59ttol6b8AUTssl3qWKG5KhHYndhwix mJFIlaGB0ZE6QIWrNWPxd7jbOe94uHOW9sO8W/F6qUxMOBMgAxj5ItsdeM8Heh17qcJU RRggwkSt1ph7U6lxxhHYiEYzNKVjefFtXH7Xk0ZKGpMdRhNUHKSR5bfqpGV4f0waTgg4 myQg== X-Gm-Message-State: AOAM530I64iWqKkQpV7z+0OYksgkddjhTVMj3T6cg3GNiCpgG7oOncLs CXtG2B5dXZp5+YXgtppgfiM= X-Google-Smtp-Source: ABdhPJzog99PSephaO8dD/CEfhrrPOn/dOH3lhAa3XXooHUqxwXYCjCd8EQtY1n3pOa07sy90Mb4xA== X-Received: by 2002:a19:6903:: with SMTP id e3mr8013646lfc.264.1625575767280; Tue, 06 Jul 2021 05:49:27 -0700 (PDT) Received: from carbon.v ([94.143.149.146]) by smtp.googlemail.com with ESMTPSA id r18sm139519ljc.120.2021.07.06.05.49.26 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 06 Jul 2021 05:49:26 -0700 (PDT) From: Dmitry Kadashev To: Jens Axboe , Alexander Viro , Christian Brauner , Linus Torvalds Cc: Pavel Begunkov , linux-fsdevel@vger.kernel.org, io-uring@vger.kernel.org, Dmitry Kadashev Subject: [PATCH v7 06/10] namei: add getname_uflags() Date: Tue, 6 Jul 2021 19:48:57 +0700 Message-Id: <20210706124901.1360377-7-dkadashev@gmail.com> X-Mailer: git-send-email 2.30.2 In-Reply-To: <20210706124901.1360377-1-dkadashev@gmail.com> References: <20210706124901.1360377-1-dkadashev@gmail.com> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: linux-fsdevel@vger.kernel.org There are a couple of places where we already open-code the (flags & AT_EMPTY_PATH) check and io_uring will likely add another one in the future. Let's just add a simple helper getname_uflags() that handles this directly and use it. Cc: Linus Torvalds Cc: Al Viro Cc: Christian Brauner Link: https://lore.kernel.org/io-uring/20210415100815.edrn4a7cy26wkowe@wittgenstein/ Signed-off-by: Christian Brauner Signed-off-by: Dmitry Kadashev Acked-by: Christian Brauner --- fs/exec.c | 8 ++------ fs/namei.c | 8 ++++++++ include/linux/fs.h | 1 + 3 files changed, 11 insertions(+), 6 deletions(-) diff --git a/fs/exec.c b/fs/exec.c index 18594f11c31f..df33ecaf2111 100644 --- a/fs/exec.c +++ b/fs/exec.c @@ -2069,10 +2069,8 @@ SYSCALL_DEFINE5(execveat, const char __user *const __user *, envp, int, flags) { - int lookup_flags = (flags & AT_EMPTY_PATH) ? LOOKUP_EMPTY : 0; - return do_execveat(fd, - getname_flags(filename, lookup_flags, NULL), + getname_uflags(filename, flags), argv, envp, flags); } @@ -2090,10 +2088,8 @@ COMPAT_SYSCALL_DEFINE5(execveat, int, fd, const compat_uptr_t __user *, envp, int, flags) { - int lookup_flags = (flags & AT_EMPTY_PATH) ? LOOKUP_EMPTY : 0; - return compat_do_execveat(fd, - getname_flags(filename, lookup_flags, NULL), + getname_uflags(filename, flags), argv, envp, flags); } #endif diff --git a/fs/namei.c b/fs/namei.c index 57170d57e84d..70a3c5124db3 100644 --- a/fs/namei.c +++ b/fs/namei.c @@ -203,6 +203,14 @@ getname_flags(const char __user *filename, int flags, int *empty) return result; } +struct filename * +getname_uflags(const char __user *filename, int uflags) +{ + int flags = (uflags & AT_EMPTY_PATH) ? LOOKUP_EMPTY : 0; + + return getname_flags(filename, flags, NULL); +} + struct filename * getname(const char __user * filename) { diff --git a/include/linux/fs.h b/include/linux/fs.h index c3c88fdb9b2a..5885a68d2c12 100644 --- a/include/linux/fs.h +++ b/include/linux/fs.h @@ -2781,6 +2781,7 @@ static inline struct file *file_clone_open(struct file *file) extern int filp_close(struct file *, fl_owner_t id); extern struct filename *getname_flags(const char __user *, int, int *); +extern struct filename *getname_uflags(const char __user *, int); extern struct filename *getname(const char __user *); extern struct filename *getname_kernel(const char *); extern void putname(struct filename *name); From patchwork Tue Jul 6 12:48:58 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Dmitry Kadashev X-Patchwork-Id: 12360537 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-15.7 required=3.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,FREEMAIL_FORGED_FROMDOMAIN,FREEMAIL_FROM, HEADER_FROM_DIFFERENT_DOMAINS,INCLUDES_CR_TRAILER,INCLUDES_PATCH, MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS,URIBL_BLOCKED,USER_AGENT_GIT autolearn=unavailable autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id AD773C11F66 for ; Tue, 6 Jul 2021 12:49:55 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 9872C611AF for ; Tue, 6 Jul 2021 12:49:55 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S233396AbhGFMwc (ORCPT ); Tue, 6 Jul 2021 08:52:32 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:35928 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S241581AbhGFMwJ (ORCPT ); Tue, 6 Jul 2021 08:52:09 -0400 Received: from mail-lf1-x129.google.com (mail-lf1-x129.google.com [IPv6:2a00:1450:4864:20::129]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 08D21C0613DF; Tue, 6 Jul 2021 05:49:30 -0700 (PDT) Received: by mail-lf1-x129.google.com with SMTP id y42so2836055lfa.3; Tue, 06 Jul 2021 05:49:29 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=bXHmKGf9s34tUbivjGry2QpdM+WhLY3D95j9pn9YUQc=; b=JrL4KSYaIUc7Hos/tqCB8qqClVieoxzVDEd4PusBL+22wmzJsPOBSdeS1XSIKoroYI xcUkyStadhRxxWWHnbScZuXe3uuj94D7UcbAUR60Bmuhg4tXYhX6973GcKa5xnqXpitJ lkK2AY8GT6jFXg4ltEjT78FArBBrsFjl3c/vxZYVYFJeAtWjBS74zMPBWfMCtKjQQKeU U/MMT2TzOFYKrawe9EgzO4xVkSBGLDBNRV8M3VqXmJy+d4I7iNqX830D+Yuy23ivDZGV 2kwCDKlH1igMJfWp6DbzYL6tJcv9dSSM+GHOSW8PffbN5nitCSgHZGlBfJkkrMcRf/lI lEsg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=bXHmKGf9s34tUbivjGry2QpdM+WhLY3D95j9pn9YUQc=; b=uf0dgjmSUMiVA6Qrbl1Owl6T5Z0N8wcmZNaspnn688hFdRkMzm+u5NHRl/wL5jgbcU c5eQtQhzGQUtAIqV0ZUYzNJ3D6kKAHSDUgsq92kx/WoO3htMKHaiun9XRYytpyjyt+dJ FYMN631Z319fnDoAJdIzrPZjdpqyNXzzJnLLbKvYJvnwL4X8rV6GWXNrrb3LTwgUtmkY eFCb31p5ayiPyS3PcPaK2U8KjtAQiTblHfEyTpJRiIAp3PyBX0OFmIktZ/K/LTN91Ew9 wMGeMo8S1oePTdHMWjJBERHDep3YQExyjBT0LHGJudA6U7gEfCSbH8B7NBvFUSY+3M7v D7/w== X-Gm-Message-State: AOAM53110W9FbMUdYYUDvkYPIGTV0oJpNgB2XM5dhNMujAyg+0TOnHsh 9xRbj2zB4Y4bdiG/rFhAvZQ= X-Google-Smtp-Source: ABdhPJyLadfVOw66hPLNY4hfAGcQzZXS1jSOJpdaOn0YHvkxP5OVqcx2GdRaZEk4w8Pzwb7YGYFzUA== X-Received: by 2002:a05:6512:32c9:: with SMTP id f9mr14570902lfg.638.1625575768458; Tue, 06 Jul 2021 05:49:28 -0700 (PDT) Received: from carbon.v ([94.143.149.146]) by smtp.googlemail.com with ESMTPSA id r18sm139519ljc.120.2021.07.06.05.49.27 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 06 Jul 2021 05:49:28 -0700 (PDT) From: Dmitry Kadashev To: Jens Axboe , Alexander Viro , Christian Brauner , Linus Torvalds Cc: Pavel Begunkov , linux-fsdevel@vger.kernel.org, io-uring@vger.kernel.org, Dmitry Kadashev Subject: [PATCH v7 07/10] fs: make do_linkat() take struct filename Date: Tue, 6 Jul 2021 19:48:58 +0700 Message-Id: <20210706124901.1360377-8-dkadashev@gmail.com> X-Mailer: git-send-email 2.30.2 In-Reply-To: <20210706124901.1360377-1-dkadashev@gmail.com> References: <20210706124901.1360377-1-dkadashev@gmail.com> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: linux-fsdevel@vger.kernel.org Pass in the struct filename pointers instead of the user string, for uniformity with do_renameat2, do_unlinkat, do_mknodat, etc. Cc: Linus Torvalds Cc: Al Viro Cc: Christian Brauner Link: https://lore.kernel.org/io-uring/20210330071700.kpjoyp5zlni7uejm@wittgenstein/ Signed-off-by: Dmitry Kadashev Acked-by: Christian Brauner --- fs/namei.c | 57 +++++++++++++++++++++++++++++++++++++----------------- 1 file changed, 39 insertions(+), 18 deletions(-) diff --git a/fs/namei.c b/fs/namei.c index 70a3c5124db3..0a2731f7ef71 100644 --- a/fs/namei.c +++ b/fs/namei.c @@ -2450,7 +2450,7 @@ static int path_lookupat(struct nameidata *nd, unsigned flags, struct path *path return err; } -int filename_lookup(int dfd, struct filename *name, unsigned flags, +static int __filename_lookup(int dfd, struct filename *name, unsigned flags, struct path *path, struct path *root) { int retval; @@ -2472,7 +2472,18 @@ int filename_lookup(int dfd, struct filename *name, unsigned flags, audit_inode(name, path->dentry, flags & LOOKUP_MOUNTPOINT ? AUDIT_INODE_NOEVAL : 0); restore_nameidata(); - putname(name); + if (retval) + putname(name); + return retval; +} + +int filename_lookup(int dfd, struct filename *name, unsigned flags, + struct path *path, struct path *root) +{ + int retval = __filename_lookup(dfd, name, flags, path, root); + + if (!retval) + putname(name); return retval; } @@ -4346,8 +4357,8 @@ EXPORT_SYMBOL(vfs_link); * with linux 2.0, and to avoid hard-linking to directories * and other special files. --ADM */ -static int do_linkat(int olddfd, const char __user *oldname, int newdfd, - const char __user *newname, int flags) +static int do_linkat(int olddfd, struct filename *old, int newdfd, + struct filename *new, int flags) { struct user_namespace *mnt_userns; struct dentry *new_dentry; @@ -4356,31 +4367,36 @@ static int do_linkat(int olddfd, const char __user *oldname, int newdfd, int how = 0; int error; - if ((flags & ~(AT_SYMLINK_FOLLOW | AT_EMPTY_PATH)) != 0) - return -EINVAL; + if ((flags & ~(AT_SYMLINK_FOLLOW | AT_EMPTY_PATH)) != 0) { + error = -EINVAL; + goto out_putnames; + } /* * To use null names we require CAP_DAC_READ_SEARCH * This ensures that not everyone will be able to create * handlink using the passed filedescriptor. */ - if (flags & AT_EMPTY_PATH) { - if (!capable(CAP_DAC_READ_SEARCH)) - return -ENOENT; - how = LOOKUP_EMPTY; + if (flags & AT_EMPTY_PATH && !capable(CAP_DAC_READ_SEARCH)) { + error = -ENOENT; + goto out_putnames; } if (flags & AT_SYMLINK_FOLLOW) how |= LOOKUP_FOLLOW; retry: - error = user_path_at(olddfd, oldname, how, &old_path); + error = __filename_lookup(olddfd, old, how, &old_path, NULL); if (error) - return error; + goto out_putnew; - new_dentry = user_path_create(newdfd, newname, &new_path, + new_dentry = __filename_create(newdfd, new, &new_path, (how & LOOKUP_REVAL)); error = PTR_ERR(new_dentry); - if (IS_ERR(new_dentry)) - goto out; + if (IS_ERR(new_dentry)) { + // On error `new` is freed by __filename_create, set to NULL to + // signal that we do not have to free it below + new = NULL; + goto out_putpath; + } error = -EXDEV; if (old_path.mnt != new_path.mnt) @@ -4408,8 +4424,12 @@ static int do_linkat(int olddfd, const char __user *oldname, int newdfd, how |= LOOKUP_REVAL; goto retry; } -out: +out_putpath: path_put(&old_path); +out_putnames: + putname(old); +out_putnew: + putname(new); return error; } @@ -4417,12 +4437,13 @@ static int do_linkat(int olddfd, const char __user *oldname, int newdfd, SYSCALL_DEFINE5(linkat, int, olddfd, const char __user *, oldname, int, newdfd, const char __user *, newname, int, flags) { - return do_linkat(olddfd, oldname, newdfd, newname, flags); + return do_linkat(olddfd, getname_uflags(oldname, flags), + newdfd, getname(newname), flags); } SYSCALL_DEFINE2(link, const char __user *, oldname, const char __user *, newname) { - return do_linkat(AT_FDCWD, oldname, AT_FDCWD, newname, 0); + return do_linkat(AT_FDCWD, getname(oldname), AT_FDCWD, getname(newname), 0); } /** From patchwork Tue Jul 6 12:48:59 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Dmitry Kadashev X-Patchwork-Id: 12360539 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-15.7 required=3.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,FREEMAIL_FORGED_FROMDOMAIN,FREEMAIL_FROM, HEADER_FROM_DIFFERENT_DOMAINS,INCLUDES_CR_TRAILER,INCLUDES_PATCH, MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS,URIBL_BLOCKED,USER_AGENT_GIT autolearn=unavailable autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id E9458C07E9B for ; Tue, 6 Jul 2021 12:50:00 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id D8F606121E for ; Tue, 6 Jul 2021 12:50:00 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S235100AbhGFMwi (ORCPT ); Tue, 6 Jul 2021 08:52:38 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:35842 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S241617AbhGFMwL (ORCPT ); Tue, 6 Jul 2021 08:52:11 -0400 Received: from mail-lf1-x12d.google.com (mail-lf1-x12d.google.com [IPv6:2a00:1450:4864:20::12d]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 3CB6BC061762; Tue, 6 Jul 2021 05:49:31 -0700 (PDT) Received: by mail-lf1-x12d.google.com with SMTP id n14so38115771lfu.8; Tue, 06 Jul 2021 05:49:31 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=U3TpmkEbOEl8XxDNCUtx8QPNmXronxF1cOY9CIR3fQs=; b=i26gSEhaDfFOVJ+lkynY5yB2vlj1NKszOie41PEK2RPDegL5+GPPm8R5X2mJDpCC1b fqnW23DxNcd5H8mbdvwS1Vn40tOOISMf1vmeJ1R/P/regCZYQJq6+jwQSgop7/dU7uoO ouqmDhvxAIUMkpyt7oOyxeS6TKk/t9EE0jYqxXTHOVnxHeQz8/2Ix7WMzpccNhHb8ORd UeTumPPOiHpGgzdasDIkMzVP2q2qaMAFz2309RWCGlSumbZkKuPn8BFa+3jJYpfdJnLv P7GRs92+JrsyuJtDEm04by6nJJgWIT021Oj8uPWe0hL1Zb/wYmxk3xeaiv+bflFmQSwI B9IA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=U3TpmkEbOEl8XxDNCUtx8QPNmXronxF1cOY9CIR3fQs=; b=X9U49zfVwcBqHQyDhG29EVy+VKmPwgx/kiETr1KHeie0NxAkL4OpXKw7eczogg9oto qhZab20grWLUoHdG+VpxaTdkwtvxZvyDHyP3FNPF3PijAVI8z/7XHW3WzcGxB0T6LXHA T9TkHzhyKFD8YQ5Zke7eDHqbfmK1OtOwqc9BW2+yjDOktBdUfdgdWM5LBxIQHgJA2BmM RW2XEfJF3XilO0gGAH85Pl/9vVu4fl9FqvHgacEE9e8gMtlAl0qyvonA570SzraPX6bF g7fhPGdE2w2WXCGMOvwK2thYPnmNEhBIG8H/2UuXHbHVCvIU/IJqp4lE88gEenAGvaPp /vfA== X-Gm-Message-State: AOAM532rgiGLi7zp5bY2UFwwq0nNhFok+hII+7IHtY0QpHseur2UyFk4 XAtskx1ox/94AD/gWrl3eEA= X-Google-Smtp-Source: ABdhPJxIMvOC7fye8f41lFke77y/TKZP9IxyoXzwFdWfXal/mYzrQWyv08pJzu3oHOUC6yn+s2Tcig== X-Received: by 2002:ac2:4285:: with SMTP id m5mr11469535lfh.244.1625575769659; Tue, 06 Jul 2021 05:49:29 -0700 (PDT) Received: from carbon.v ([94.143.149.146]) by smtp.googlemail.com with ESMTPSA id r18sm139519ljc.120.2021.07.06.05.49.28 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 06 Jul 2021 05:49:29 -0700 (PDT) From: Dmitry Kadashev To: Jens Axboe , Alexander Viro , Christian Brauner , Linus Torvalds Cc: Pavel Begunkov , linux-fsdevel@vger.kernel.org, io-uring@vger.kernel.org, Dmitry Kadashev Subject: [PATCH v7 08/10] fs: update do_*() helpers to return ints Date: Tue, 6 Jul 2021 19:48:59 +0700 Message-Id: <20210706124901.1360377-9-dkadashev@gmail.com> X-Mailer: git-send-email 2.30.2 In-Reply-To: <20210706124901.1360377-1-dkadashev@gmail.com> References: <20210706124901.1360377-1-dkadashev@gmail.com> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: linux-fsdevel@vger.kernel.org Update the following to return int rather than long, for uniformity with the rest of the do_* helpers in namei.c: * do_rmdir() * do_unlinkat() * do_mkdirat() * do_mknodat() * do_symlinkat() Cc: Linus Torvalds Cc: Al Viro Cc: Christian Brauner Link: https://lore.kernel.org/io-uring/20210514143202.dmzfcgz5hnauy7ze@wittgenstein/ Signed-off-by: Dmitry Kadashev Acked-by: Christian Brauner --- fs/internal.h | 6 +++--- fs/namei.c | 10 +++++----- 2 files changed, 8 insertions(+), 8 deletions(-) diff --git a/fs/internal.h b/fs/internal.h index 848e165ef0f1..207a455e32d3 100644 --- a/fs/internal.h +++ b/fs/internal.h @@ -72,12 +72,12 @@ extern int filename_lookup(int dfd, struct filename *name, unsigned flags, struct path *path, struct path *root); extern int vfs_path_lookup(struct dentry *, struct vfsmount *, const char *, unsigned int, struct path *); -long do_rmdir(int dfd, struct filename *name); -long do_unlinkat(int dfd, struct filename *name); +int do_rmdir(int dfd, struct filename *name); +int do_unlinkat(int dfd, struct filename *name); int may_linkat(struct user_namespace *mnt_userns, struct path *link); int do_renameat2(int olddfd, struct filename *oldname, int newdfd, struct filename *newname, unsigned int flags); -long do_mkdirat(int dfd, struct filename *name, umode_t mode); +int do_mkdirat(int dfd, struct filename *name, umode_t mode); /* * namespace.c diff --git a/fs/namei.c b/fs/namei.c index 0a2731f7ef71..1656073ca493 100644 --- a/fs/namei.c +++ b/fs/namei.c @@ -3746,7 +3746,7 @@ static int may_mknod(umode_t mode) } } -static long do_mknodat(int dfd, struct filename *name, umode_t mode, +static int do_mknodat(int dfd, struct filename *name, umode_t mode, unsigned int dev) { struct user_namespace *mnt_userns; @@ -3850,7 +3850,7 @@ int vfs_mkdir(struct user_namespace *mnt_userns, struct inode *dir, } EXPORT_SYMBOL(vfs_mkdir); -long do_mkdirat(int dfd, struct filename *name, umode_t mode) +int do_mkdirat(int dfd, struct filename *name, umode_t mode) { struct dentry *dentry; struct path path; @@ -3945,7 +3945,7 @@ int vfs_rmdir(struct user_namespace *mnt_userns, struct inode *dir, } EXPORT_SYMBOL(vfs_rmdir); -long do_rmdir(int dfd, struct filename *name) +int do_rmdir(int dfd, struct filename *name) { struct user_namespace *mnt_userns; int error = 0; @@ -4083,7 +4083,7 @@ EXPORT_SYMBOL(vfs_unlink); * writeout happening, and we don't want to prevent access to the directory * while waiting on the I/O. */ -long do_unlinkat(int dfd, struct filename *name) +int do_unlinkat(int dfd, struct filename *name) { int error; struct dentry *dentry; @@ -4210,7 +4210,7 @@ int vfs_symlink(struct user_namespace *mnt_userns, struct inode *dir, } EXPORT_SYMBOL(vfs_symlink); -static long do_symlinkat(struct filename *from, int newdfd, +static int do_symlinkat(struct filename *from, int newdfd, struct filename *to) { int error; From patchwork Tue Jul 6 12:49:00 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Dmitry Kadashev X-Patchwork-Id: 12360541 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-15.7 required=3.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,FREEMAIL_FORGED_FROMDOMAIN,FREEMAIL_FROM, HEADER_FROM_DIFFERENT_DOMAINS,INCLUDES_CR_TRAILER,INCLUDES_PATCH, MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS,URIBL_BLOCKED,USER_AGENT_GIT autolearn=unavailable autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 4ADD5C07E9E for ; Tue, 6 Jul 2021 12:50:03 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 361F1611AF for ; Tue, 6 Jul 2021 12:50:03 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S235245AbhGFMwi (ORCPT ); Tue, 6 Jul 2021 08:52:38 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:35936 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S241426AbhGFMwL (ORCPT ); Tue, 6 Jul 2021 08:52:11 -0400 Received: from mail-lf1-x135.google.com (mail-lf1-x135.google.com [IPv6:2a00:1450:4864:20::135]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 72353C061764; Tue, 6 Jul 2021 05:49:32 -0700 (PDT) Received: by mail-lf1-x135.google.com with SMTP id v14so12546074lfb.4; Tue, 06 Jul 2021 05:49:32 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=tsMm5RVkk7HjOAg6FFDUzu6dgkNFgLiUvnWCmOkKYN0=; b=O1gTq7K8zViQw+flUMMEU+hJo6BwsJPeO3Kx+BsZFlvzZdBgTeyx7GWYnsvB9RSWdc 6r+DFs9ygFK9/6OJVbt6gJd1LjV9CENN86Dq1GIN+OmIxkCGXJpOwX/lkeTQqw9MNZDg vlKpXfwV35LnYB7HOTry6SoShk6DnITR1ArMi3CbA+UMHsWfCmPBweWTOBkNOQT36SDx uVAqkzI1phlGn5rkIYCW8k7AjdnHz3FmisPTerDHSWYcITOevwbClyoZM57J318wBMCc FQ0k3y/iKGetPp4D0CE8JOOFDggxN0AgQFsCaSzM/WTiieOsa4IzcYgG6j7Mfy4gNs6s zQpA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=tsMm5RVkk7HjOAg6FFDUzu6dgkNFgLiUvnWCmOkKYN0=; b=IYa7vo5dgt9ns/PubO3Xlzdu4JszEbk+FNyy+MLRQ3zQHJhz95l67tdMjJx/UHxKep ZPFo5aICRvLHZ1wSrbVbiqWEbb05KlxerKRlxu22jWxqvpFDt+QR1dLJFgCBOKcJsSf6 1avuW/+nBkTOeGCDFbzWWiHHyo0ca2upZz35uL+IkwkIyvXffnaioYKT/tcBh8VSZ543 FEcoF6oHUvPYrVkxwmR/cafQLmfJs6BxBGeOcEOCCGRcyAGn3NE+VxFAN+cDLmQ6hcaV waBImqYiCw6gTZG724lcCa4QPHUHBPyqsCE6BYCJMxYoes4qgwIawkKQ+A2uCmZbF8r7 rvnQ== X-Gm-Message-State: AOAM530owAAErrn+zt24MDkV7hzo48D81K+LsIqSq0GRel8MLZibLt6e SqAYixjWsJg1CepQQwN5yk4= X-Google-Smtp-Source: ABdhPJyQVSR+QDqKEPXLsdeP0fnDXD1VG0KSEazsIvjcidrEqzyQDCfq2hl6Wnqarq9d+nSyDRxexw== X-Received: by 2002:a19:9156:: with SMTP id y22mr14678803lfj.207.1625575770840; Tue, 06 Jul 2021 05:49:30 -0700 (PDT) Received: from carbon.v ([94.143.149.146]) by smtp.googlemail.com with ESMTPSA id r18sm139519ljc.120.2021.07.06.05.49.29 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 06 Jul 2021 05:49:30 -0700 (PDT) From: Dmitry Kadashev To: Jens Axboe , Alexander Viro , Christian Brauner , Linus Torvalds Cc: Pavel Begunkov , linux-fsdevel@vger.kernel.org, io-uring@vger.kernel.org, Dmitry Kadashev Subject: [PATCH v7 09/10] io_uring: add support for IORING_OP_SYMLINKAT Date: Tue, 6 Jul 2021 19:49:00 +0700 Message-Id: <20210706124901.1360377-10-dkadashev@gmail.com> X-Mailer: git-send-email 2.30.2 In-Reply-To: <20210706124901.1360377-1-dkadashev@gmail.com> References: <20210706124901.1360377-1-dkadashev@gmail.com> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: linux-fsdevel@vger.kernel.org IORING_OP_SYMLINKAT behaves like symlinkat(2) and takes the same flags and arguments. Cc: Linus Torvalds Suggested-by: Christian Brauner Link: https://lore.kernel.org/io-uring/20210514145259.wtl4xcsp52woi6ab@wittgenstein/ Signed-off-by: Dmitry Kadashev Acked-by: Christian Brauner --- fs/internal.h | 1 + fs/io_uring.c | 66 +++++++++++++++++++++++++++++++++++ fs/namei.c | 3 +- include/uapi/linux/io_uring.h | 1 + 4 files changed, 69 insertions(+), 2 deletions(-) diff --git a/fs/internal.h b/fs/internal.h index 207a455e32d3..3b3954214385 100644 --- a/fs/internal.h +++ b/fs/internal.h @@ -78,6 +78,7 @@ int may_linkat(struct user_namespace *mnt_userns, struct path *link); int do_renameat2(int olddfd, struct filename *oldname, int newdfd, struct filename *newname, unsigned int flags); int do_mkdirat(int dfd, struct filename *name, umode_t mode); +int do_symlinkat(struct filename *from, int newdfd, struct filename *to); /* * namespace.c diff --git a/fs/io_uring.c b/fs/io_uring.c index 42d54f9bbbb2..a0f681ec25bb 100644 --- a/fs/io_uring.c +++ b/fs/io_uring.c @@ -681,6 +681,13 @@ struct io_mkdir { struct filename *filename; }; +struct io_symlink { + struct file *file; + int new_dfd; + struct filename *oldpath; + struct filename *newpath; +}; + struct io_completion { struct file *file; struct list_head list; @@ -839,6 +846,7 @@ struct io_kiocb { struct io_rename rename; struct io_unlink unlink; struct io_mkdir mkdir; + struct io_symlink symlink; /* use only after cleaning per-op data, see io_clean_op() */ struct io_completion compl; }; @@ -1051,6 +1059,7 @@ static const struct io_op_def io_op_defs[] = { [IORING_OP_RENAMEAT] = {}, [IORING_OP_UNLINKAT] = {}, [IORING_OP_MKDIRAT] = {}, + [IORING_OP_SYMLINKAT] = {}, }; static bool io_disarm_next(struct io_kiocb *req); @@ -3596,6 +3605,54 @@ static int io_mkdirat(struct io_kiocb *req, int issue_flags) return 0; } +static int io_symlinkat_prep(struct io_kiocb *req, + const struct io_uring_sqe *sqe) +{ + struct io_symlink *sl = &req->symlink; + const char __user *oldpath, *newpath; + + if (unlikely(req->ctx->flags & IORING_SETUP_IOPOLL)) + return -EINVAL; + if (sqe->ioprio || sqe->len || sqe->rw_flags || sqe->buf_index) + return -EINVAL; + if (unlikely(req->flags & REQ_F_FIXED_FILE)) + return -EBADF; + + sl->new_dfd = READ_ONCE(sqe->fd); + oldpath = u64_to_user_ptr(READ_ONCE(sqe->addr)); + newpath = u64_to_user_ptr(READ_ONCE(sqe->addr2)); + + sl->oldpath = getname(oldpath); + if (IS_ERR(sl->oldpath)) + return PTR_ERR(sl->oldpath); + + sl->newpath = getname(newpath); + if (IS_ERR(sl->newpath)) { + putname(sl->oldpath); + return PTR_ERR(sl->newpath); + } + + req->flags |= REQ_F_NEED_CLEANUP; + return 0; +} + +static int io_symlinkat(struct io_kiocb *req, int issue_flags) +{ + struct io_symlink *sl = &req->symlink; + int ret; + + if (issue_flags & IO_URING_F_NONBLOCK) + return -EAGAIN; + + ret = do_symlinkat(sl->oldpath, sl->new_dfd, sl->newpath); + + req->flags &= ~REQ_F_NEED_CLEANUP; + if (ret < 0) + req_set_fail(req); + io_req_complete(req, ret); + return 0; +} + static int io_shutdown_prep(struct io_kiocb *req, const struct io_uring_sqe *sqe) { @@ -6006,6 +6063,8 @@ static int io_req_prep(struct io_kiocb *req, const struct io_uring_sqe *sqe) return io_unlinkat_prep(req, sqe); case IORING_OP_MKDIRAT: return io_mkdirat_prep(req, sqe); + case IORING_OP_SYMLINKAT: + return io_symlinkat_prep(req, sqe); } printk_once(KERN_WARNING "io_uring: unhandled opcode %d\n", @@ -6170,6 +6229,10 @@ static void io_clean_op(struct io_kiocb *req) case IORING_OP_MKDIRAT: putname(req->mkdir.filename); break; + case IORING_OP_SYMLINKAT: + putname(req->symlink.oldpath); + putname(req->symlink.newpath); + break; } } if ((req->flags & REQ_F_POLLED) && req->apoll) { @@ -6301,6 +6364,9 @@ static int io_issue_sqe(struct io_kiocb *req, unsigned int issue_flags) case IORING_OP_MKDIRAT: ret = io_mkdirat(req, issue_flags); break; + case IORING_OP_SYMLINKAT: + ret = io_symlinkat(req, issue_flags); + break; default: ret = -EINVAL; break; diff --git a/fs/namei.c b/fs/namei.c index 1656073ca493..3cf8f5e3b155 100644 --- a/fs/namei.c +++ b/fs/namei.c @@ -4210,8 +4210,7 @@ int vfs_symlink(struct user_namespace *mnt_userns, struct inode *dir, } EXPORT_SYMBOL(vfs_symlink); -static int do_symlinkat(struct filename *from, int newdfd, - struct filename *to) +int do_symlinkat(struct filename *from, int newdfd, struct filename *to) { int error; struct dentry *dentry; diff --git a/include/uapi/linux/io_uring.h b/include/uapi/linux/io_uring.h index a926407c230e..61fd347ab176 100644 --- a/include/uapi/linux/io_uring.h +++ b/include/uapi/linux/io_uring.h @@ -134,6 +134,7 @@ enum { IORING_OP_RENAMEAT, IORING_OP_UNLINKAT, IORING_OP_MKDIRAT, + IORING_OP_SYMLINKAT, /* this goes last, obviously */ IORING_OP_LAST, From patchwork Tue Jul 6 12:49:01 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Dmitry Kadashev X-Patchwork-Id: 12360543 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-15.7 required=3.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,FREEMAIL_FORGED_FROMDOMAIN,FREEMAIL_FROM, HEADER_FROM_DIFFERENT_DOMAINS,INCLUDES_CR_TRAILER,INCLUDES_PATCH, MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS,URIBL_BLOCKED,USER_AGENT_GIT autolearn=unavailable autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id AA4D5C11F68 for ; Tue, 6 Jul 2021 12:50:05 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 982BD611AF for ; Tue, 6 Jul 2021 12:50:05 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S235594AbhGFMwm (ORCPT ); Tue, 6 Jul 2021 08:52:42 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:35870 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S241836AbhGFMwN (ORCPT ); Tue, 6 Jul 2021 08:52:13 -0400 Received: from mail-lj1-x231.google.com (mail-lj1-x231.google.com [IPv6:2a00:1450:4864:20::231]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id AA02EC061760; Tue, 6 Jul 2021 05:49:33 -0700 (PDT) Received: by mail-lj1-x231.google.com with SMTP id b40so9158808ljf.12; Tue, 06 Jul 2021 05:49:33 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=gJq2iRTwHGrfYDqYL7yzYFbXyEbtL7aWF6AFG6qJkmM=; b=u/KpHxWOeVMb9ymxDIWlZff+1dnE91bMiUZB+giivR0IZAWcowsj1FrfVUlT2QEoNS xHQY3CUYTYUcIEscxdlrZ0MKl4muZ1y0tZCt1nITf2oeb87uVvOmlkmskXHbE/B1Xpx9 HDHtFx5sNQbwVkJ3m3cXnCJbRcJ1y1JROgi9Tbu2Hl89XGtCQWrTwIYoBzRVEt77SXg2 1fEa+GOae914uJ0qqF8wCrdw1PQ2vQY1q0KP3RKKA34sjDFB1i45OJbgtqhbDF8AIGtY dNp3kbImNT7GoGbPNPYVwcmO/b3tj2ldeB8qDfPmU/Zhk7bb1Yx6ZZEnV+crkMPysuTX FDoQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=gJq2iRTwHGrfYDqYL7yzYFbXyEbtL7aWF6AFG6qJkmM=; b=HJdQta7oUvd5VGiNRax+N+rwpcDVBhknf0jkiPGn90qZZ/Tg4WRGmn8js09c3e6sH2 Y5Q41ysLHwL9InyK50KuW6nTC8YhiejuhfH4XoYTbyGUr24G/67i7v/x7SGag0j3Orq6 qnSwdsDOahmsQkaxcTJ8al5NHk+72vfXZyiUDuSZoVQBVdnVwO4ZiJEv5Je/7mTfKiIU JcMDH6SxGvFYBKGR+pg2ZjqpAtBRuhP+dv7mN8mO+I2H6GE0km85R91DqsqpPem0G6wI NJER3/9q/O5MhHkPIE/2DaW7yhM/yPubtW0xwPZaZavRVdhoII1sQ+TN7ekJL5HojO8m V12g== X-Gm-Message-State: AOAM532v4oI/O23wHi3WGfoFtM8lkpX7OEuYF0ZsoVqi4MSssDLEZu/1 0VS3uyV7VXH+9ToNwf0jwys= X-Google-Smtp-Source: ABdhPJyfaqlQ2gRvLlXcTzEcltO5/3XD2JQtdTCWyONqCZFhG22PpOjkgkcz0aCdfoFikKKto/iSsg== X-Received: by 2002:a2e:9e8e:: with SMTP id f14mr15154861ljk.468.1625575772041; Tue, 06 Jul 2021 05:49:32 -0700 (PDT) Received: from carbon.v ([94.143.149.146]) by smtp.googlemail.com with ESMTPSA id r18sm139519ljc.120.2021.07.06.05.49.30 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 06 Jul 2021 05:49:31 -0700 (PDT) From: Dmitry Kadashev To: Jens Axboe , Alexander Viro , Christian Brauner , Linus Torvalds Cc: Pavel Begunkov , linux-fsdevel@vger.kernel.org, io-uring@vger.kernel.org, Dmitry Kadashev Subject: [PATCH v7 10/10] io_uring: add support for IORING_OP_LINKAT Date: Tue, 6 Jul 2021 19:49:01 +0700 Message-Id: <20210706124901.1360377-11-dkadashev@gmail.com> X-Mailer: git-send-email 2.30.2 In-Reply-To: <20210706124901.1360377-1-dkadashev@gmail.com> References: <20210706124901.1360377-1-dkadashev@gmail.com> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: linux-fsdevel@vger.kernel.org IORING_OP_LINKAT behaves like linkat(2) and takes the same flags and arguments. In some internal places 'hardlink' is used instead of 'link' to avoid confusion with the SQE links. Name 'link' conflicts with the existing 'link' member of io_kiocb. Cc: Linus Torvalds Suggested-by: Christian Brauner Link: https://lore.kernel.org/io-uring/20210514145259.wtl4xcsp52woi6ab@wittgenstein/ Signed-off-by: Dmitry Kadashev Acked-by: Christian Brauner --- fs/internal.h | 2 + fs/io_uring.c | 71 +++++++++++++++++++++++++++++++++++ fs/namei.c | 2 +- include/uapi/linux/io_uring.h | 2 + 4 files changed, 76 insertions(+), 1 deletion(-) diff --git a/fs/internal.h b/fs/internal.h index 3b3954214385..15a7d210cc67 100644 --- a/fs/internal.h +++ b/fs/internal.h @@ -79,6 +79,8 @@ int do_renameat2(int olddfd, struct filename *oldname, int newdfd, struct filename *newname, unsigned int flags); int do_mkdirat(int dfd, struct filename *name, umode_t mode); int do_symlinkat(struct filename *from, int newdfd, struct filename *to); +int do_linkat(int olddfd, struct filename *old, int newdfd, + struct filename *new, int flags); /* * namespace.c diff --git a/fs/io_uring.c b/fs/io_uring.c index a0f681ec25bb..d18ca8afd1fb 100644 --- a/fs/io_uring.c +++ b/fs/io_uring.c @@ -688,6 +688,15 @@ struct io_symlink { struct filename *newpath; }; +struct io_hardlink { + struct file *file; + int old_dfd; + int new_dfd; + struct filename *oldpath; + struct filename *newpath; + int flags; +}; + struct io_completion { struct file *file; struct list_head list; @@ -847,6 +856,7 @@ struct io_kiocb { struct io_unlink unlink; struct io_mkdir mkdir; struct io_symlink symlink; + struct io_hardlink hardlink; /* use only after cleaning per-op data, see io_clean_op() */ struct io_completion compl; }; @@ -1060,6 +1070,7 @@ static const struct io_op_def io_op_defs[] = { [IORING_OP_UNLINKAT] = {}, [IORING_OP_MKDIRAT] = {}, [IORING_OP_SYMLINKAT] = {}, + [IORING_OP_LINKAT] = {}, }; static bool io_disarm_next(struct io_kiocb *req); @@ -3653,6 +3664,57 @@ static int io_symlinkat(struct io_kiocb *req, int issue_flags) return 0; } +static int io_linkat_prep(struct io_kiocb *req, + const struct io_uring_sqe *sqe) +{ + struct io_hardlink *lnk = &req->hardlink; + const char __user *oldf, *newf; + + if (unlikely(req->ctx->flags & IORING_SETUP_IOPOLL)) + return -EINVAL; + if (sqe->ioprio || sqe->rw_flags || sqe->buf_index) + return -EINVAL; + if (unlikely(req->flags & REQ_F_FIXED_FILE)) + return -EBADF; + + lnk->old_dfd = READ_ONCE(sqe->fd); + lnk->new_dfd = READ_ONCE(sqe->len); + oldf = u64_to_user_ptr(READ_ONCE(sqe->addr)); + newf = u64_to_user_ptr(READ_ONCE(sqe->addr2)); + lnk->flags = READ_ONCE(sqe->hardlink_flags); + + lnk->oldpath = getname(oldf); + if (IS_ERR(lnk->oldpath)) + return PTR_ERR(lnk->oldpath); + + lnk->newpath = getname(newf); + if (IS_ERR(lnk->newpath)) { + putname(lnk->oldpath); + return PTR_ERR(lnk->newpath); + } + + req->flags |= REQ_F_NEED_CLEANUP; + return 0; +} + +static int io_linkat(struct io_kiocb *req, int issue_flags) +{ + struct io_hardlink *lnk = &req->hardlink; + int ret; + + if (issue_flags & IO_URING_F_NONBLOCK) + return -EAGAIN; + + ret = do_linkat(lnk->old_dfd, lnk->oldpath, lnk->new_dfd, + lnk->newpath, lnk->flags); + + req->flags &= ~REQ_F_NEED_CLEANUP; + if (ret < 0) + req_set_fail(req); + io_req_complete(req, ret); + return 0; +} + static int io_shutdown_prep(struct io_kiocb *req, const struct io_uring_sqe *sqe) { @@ -6065,6 +6127,8 @@ static int io_req_prep(struct io_kiocb *req, const struct io_uring_sqe *sqe) return io_mkdirat_prep(req, sqe); case IORING_OP_SYMLINKAT: return io_symlinkat_prep(req, sqe); + case IORING_OP_LINKAT: + return io_linkat_prep(req, sqe); } printk_once(KERN_WARNING "io_uring: unhandled opcode %d\n", @@ -6233,6 +6297,10 @@ static void io_clean_op(struct io_kiocb *req) putname(req->symlink.oldpath); putname(req->symlink.newpath); break; + case IORING_OP_LINKAT: + putname(req->hardlink.oldpath); + putname(req->hardlink.newpath); + break; } } if ((req->flags & REQ_F_POLLED) && req->apoll) { @@ -6367,6 +6435,9 @@ static int io_issue_sqe(struct io_kiocb *req, unsigned int issue_flags) case IORING_OP_SYMLINKAT: ret = io_symlinkat(req, issue_flags); break; + case IORING_OP_LINKAT: + ret = io_linkat(req, issue_flags); + break; default: ret = -EINVAL; break; diff --git a/fs/namei.c b/fs/namei.c index 3cf8f5e3b155..99d315462c42 100644 --- a/fs/namei.c +++ b/fs/namei.c @@ -4356,7 +4356,7 @@ EXPORT_SYMBOL(vfs_link); * with linux 2.0, and to avoid hard-linking to directories * and other special files. --ADM */ -static int do_linkat(int olddfd, struct filename *old, int newdfd, +int do_linkat(int olddfd, struct filename *old, int newdfd, struct filename *new, int flags) { struct user_namespace *mnt_userns; diff --git a/include/uapi/linux/io_uring.h b/include/uapi/linux/io_uring.h index 61fd347ab176..10eb38d2864f 100644 --- a/include/uapi/linux/io_uring.h +++ b/include/uapi/linux/io_uring.h @@ -44,6 +44,7 @@ struct io_uring_sqe { __u32 splice_flags; __u32 rename_flags; __u32 unlink_flags; + __u32 hardlink_flags; }; __u64 user_data; /* data to be passed back at completion time */ /* pack this to avoid bogus arm OABI complaints */ @@ -135,6 +136,7 @@ enum { IORING_OP_UNLINKAT, IORING_OP_MKDIRAT, IORING_OP_SYMLINKAT, + IORING_OP_LINKAT, /* this goes last, obviously */ IORING_OP_LAST,