From patchwork Thu Jul 8 06:34:37 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Dmitry Kadashev X-Patchwork-Id: 12364661 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=-16.0 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 4F04DC07E9C for ; Thu, 8 Jul 2021 06:35:17 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 3333B61CC4 for ; Thu, 8 Jul 2021 06:35:17 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S229815AbhGHGh4 (ORCPT ); Thu, 8 Jul 2021 02:37:56 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:56148 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229701AbhGHGhv (ORCPT ); Thu, 8 Jul 2021 02:37:51 -0400 Received: from mail-ej1-x62f.google.com (mail-ej1-x62f.google.com [IPv6:2a00:1450:4864:20::62f]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 6DDE4C061574; Wed, 7 Jul 2021 23:35:10 -0700 (PDT) Received: by mail-ej1-x62f.google.com with SMTP id v20so7597690eji.10; Wed, 07 Jul 2021 23:35:10 -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=BoFPoTEmWa3dojswo8JWLDQ3Qut9jFAuQjLXxSuXqGEDBQQCbwqNrveaIFbcoZbgkS vWALlj2lFShp46X25o2hGtr4Ck5bJGQ1ujhEvVxnH9NgV6gwTPHhJRk1g2dba8g8AST+ 7mylcCOSQfHNakE1TdsJATX17N3RQ7zObD+526l9rsQA+5yDHjXTPQQsR/MNp/SrgY0x S8aNUyOUzQmd/EpMzRC5oWc3eWnvZYOFwVWcZyMKCQeE5UJRdHyclIZScjmrVNnp0yq8 CXsIHxRrnil4qHLpYJVC1ZyC5fLhF/pSTwoK6XFw50pbiVUW7E01SOVPozFKQn8Z0SkV ujxA== 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=r5u2pDaRCLJHZz0ucl3Xvo05JZoUaK5Lg7ubrzsu2M8qQ/oVqokstM/ibShgV6gXVE aVRitvcL9h/7jJgNFbp+1JxQMQnrVoUkUovXEuk7W9NGcf25qK6EKETOgg+SBYj1q3d7 qRYAEZZCbledPnaKg23FyMT7pmSSraord41EJuJdQQY1rnVx7BOo3hnMB4RGedEDMChH 2QSwlbhOD63lqtpel97dg0i4FLN2NizGyEiUJHQbVBc4xxo+6hTOYPrV+YTmA/0P7JZv HbczEZPX6fvVaIQKc+mvQxa6UNn5gDcrBKPgbG9Wdot2gEp/gkrH1IAvMt47Ax0dZHXf 3SvQ== X-Gm-Message-State: AOAM530ymzTRUd6BP7RLpwMX2ZoD4WFDMzCsXR7Y/uRLcLk9qXhx1dxO XtRqu54wsog2OnUvGujMWVI= X-Google-Smtp-Source: ABdhPJyq7S8kAUWPiONQiLyFdtpAWYQ3HaNDBVUZsKb85uJvOuPqgra8QoNKnzIhX17NCxo6Bft4cQ== X-Received: by 2002:a17:906:1796:: with SMTP id t22mr28474566eje.304.1625726108972; Wed, 07 Jul 2021 23:35:08 -0700 (PDT) Received: from carbon.v ([108.61.166.58]) by smtp.googlemail.com with ESMTPSA id u21sm410260eja.59.2021.07.07.23.35.07 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 07 Jul 2021 23:35:08 -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 v9 01/11] namei: ignore ERR/NULL names in putname() Date: Thu, 8 Jul 2021 13:34:37 +0700 Message-Id: <20210708063447.3556403-2-dkadashev@gmail.com> X-Mailer: git-send-email 2.30.2 In-Reply-To: <20210708063447.3556403-1-dkadashev@gmail.com> References: <20210708063447.3556403-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 Thu Jul 8 06:34:38 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Dmitry Kadashev X-Patchwork-Id: 12364665 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=-16.0 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 3F27AC07E9C for ; Thu, 8 Jul 2021 06:35:24 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 2611961CD1 for ; Thu, 8 Jul 2021 06:35:24 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S229843AbhGHGh7 (ORCPT ); Thu, 8 Jul 2021 02:37:59 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:56156 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229756AbhGHGhy (ORCPT ); Thu, 8 Jul 2021 02:37:54 -0400 Received: from mail-ed1-x52d.google.com (mail-ed1-x52d.google.com [IPv6:2a00:1450:4864:20::52d]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 31748C061574; Wed, 7 Jul 2021 23:35:12 -0700 (PDT) Received: by mail-ed1-x52d.google.com with SMTP id m1so6878730edq.8; Wed, 07 Jul 2021 23:35:12 -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=xqr2s+A/IvkPLe4a4IGu4i1RJV8tZqdSAJM7YR4tQUc=; b=Z7PULl/kYg2CKG9qU+YNq0TR0becYkza367q1SIWKV8jmnDum9LHd/RqwwK//Oqeu5 NbpbrFl02TRm7HWrz47gijxTj54YKpLBQG9IxL+q3eqpFxcjLTOYLH6gooUf4fYRt1Ia gI4z2mfdLy6AYjRgbSNvU3+/4cHurKj/0VBH1ATCiSID2rn0YXUnH0O8GxKnmvXq9Dtq kYKFwaRZj52QKj/E8d/tJT8bza3rJeMSeFVCt8+zzd4/+YUGnKnmqN5WCrRBpZmoQjCv 9EaL1hp1WDiTqPpo4Sb1dtqvie//OGetH+iOsMkdWjB3rB6qt3BbWnhp0EKHLfiRFOLR l78Q== 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=xqr2s+A/IvkPLe4a4IGu4i1RJV8tZqdSAJM7YR4tQUc=; b=BQwUwagVoK69pYrb2py3mes/pmYcsICy5lRjQ5p/PF7oA0v4o0ikDuGBNHUEcoAm9s vJtp6dRGDNwc+DT2cqSTycSW41kDhXRYJST7MXmjhKaTIxlMGwBu/UvZVH6N1dRz97RI pmfL5QmABah7Nz42QVMwNdd0kbv80B7f4KW99/U6PTPiVgTbHuwNub5zrDTYjbFaJSdJ tGSZutFU3B2070si/lLw8fz/eOrsEO6ahCli3oq2V025sg2PyR2vqEIyNyoyA6cfzsNA kdoMPMcJdBN8ci7n96IfxaLTLO/VdlGEcZVQykT7QJFU+eDClhS7ea544VhECF3UuUlf uD+w== X-Gm-Message-State: AOAM5307DaXQ170/mfgsdPPzey0qRxgJBEyyz0WvCqOTMcMLOBD1DcoF +VnBQ6opXfC2N4GZgmLJpOU= X-Google-Smtp-Source: ABdhPJzANfThhYznnK3tlNi+j263lDlyi+hX30mDP6Vr3HRdQXO0x+AgleWHpoB5Rb/tGN0HP5B59A== X-Received: by 2002:a50:9b06:: with SMTP id o6mr36664976edi.284.1625726110855; Wed, 07 Jul 2021 23:35:10 -0700 (PDT) Received: from carbon.v ([108.61.166.58]) by smtp.googlemail.com with ESMTPSA id u21sm410260eja.59.2021.07.07.23.35.09 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 07 Jul 2021 23:35:10 -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 v9 02/11] namei: change filename_parentat() calling conventions Date: Thu, 8 Jul 2021 13:34:38 +0700 Message-Id: <20210708063447.3556403-3-dkadashev@gmail.com> X-Mailer: git-send-email 2.30.2 In-Reply-To: <20210708063447.3556403-1-dkadashev@gmail.com> References: <20210708063447.3556403-1-dkadashev@gmail.com> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: linux-fsdevel@vger.kernel.org Since commit 5c31b6cedb675 ("namei: saner calling conventions for filename_parentat()") filename_parentat() had the following behavior WRT the passed in struct filename *: * On error the name is consumed (putname() is called on it); * On success the name is returned back as the return value; Now there is a need for filename_create() and filename_lookup() variants that do not consume the passed filename, and following the same "consume the name only on error" semantics is proven to be hard to reason about and result in confusing code. Hence this preparation change splits filename_parentat() into two: one that always consumes the name and another that never consumes the name. This will allow to implement two filename_create() variants in the same way, and is a consistent and hopefully easier to reason about approach. Link: https://lore.kernel.org/io-uring/CAOKbgA7MiqZAq3t-HDCpSGUFfco4hMA9ArAE-74fTpU+EkvKPw@mail.gmail.com/ Cc: Linus Torvalds Cc: Al Viro Cc: Christian Brauner Signed-off-by: Dmitry Kadashev --- fs/namei.c | 108 ++++++++++++++++++++++++++--------------------------- 1 file changed, 53 insertions(+), 55 deletions(-) diff --git a/fs/namei.c b/fs/namei.c index 70caf4ef1134..2995b3695724 100644 --- a/fs/namei.c +++ b/fs/namei.c @@ -2485,7 +2485,7 @@ static int path_parentat(struct nameidata *nd, unsigned flags, return err; } -static struct filename *filename_parentat(int dfd, struct filename *name, +static int __filename_parentat(int dfd, struct filename *name, unsigned int flags, struct path *parent, struct qstr *last, int *type) { @@ -2493,7 +2493,7 @@ static struct filename *filename_parentat(int dfd, struct filename *name, struct nameidata nd; if (IS_ERR(name)) - return name; + return PTR_ERR(name); set_nameidata(&nd, dfd, name); retval = path_parentat(&nd, flags | LOOKUP_RCU, parent); if (unlikely(retval == -ECHILD)) @@ -2504,29 +2504,34 @@ static struct filename *filename_parentat(int dfd, struct filename *name, *last = nd.last; *type = nd.last_type; audit_inode(name, parent->dentry, AUDIT_INODE_PARENT); - } else { - putname(name); - name = ERR_PTR(retval); } restore_nameidata(); - return name; + return retval; +} + +static int filename_parentat(int dfd, struct filename *name, + unsigned int flags, struct path *parent, + struct qstr *last, int *type) +{ + int retval = __filename_parentat(dfd, name, flags, parent, last, type); + + putname(name); + return retval; } /* does lookup, returns the object with parent locked */ struct dentry *kern_path_locked(const char *name, struct path *path) { - struct filename *filename; struct dentry *d; struct qstr last; - int type; + int type, error; - filename = filename_parentat(AT_FDCWD, getname_kernel(name), 0, path, + error = filename_parentat(AT_FDCWD, getname_kernel(name), 0, path, &last, &type); - if (IS_ERR(filename)) - return ERR_CAST(filename); + if (error) + return ERR_PTR(error); if (unlikely(type != LAST_NORM)) { path_put(path); - putname(filename); return ERR_PTR(-EINVAL); } inode_lock_nested(path->dentry->d_inode, I_MUTEX_PARENT); @@ -2535,7 +2540,6 @@ struct dentry *kern_path_locked(const char *name, struct path *path) inode_unlock(path->dentry->d_inode); path_put(path); } - putname(filename); return d; } @@ -3575,9 +3579,9 @@ static struct dentry *filename_create(int dfd, struct filename *name, */ lookup_flags &= LOOKUP_REVAL; - name = filename_parentat(dfd, name, lookup_flags, path, &last, &type); - if (IS_ERR(name)) - return ERR_CAST(name); + error = filename_parentat(dfd, name, lookup_flags, path, &last, &type); + if (error) + return ERR_PTR(error); /* * Yucky last component or no last component at all? @@ -3615,7 +3619,6 @@ static struct dentry *filename_create(int dfd, struct filename *name, error = err2; goto fail; } - putname(name); return dentry; fail: dput(dentry); @@ -3626,7 +3629,6 @@ static struct dentry *filename_create(int dfd, struct filename *name, mnt_drop_write(path->mnt); out: path_put(path); - putname(name); return dentry; } @@ -3917,59 +3919,59 @@ EXPORT_SYMBOL(vfs_rmdir); long do_rmdir(int dfd, struct filename *name) { struct user_namespace *mnt_userns; - int error = 0; + int error; struct dentry *dentry; struct path path; struct qstr last; int type; unsigned int lookup_flags = 0; retry: - name = filename_parentat(dfd, name, lookup_flags, - &path, &last, &type); - if (IS_ERR(name)) - return PTR_ERR(name); + error = __filename_parentat(dfd, name, lookup_flags, &path, &last, &type); + if (error) + goto exit1; switch (type) { case LAST_DOTDOT: error = -ENOTEMPTY; - goto exit1; + goto exit2; case LAST_DOT: error = -EINVAL; - goto exit1; + goto exit2; case LAST_ROOT: error = -EBUSY; - goto exit1; + goto exit2; } error = mnt_want_write(path.mnt); if (error) - goto exit1; + goto exit2; inode_lock_nested(path.dentry->d_inode, I_MUTEX_PARENT); dentry = __lookup_hash(&last, path.dentry, lookup_flags); error = PTR_ERR(dentry); if (IS_ERR(dentry)) - goto exit2; + goto exit3; if (!dentry->d_inode) { error = -ENOENT; - goto exit3; + goto exit4; } error = security_path_rmdir(&path, dentry); if (error) - goto exit3; + goto exit4; mnt_userns = mnt_user_ns(path.mnt); error = vfs_rmdir(mnt_userns, path.dentry->d_inode, dentry); -exit3: +exit4: dput(dentry); -exit2: +exit3: inode_unlock(path.dentry->d_inode); mnt_drop_write(path.mnt); -exit1: +exit2: path_put(&path); if (retry_estale(error, lookup_flags)) { lookup_flags |= LOOKUP_REVAL; goto retry; } +exit1: putname(name); return error; } @@ -4063,17 +4065,17 @@ long do_unlinkat(int dfd, struct filename *name) struct inode *delegated_inode = NULL; unsigned int lookup_flags = 0; retry: - name = filename_parentat(dfd, name, lookup_flags, &path, &last, &type); - if (IS_ERR(name)) - return PTR_ERR(name); + error = __filename_parentat(dfd, name, lookup_flags, &path, &last, &type); + if (error) + goto exit1; error = -EISDIR; if (type != LAST_NORM) - goto exit1; + goto exit2; error = mnt_want_write(path.mnt); if (error) - goto exit1; + goto exit2; retry_deleg: inode_lock_nested(path.dentry->d_inode, I_MUTEX_PARENT); dentry = __lookup_hash(&last, path.dentry, lookup_flags); @@ -4090,11 +4092,11 @@ long do_unlinkat(int dfd, struct filename *name) ihold(inode); error = security_path_unlink(&path, dentry); if (error) - goto exit2; + goto exit3; mnt_userns = mnt_user_ns(path.mnt); error = vfs_unlink(mnt_userns, path.dentry->d_inode, dentry, &delegated_inode); -exit2: +exit3: dput(dentry); } inode_unlock(path.dentry->d_inode); @@ -4107,13 +4109,14 @@ long do_unlinkat(int dfd, struct filename *name) goto retry_deleg; } mnt_drop_write(path.mnt); -exit1: +exit2: path_put(&path); if (retry_estale(error, lookup_flags)) { lookup_flags |= LOOKUP_REVAL; inode = NULL; goto retry; } +exit1: putname(name); return error; @@ -4124,7 +4127,7 @@ long do_unlinkat(int dfd, struct filename *name) error = -EISDIR; else error = -ENOTDIR; - goto exit2; + goto exit3; } SYSCALL_DEFINE3(unlinkat, int, dfd, const char __user *, pathname, int, flag) @@ -4595,29 +4598,25 @@ int do_renameat2(int olddfd, struct filename *from, int newdfd, int error = -EINVAL; if (flags & ~(RENAME_NOREPLACE | RENAME_EXCHANGE | RENAME_WHITEOUT)) - goto put_both; + goto put_names; if ((flags & (RENAME_NOREPLACE | RENAME_WHITEOUT)) && (flags & RENAME_EXCHANGE)) - goto put_both; + goto put_names; if (flags & RENAME_EXCHANGE) target_flags = 0; retry: - from = filename_parentat(olddfd, from, lookup_flags, &old_path, + error = __filename_parentat(olddfd, from, lookup_flags, &old_path, &old_last, &old_type); - if (IS_ERR(from)) { - error = PTR_ERR(from); - goto put_new; - } + if (error) + goto put_names; - to = filename_parentat(newdfd, to, lookup_flags, &new_path, &new_last, + error = __filename_parentat(newdfd, to, lookup_flags, &new_path, &new_last, &new_type); - if (IS_ERR(to)) { - error = PTR_ERR(to); + if (error) goto exit1; - } error = -EXDEV; if (old_path.mnt != new_path.mnt) @@ -4720,9 +4719,8 @@ int do_renameat2(int olddfd, struct filename *from, int newdfd, lookup_flags |= LOOKUP_REVAL; goto retry; } -put_both: +put_names: putname(from); -put_new: putname(to); return error; } From patchwork Thu Jul 8 06:34:39 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Dmitry Kadashev X-Patchwork-Id: 12364669 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=-16.0 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 77031C11F66 for ; Thu, 8 Jul 2021 06:35:24 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 5586561CE5 for ; Thu, 8 Jul 2021 06:35:24 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S229872AbhGHGiA (ORCPT ); Thu, 8 Jul 2021 02:38:00 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:56166 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229763AbhGHGhz (ORCPT ); Thu, 8 Jul 2021 02:37:55 -0400 Received: from mail-ej1-x62f.google.com (mail-ej1-x62f.google.com [IPv6:2a00:1450:4864:20::62f]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id D74E4C06175F; Wed, 7 Jul 2021 23:35:13 -0700 (PDT) Received: by mail-ej1-x62f.google.com with SMTP id bu12so7675078ejb.0; Wed, 07 Jul 2021 23:35:13 -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=AVmhH06SyxapkboM9opDUcgHzjT4U95zTavxicpRMho=; b=AYncr8Sy8xfEpe8yQAiHsMwSyzZHYdGzamYEMucX441Y7NS7zBkXu1ssAOU8WnB6eY Q+fh7uwc7vEsr48sNB9JIQ+7Xn0S5kcCUOx20mOErokElKcCYHd2WiqWZkdZ7j+0St37 AcgVngCnE2hDJJThgaQOYkduCROyRJNlkgF53HHXaidOOWxl8P+U+vomx3dhBhN6R4rU N1iPNo8dzisFIk42ZaGwUIGVjRrRBxWUiAsTOgyi7VtltgBGKK2OH7D95N29o36NquGi 23tI/uGDAgrKgqtIevgd/dQZcWawnxYegcoDBPqDH/XvpTDgDZjdsZ3mfaq1Fex0zMY0 7wOQ== 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=AVmhH06SyxapkboM9opDUcgHzjT4U95zTavxicpRMho=; b=cGdxE/CIx5Hi+Dq6FmTK9fec19j1LP71J5mWiVGOY3CVsTOXoC64Ggq6dbM61WK1WD crYlxIBXm9/P0U1Jbtm9Q34GyCeBxfpknwwKlzmbz+0vQttnLUSxfsSBOrttlgdTE4za R0Z54NIi7SucVA1l7dUyWa+skGAjRXgmWuv7lElak9uPFZtW6XzT9NSFTuYWXkX6Ya3I knuC1IwxR21XAC8APW/9HIz7SN6Q3975w6deuDik3aeGAkT6AoUOidm8HiJTkvVlcrpj 3HqK8kQOigBEElH13rlpWcP3+xWSVsVOWS8E63mN2vW646yvcJizglo9JOqrprIfdN1T 4ySA== X-Gm-Message-State: AOAM531vahHDunWwPsVPqfxrPIRQEWH/7yF7O+QtYJpsrHeXV4cEeDi1 0zpZ2ATSrrko2VniO6zNS5Y= X-Google-Smtp-Source: ABdhPJz9OsdMxDoYL6Xhw5hG2L9Z+k50d9PNIS+N5Bo36GfNNwOIVyEBjwzG0ZehGal6pMbxNoK9nA== X-Received: by 2002:a17:907:c20:: with SMTP id ga32mr29226012ejc.7.1625726112512; Wed, 07 Jul 2021 23:35:12 -0700 (PDT) Received: from carbon.v ([108.61.166.58]) by smtp.googlemail.com with ESMTPSA id u21sm410260eja.59.2021.07.07.23.35.11 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 07 Jul 2021 23:35:12 -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 v9 03/11] namei: make do_mkdirat() take struct filename Date: Thu, 8 Jul 2021 13:34:39 +0700 Message-Id: <20210708063447.3556403-4-dkadashev@gmail.com> X-Mailer: git-send-email 2.30.2 In-Reply-To: <20210708063447.3556403-1-dkadashev@gmail.com> References: <20210708063447.3556403-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 | 26 +++++++++++++++++++------- 2 files changed, 20 insertions(+), 7 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 2995b3695724..54d5f19ee1ce 100644 --- a/fs/namei.c +++ b/fs/namei.c @@ -3563,7 +3563,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); @@ -3579,7 +3579,7 @@ static struct dentry *filename_create(int dfd, struct filename *name, */ lookup_flags &= LOOKUP_REVAL; - error = filename_parentat(dfd, name, lookup_flags, path, &last, &type); + error = __filename_parentat(dfd, name, lookup_flags, path, &last, &type); if (error) return ERR_PTR(error); @@ -3632,6 +3632,15 @@ 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); + + putname(name); + return res; +} + struct dentry *kern_path_create(int dfd, const char *pathname, struct path *path, unsigned int lookup_flags) { @@ -3822,7 +3831,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; @@ -3830,9 +3839,10 @@ 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); + error = PTR_ERR(dentry); if (IS_ERR(dentry)) - return PTR_ERR(dentry); + goto out_putname; if (!IS_POSIXACL(path.dentry->d_inode)) mode &= ~current_umask(); @@ -3848,17 +3858,19 @@ static long do_mkdirat(int dfd, const char __user *pathname, umode_t mode) lookup_flags |= LOOKUP_REVAL; goto retry; } +out_putname: + 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 Thu Jul 8 06:34:40 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Dmitry Kadashev X-Patchwork-Id: 12364667 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=-16.0 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 5D159C07E9E for ; Thu, 8 Jul 2021 06:35:24 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 4614C61CC4 for ; Thu, 8 Jul 2021 06:35:24 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S229899AbhGHGiA (ORCPT ); Thu, 8 Jul 2021 02:38:00 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:56170 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229838AbhGHGh5 (ORCPT ); Thu, 8 Jul 2021 02:37:57 -0400 Received: from mail-ej1-x62e.google.com (mail-ej1-x62e.google.com [IPv6:2a00:1450:4864:20::62e]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 8137FC061574; Wed, 7 Jul 2021 23:35:15 -0700 (PDT) Received: by mail-ej1-x62e.google.com with SMTP id ga42so7598353ejc.6; Wed, 07 Jul 2021 23:35:15 -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=ldQ7yGS4aEvHdrCjdrJwmRjCzLuQxIXl0hNYPBTwz2Q=; b=HHFQhUq/vzRr043P2CTflyIRyRVpFHZUm2CtPvk9LQxsu9Gu8UGE1ohOc4n4HQP3hb BrA8p+u9bg+m1hHqGS4wkSWxkdSVEum+LRiJMfOxL7y2WLvY7GsaYWLihV0NeAPWRBDI GRw1QOxWwvGzNL9N6tWFLgsBzdcahQVT5DX75TSh+9WWcqUGYF6IqIS/aDCWd1uGTuOz QbtBCh7x0wU4GhASWGIpsrTXW9Xp+stdJFitbHy/V1ZyA+gr/MBQpCHTXNQrDICY69Yn 5yiwRjVeSqZAEWp03rgC+VBNoHbqcNhuR7qiW62bVGT7o+nJaDThhbcu4NaFamlfU6MN B+6A== 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=ldQ7yGS4aEvHdrCjdrJwmRjCzLuQxIXl0hNYPBTwz2Q=; b=hN8r9pgyQ6pL3BoDJTJ8PugaA9Wmh7hC8A9EsqsqwVKRiQ0Z6GO8B2nBT909NO/8tS gbmDls6yuM7Am/U9gw/uqVICZC62Br+Q4+HX9EfbWJIsjyye+t/aWQGKA0KqxPxUGg4X egjTr2E9vzWHGyDPavmGVcZhhLn1Z8ZyUmTxbORO9OkkYKZmV9+oX/ERSUsmiCI0TZjM +iHv4+NrKNEv6h7iPDWh90OBmR66DiRK8ajVMfljgE8Y8Jr3sj75KXqlwgFJtZyf1vnR 62lih3rW7xHVNhdv7UnkYaY4CypHVD2a5INxyNshX9SROeIisfwdAWYIk5UWIwrMbUei O5aw== X-Gm-Message-State: AOAM532sJhe8/JbYhsSih9N5XG6ikHZAjIdtcz15Vq2VqhNIzIYh6Leu 0BF2p+G25a5rhB2zo8DrBvc= X-Google-Smtp-Source: ABdhPJx51asT/OQxLxRQQg6VNUir1JVmH6bjOkv04OZm1KZfb8d6njWZnZL1SkD8rAQvzXZJCRzOcw== X-Received: by 2002:a17:907:9701:: with SMTP id jg1mr17644208ejc.56.1625726114200; Wed, 07 Jul 2021 23:35:14 -0700 (PDT) Received: from carbon.v ([108.61.166.58]) by smtp.googlemail.com with ESMTPSA id u21sm410260eja.59.2021.07.07.23.35.12 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 07 Jul 2021 23:35:13 -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 v9 04/11] namei: make do_mknodat() take struct filename Date: Thu, 8 Jul 2021 13:34:40 +0700 Message-Id: <20210708063447.3556403-5-dkadashev@gmail.com> X-Mailer: git-send-email 2.30.2 In-Reply-To: <20210708063447.3556403-1-dkadashev@gmail.com> References: <20210708063447.3556403-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 | 19 +++++++++++-------- 1 file changed, 11 insertions(+), 8 deletions(-) diff --git a/fs/namei.c b/fs/namei.c index 54d5f19ee1ce..0bc8ff637934 100644 --- a/fs/namei.c +++ b/fs/namei.c @@ -3729,7 +3729,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; @@ -3740,17 +3740,18 @@ 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); + error = PTR_ERR(dentry); if (IS_ERR(dentry)) - return PTR_ERR(dentry); + goto out1; if (!IS_POSIXACL(path.dentry->d_inode)) 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) { @@ -3769,24 +3770,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 Thu Jul 8 06:34:41 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Dmitry Kadashev X-Patchwork-Id: 12364677 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=-16.0 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 B581FC11F69 for ; Thu, 8 Jul 2021 06:35:27 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 973A561CDE for ; Thu, 8 Jul 2021 06:35:27 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S230416AbhGHGiF (ORCPT ); Thu, 8 Jul 2021 02:38:05 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:56178 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229846AbhGHGh7 (ORCPT ); Thu, 8 Jul 2021 02:37:59 -0400 Received: from mail-ed1-x534.google.com (mail-ed1-x534.google.com [IPv6:2a00:1450:4864:20::534]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 3803DC061574; Wed, 7 Jul 2021 23:35:17 -0700 (PDT) Received: by mail-ed1-x534.google.com with SMTP id cy23so1902101edb.4; Wed, 07 Jul 2021 23:35:17 -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=7wVETDFdeZlwqopZKc4dLFFstHCEoM9cJ3/d5EEJtEs=; b=BCYibFVeg5tC7gxx2iFLd7LbdbcgIjoYIoKioYBHIqV1Bu1cd9KqyRQLhN2mvf/eze eCRot3vbK8PLwWSh36ZBXUE6hdg0+lD8Vl1NNPPhy5FZaSFxpK/ufiTEXs+e6lmXFmA9 LNcg7bvhoRR+mC15fQbD4753lSNkgy7Y9LH18HdriStk3FdcHtJEeBr0SyCmJQuFRpTf 0n/vj1yMwfNVTHTUseDqqEtj0EKZ2VcxH4E5y0hSpUbMeM2AGU/O/OnBO1IgqCJ06BCg lc1b/SdTrVSHiAzTrL1QdUTRPt3ROl7QNxOsIS+kubjl5uitCbypQCEEeFBHypguXwLZ iwHA== 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=7wVETDFdeZlwqopZKc4dLFFstHCEoM9cJ3/d5EEJtEs=; b=hP0LlK1x1Me0hEv5+bEsYFFfn8EqEU9P40gpUAjVrA/E71LOmgbKG1IkjmIAW8bJY5 NiHL5eZPm+/th7pOEcQz4iHlTOeR082y1k4VC++7fkzJ3vU4U3je8Ae868nt4lz2Iu7N nvm6Ik5ruvIIiO4jQrirQM1/zDpcSn4vsTUw2rpwLOfUQA7Xq4176z2cMuyQkcGMASLg A6jaNBtdW8gcULZ9/IIMBwM16l5IjFhfvCEpS10PY2RO0uhn723SxyJ1ejZU60blexAr hnJdDfCLYI/JzgIWMhpArWL5KJEtf6x5NbYNmmY72vCuQLKId0O6qPK7mgZI4h7yE+Bt XH4w== X-Gm-Message-State: AOAM5336iGGqiA9Ba15vG6s+c5yYzW+a66RWlmX8wB3zHhkS9iSWuwur HirF/k4OWk/aAgUSeRl978I= X-Google-Smtp-Source: ABdhPJy9gc9t5QBGIeTrIjPBiu2sEiu2mawXbKqcytDFF6v4yEOMc16l3BpMYbjfhCc5MAPOCmPbjA== X-Received: by 2002:aa7:d283:: with SMTP id w3mr19816028edq.153.1625726115917; Wed, 07 Jul 2021 23:35:15 -0700 (PDT) Received: from carbon.v ([108.61.166.58]) by smtp.googlemail.com with ESMTPSA id u21sm410260eja.59.2021.07.07.23.35.14 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 07 Jul 2021 23:35:15 -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 v9 05/11] namei: make do_symlinkat() take struct filename Date: Thu, 8 Jul 2021 13:34:41 +0700 Message-Id: <20210708063447.3556403-6-dkadashev@gmail.com> X-Mailer: git-send-email 2.30.2 In-Reply-To: <20210708063447.3556403-1-dkadashev@gmail.com> References: <20210708063447.3556403-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 | 23 ++++++++++++----------- 1 file changed, 12 insertions(+), 11 deletions(-) diff --git a/fs/namei.c b/fs/namei.c index 0bc8ff637934..add984e4bfd0 100644 --- a/fs/namei.c +++ b/fs/namei.c @@ -4197,23 +4197,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_putnames; + } 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_putnames; error = security_path_symlink(&path, dentry, from->name); if (!error) { @@ -4228,7 +4228,8 @@ static long do_symlinkat(const char __user *oldname, int newdfd, lookup_flags |= LOOKUP_REVAL; goto retry; } -out_putname: +out_putnames: + putname(to); putname(from); return error; } @@ -4236,12 +4237,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 Thu Jul 8 06:34:42 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Dmitry Kadashev X-Patchwork-Id: 12364671 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=-16.0 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 CA252C11F6B for ; Thu, 8 Jul 2021 06:35:27 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id B44A661CE4 for ; Thu, 8 Jul 2021 06:35:27 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S230428AbhGHGiG (ORCPT ); Thu, 8 Jul 2021 02:38:06 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:56188 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S230396AbhGHGiB (ORCPT ); Thu, 8 Jul 2021 02:38:01 -0400 Received: from mail-ed1-x532.google.com (mail-ed1-x532.google.com [IPv6:2a00:1450:4864:20::532]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id DCF73C06175F; Wed, 7 Jul 2021 23:35:18 -0700 (PDT) Received: by mail-ed1-x532.google.com with SMTP id t3so6846586edt.12; Wed, 07 Jul 2021 23:35:18 -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=+aL8eUyCcZIm7m9c9cpQrgQm638OpqOKLxLINa0Iv48=; b=n7IrrwOZ90WSiTV/5g19dM6dn5cB+ZxsruZocVQdDOMmm1W4SWrVLQo1BTgxxZakff Rp/FImeAafFltRdJCKRa3t74NuhPKOeUFI+feaFHfTlyx+5OzpBFM9i2eYm0ErfiR3Aw +s1UEnpNypLP0yLkWfCjfrKMcISLSkirfGlMYL1zxMH8kS/L0OtehqI6TYcJ7jh0qR/D iIv63/0yGGEgyyXAH/xSMGR+aUmW5GkDoFT3D+Ae9LxNwebucGytq/a3XeYF1VP+4gIf Yj18dx7xIpe31JVdFqaUNDpwhVdXh08NGL1k6dC2S+HBCW0+SVvETJNvOzByuRdT2sx5 xiFg== 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=+aL8eUyCcZIm7m9c9cpQrgQm638OpqOKLxLINa0Iv48=; b=Qv4Cumr91Wi9bl4pRtyL9H2wEaSxNefqe0RV1LG9kCvYoPqyxPZJpb0qtYXJgai9xM zO71VQAlsjSOj2YP0qg5sZxgIEFuVuH3mzBZO/tXKD/urb7GqaO2FuD1T77ImU/oo5Xh fOLFy3UTN0+fvWEa0teqY++p3BpyiDdPe15JTWm61gv0AeScFVzLGAPoGraps79NS8mq CtFerx/QDMHpv4gw6FbQ8dK374AHzqDLEpNV5JyX5JyMI9xSSBmwIGQzBTzZa1P7+Wdz MH6t3SLUvxbzULwdzV8DZIQvGoXApyL3pKTyPY1p29rw/h5KyyuMZSrZRL17DgbwJByO C/XQ== X-Gm-Message-State: AOAM530qTZdcjcZokuX5jWWd4tWu3BALtqeUG7o+BzytDWT1ZQorBqiE vcEPNfXo+OvlOYqUFLiGOsQ= X-Google-Smtp-Source: ABdhPJx9W3O5wCAhbS9cqd/Y/s5TZhFetTt0+7Y16o8/2uxaAFETH+Dbu3tP89b7b+3a5o+pZPw51Q== X-Received: by 2002:aa7:dc0c:: with SMTP id b12mr36266761edu.105.1625726117585; Wed, 07 Jul 2021 23:35:17 -0700 (PDT) Received: from carbon.v ([108.61.166.58]) by smtp.googlemail.com with ESMTPSA id u21sm410260eja.59.2021.07.07.23.35.16 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 07 Jul 2021 23:35:17 -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 v9 06/11] namei: add getname_uflags() Date: Thu, 8 Jul 2021 13:34:42 +0700 Message-Id: <20210708063447.3556403-7-dkadashev@gmail.com> X-Mailer: git-send-email 2.30.2 In-Reply-To: <20210708063447.3556403-1-dkadashev@gmail.com> References: <20210708063447.3556403-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 add984e4bfd0..ab7979f9daaa 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 Thu Jul 8 06:34:43 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Dmitry Kadashev X-Patchwork-Id: 12364673 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=-16.0 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 C50C3C07E9C for ; Thu, 8 Jul 2021 06:35:27 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id A7B0861C94 for ; Thu, 8 Jul 2021 06:35:27 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S230433AbhGHGiH (ORCPT ); Thu, 8 Jul 2021 02:38:07 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:56194 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S230412AbhGHGiD (ORCPT ); Thu, 8 Jul 2021 02:38:03 -0400 Received: from mail-ed1-x52f.google.com (mail-ed1-x52f.google.com [IPv6:2a00:1450:4864:20::52f]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 992FEC061574; Wed, 7 Jul 2021 23:35:20 -0700 (PDT) Received: by mail-ed1-x52f.google.com with SMTP id t10so802217eds.2; Wed, 07 Jul 2021 23:35:20 -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=/ENI3vx+SPLOvrCGGRMyzNMRkwVI7tMhimck/JVEfvw=; b=iYgHh6Lz0AC4EZyvFw847POFlfgL5N6mMcv7Xd3apRPpGRbD7/hwHbghO0J1fpZU0q 093ey3gKkRiaWtLHyKS/vAm2UwsukpfMlCxhuNZ9IIktSQjcTizs6lnrUkKU1WlnW1Oc YaUvaOjebkqmoGWmhQKpv9q1zck4N7A+ZtdT61rlWXj0T33mVHeFg0Y2UaIIQZMpzGv+ x+xWe94NVstuGbeCSCoo9b5AoNTN2ZosIUFNIv6qyiCoOHU2MqjiNdP+CCAUt11rfrFl b3iN+O1cih2fGKk/m7KvH3+p4nIWLBZYvX+zl9d29lxkeJ8CkGSgk/LUHetYWBAM/u8x S9WQ== 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=/ENI3vx+SPLOvrCGGRMyzNMRkwVI7tMhimck/JVEfvw=; b=OOMBahenFk7A3lASDvuxTqRB7O58s87El7jlC8tTH3nr+YGgxS5GTNRW40XkynmjfC jsHANbN+kn6ZoswG00g06abp5T6pRA4xBNxNxZC3Pah2g1nIjcbEoMDn2uyAA8Ncaol0 bYb/9WgpR5/Ew/Fdw75HlBWTVoi5dXTltDS7kWXz0BWky7L+LSMhTs3elEY6UVRTqBul WKuqIzCATiza6E2+AcPsEe4c5zXMvJwqJMTsTRbKDP2TO0nRweR2n/PqpfgxsFF2qQ5r t8wawMXzJ+QbIY+8vGL4JQRgO9VxxGL3Qmn6mEj5lVwlCMXS7S6A8svzlz6UV8BH8X6C t7wA== X-Gm-Message-State: AOAM530sYmR5NPSfRscnFTU+E5XGiXvS3dR4vOe2Xa8Z3wq6LbeatVRq /O05SqIfS5zqjjMdVAnNoOE= X-Google-Smtp-Source: ABdhPJwZ2RMVs/WPlpBKzQ9XEogBjCGDKrzUryDzR8VRo92+Alh9C/Wr1ysO1xjR+6q9B76H2ytI6A== X-Received: by 2002:a50:fb96:: with SMTP id e22mr28679645edq.95.1625726119306; Wed, 07 Jul 2021 23:35:19 -0700 (PDT) Received: from carbon.v ([108.61.166.58]) by smtp.googlemail.com with ESMTPSA id u21sm410260eja.59.2021.07.07.23.35.17 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 07 Jul 2021 23:35:19 -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 v9 07/11] namei: make do_linkat() take struct filename Date: Thu, 8 Jul 2021 13:34:43 +0700 Message-Id: <20210708063447.3556403-8-dkadashev@gmail.com> X-Mailer: git-send-email 2.30.2 In-Reply-To: <20210708063447.3556403-1-dkadashev@gmail.com> References: <20210708063447.3556403-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 | 45 +++++++++++++++++++++++++++++---------------- 1 file changed, 29 insertions(+), 16 deletions(-) diff --git a/fs/namei.c b/fs/namei.c index ab7979f9daaa..c4e13bd8652f 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,6 +2472,14 @@ int filename_lookup(int dfd, struct filename *name, unsigned flags, audit_inode(name, path->dentry, flags & LOOKUP_MOUNTPOINT ? AUDIT_INODE_NOEVAL : 0); restore_nameidata(); + 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); + putname(name); return retval; } @@ -4351,8 +4359,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; @@ -4361,31 +4369,32 @@ 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_putnames; - 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; + goto out_putpath; error = -EXDEV; if (old_path.mnt != new_path.mnt) @@ -4413,8 +4422,11 @@ 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); + putname(new); return error; } @@ -4422,12 +4434,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 Thu Jul 8 06:34:44 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Dmitry Kadashev X-Patchwork-Id: 12364675 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=-16.0 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 5C4F8C11F67 for ; Thu, 8 Jul 2021 06:35:28 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 3D12F61CE3 for ; Thu, 8 Jul 2021 06:35:28 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S230412AbhGHGiI (ORCPT ); Thu, 8 Jul 2021 02:38:08 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:56204 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S230414AbhGHGiD (ORCPT ); Thu, 8 Jul 2021 02:38:03 -0400 Received: from mail-ed1-x535.google.com (mail-ed1-x535.google.com [IPv6:2a00:1450:4864:20::535]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 5233AC061574; Wed, 7 Jul 2021 23:35:22 -0700 (PDT) Received: by mail-ed1-x535.google.com with SMTP id s15so6835308edt.13; Wed, 07 Jul 2021 23:35: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=dJEfPWt8A2cpdRy8a2TP12zWmZnjHsnti/CgfmiTAVs=; b=SO0Te5a8vrpaBfywmtjzyQIA0pLAVyiPDCyUowoT4pFvyW200rWllfAJWK2aWR5Y7r pzhLGsm0Gu/ul24NOxtZ1WjO1LsPXFVMsvTOm9zram+HErnv60MzDQg8yFCsEBvYE1sy Mm+4Gf9NwnbWhmv9CGMYpNcv1MxMb+AiSt35VP7dHu8OGA5vnep8b71NFUTAyuzseQm4 i/8Jp9SYopOULk+B62CR+yPJ7MLDSV7j+xufJDVMUV5n6YvATqcZW5LhF1eJFxX1bUiE Cs27M3e4a0F833wj/ml93sc2gjGM5N1wMkUQIotC/+d3my6PdwkvSf1m0+PXGcQQYpDG UGTw== 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=dJEfPWt8A2cpdRy8a2TP12zWmZnjHsnti/CgfmiTAVs=; b=cH3V9Ph+ACMG652FEY1ucHEjgzFws/zZb3qnlzYTtoZTisZKI1NLnZDQA7dWq2z770 wqUYLyT0jPjMcysNjkYc8/6KZMlUiL+EJ+FO2IE/Dv8s8WdU+BDHFrN20pBLewo+L74+ 3dqWvH2vcI1XyQbIJXm1UYHgcwA3PmMfkzw1eVNw2E8BBZxHuNyGynPZYPxWa3tKcBM6 6BfR6p09ltz5DjBu2j1lsnBRtOXwzaZhxwxR35Z0MCB1YsZ3vRABWb3N/84foiePberg duwit2qAdOKfVOhOzMFItRKf2Ue6M4amAIfXCtzdlWlNBeIOVMsfzaVWT9YPapX2D3RF 3BFg== X-Gm-Message-State: AOAM530h26hp3KpWMxiPxskp07p+L95Wf7mUfuH2YK+k21/ogjJNs362 sIxp1YP3W70VQ4gyRR0BxmY= X-Google-Smtp-Source: ABdhPJw0JkxMjbzYjej4sc4nz+6XYoB4Q9B+xqFXXNqlXCVriFBheAHVuB982W9NnjKTqzFbRQrVzg== X-Received: by 2002:a05:6402:1688:: with SMTP id a8mr34097761edv.4.1625726121018; Wed, 07 Jul 2021 23:35:21 -0700 (PDT) Received: from carbon.v ([108.61.166.58]) by smtp.googlemail.com with ESMTPSA id u21sm410260eja.59.2021.07.07.23.35.19 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 07 Jul 2021 23:35: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 v9 08/11] namei: update do_*() helpers to return ints Date: Thu, 8 Jul 2021 13:34:44 +0700 Message-Id: <20210708063447.3556403-9-dkadashev@gmail.com> X-Mailer: git-send-email 2.30.2 In-Reply-To: <20210708063447.3556403-1-dkadashev@gmail.com> References: <20210708063447.3556403-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 c4e13bd8652f..d06aeaf5da00 100644 --- a/fs/namei.c +++ b/fs/namei.c @@ -3745,7 +3745,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; @@ -3947,7 +3947,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; @@ -4085,7 +4085,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; @@ -4213,7 +4213,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 Thu Jul 8 06:34:45 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Dmitry Kadashev X-Patchwork-Id: 12364679 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=-13.2 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 033A7C11F68 for ; Thu, 8 Jul 2021 06:35:30 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id DC73661CC4 for ; Thu, 8 Jul 2021 06:35:29 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S230440AbhGHGiJ (ORCPT ); Thu, 8 Jul 2021 02:38:09 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:56214 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S230405AbhGHGiF (ORCPT ); Thu, 8 Jul 2021 02:38:05 -0400 Received: from mail-ed1-x52e.google.com (mail-ed1-x52e.google.com [IPv6:2a00:1450:4864:20::52e]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 0A4E8C061574; Wed, 7 Jul 2021 23:35:24 -0700 (PDT) Received: by mail-ed1-x52e.google.com with SMTP id l2so6929423edt.1; Wed, 07 Jul 2021 23:35: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=9/0TTPk6QlPnPGwUZocYubZLcVhXXsqyK1OSZQGMszw=; b=pCfOkRHo0Qq9coTSwfnzi5NI71tLqxevuPrmaZCQ8zFdkYX+McOe0hdgEhS+dXY9ne Yq6L8G/Z1zsMIDdNHLTMr+VN8oNj+ByR5kSBBE/HEjQX7S99SSBdAa37xAKtd8YQNgtT bgl9cEDhuEp8V9add7PnsPXxvLp9TVMCB3VkYNKspS1Aw6WIseAkB2rUiJi1xhlVaq9s Q/RrG1j/ufFU4Tgz5lb0X5Cvj53vOsFHABgCTF4VeYsvWopnQL7+NbU3EdObEqjWW2ME 1KsqDpP4YNwFatX/0ydIKL5+jdWuw/MTOELS56CFPrLxYemXgMplQwEM1XRkaa5forl1 ZN0g== 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=MtcjpWWtc+mpP2+YLCEWjiSr8lNCJPDyyVyxfX3X8jvFGqMlarLY7idsdmzw0/K9jc SDVJhDo1RBr9W1L+z92KWyfMzmH1m3REoNBLnMv4BymrpQmllrE+7A4Bv1ZSEJ38BARx QUHoh6JXZddagfzgh7f9L6CldYZw1mLwaiNzQ4zvGsbESo1QJf1hTuf2sj0H447rXuNe Ri/eXMBxIO3Xf1mbJpA1Sx3iFL0tbrE4SfUYs05u/zBrvTn5JOD94lc9LYgcryC/Utb8 NKvDFqEQuKjBxtnKk0RZGGHeGPoPpt4vuZ+cjW/DiXZAqV9IXThknTTV80N7UoRn7Gsd THNg== X-Gm-Message-State: AOAM533jCL/gFRu2DKzw4Z7CRxZhXdZnL0sWvyc7Tnk9hJyqi3wYGs/r FGt10LNaOFr0VtKdmWUlZqM= X-Google-Smtp-Source: ABdhPJw2Q61DmuCUKztHlWGygJftYGW+XirLPSf3xaw9D/Ek4e7Joxhl9Exjt7gcWmcXf8y83Wv+VA== X-Received: by 2002:a05:6402:1cbc:: with SMTP id cz28mr36681560edb.246.1625726122712; Wed, 07 Jul 2021 23:35:22 -0700 (PDT) Received: from carbon.v ([108.61.166.58]) by smtp.googlemail.com with ESMTPSA id u21sm410260eja.59.2021.07.07.23.35.21 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 07 Jul 2021 23:35:22 -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 v9 09/11] io_uring: add support for IORING_OP_MKDIRAT Date: Thu, 8 Jul 2021 13:34:45 +0700 Message-Id: <20210708063447.3556403-10-dkadashev@gmail.com> X-Mailer: git-send-email 2.30.2 In-Reply-To: <20210708063447.3556403-1-dkadashev@gmail.com> References: <20210708063447.3556403-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 Thu Jul 8 06:34:46 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Dmitry Kadashev X-Patchwork-Id: 12364681 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=-16.0 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 9D310C11F6A for ; Thu, 8 Jul 2021 06:35:30 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 7EF1961CD1 for ; Thu, 8 Jul 2021 06:35:30 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S230458AbhGHGiK (ORCPT ); Thu, 8 Jul 2021 02:38:10 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:56224 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S230436AbhGHGiI (ORCPT ); Thu, 8 Jul 2021 02:38:08 -0400 Received: from mail-ej1-x634.google.com (mail-ej1-x634.google.com [IPv6:2a00:1450:4864:20::634]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 8CEC6C061574; Wed, 7 Jul 2021 23:35:26 -0700 (PDT) Received: by mail-ej1-x634.google.com with SMTP id ga42so7599068ejc.6; Wed, 07 Jul 2021 23:35: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=miRy2lgiuN42/MSS5JbhcjI1baujjkLTDwAmJ5AFvKA=; b=uIW9iOAPX/FRMpB2JcRg8HzZllB7btF52AZYWgIZj3tzMoi9CYmDSKkuBm5D0EGuPn w+6ckf9Fs+sqCboGp4kvt9b11q7tqSWayJbh+kLURdJmAXilXastmVEUdjzaO9Fgi1rO 1GR2hX8L88J+f6WLksvjzvMIV/GFKpbAC/2ZkhRLiLWYFQuR7OKSJfKuJMNvHKlLI0Rv lrfoSBWC3ueSrRQQxHfrNkpfVB4ZNq8eIymVz48U3j+4NURiK0k0zlUowqMLHdo8EJj3 MEJzCjplgauXXBZtuqwYwTAIHUVZJmwXv33P2aYqIBsr0qm9Psr+IDDgox8COWiyji46 YP4A== 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=miRy2lgiuN42/MSS5JbhcjI1baujjkLTDwAmJ5AFvKA=; b=lJXo9iAb3RcMKV2+Kz5toiRLpr8d9xvKqALWTAQW0Fr4mmzn3QkQUDpLxOSoMHdpyo jpgMU8sUgZzFTI/WO292mJVVTgO72A97+IPBM3wojtvH8/M9Aw3JKal9lWSD05zPbJkV TBGnMgJzzsHkPS+BA/QuB1yimN/v7Q4wbl3l4MkAwNB/O1hyxfAeZVJux/wJ7TVVRRzE LqJFuWySflr4cB8k5/+6eW5ItMTR/JPOLQpOmHQL9TmHpncFCk0fuoiFMTFKEIgheODd luweYIjVH8RI/nQuhtRBfom4sNTn4yp3cH/sTT+zBqRHP9vK+4EhcJO3G6Wy246CGZn0 wI4g== X-Gm-Message-State: AOAM533OXITl6+Sq7Q2u5u5HYQdOu38AnoquWZUJv31wMp4u6ArsltSJ z+cXwFId75qLCgvqD/xNm45oZ6C7vHnX6Une X-Google-Smtp-Source: ABdhPJwPbBTWOltRiuhPRfEHBsUNtARLeGK/2SVgYWRmMrJMaTACzwGe6UvGDxFPIKR5G1eQnXwh7w== X-Received: by 2002:a17:906:30d8:: with SMTP id b24mr7210018ejb.358.1625726124572; Wed, 07 Jul 2021 23:35:24 -0700 (PDT) Received: from carbon.v ([108.61.166.58]) by smtp.googlemail.com with ESMTPSA id u21sm410260eja.59.2021.07.07.23.35.22 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 07 Jul 2021 23:35: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 v9 10/11] io_uring: add support for IORING_OP_SYMLINKAT Date: Thu, 8 Jul 2021 13:34:46 +0700 Message-Id: <20210708063447.3556403-11-dkadashev@gmail.com> X-Mailer: git-send-email 2.30.2 In-Reply-To: <20210708063447.3556403-1-dkadashev@gmail.com> References: <20210708063447.3556403-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 d06aeaf5da00..f241348e64f4 100644 --- a/fs/namei.c +++ b/fs/namei.c @@ -4213,8 +4213,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 Thu Jul 8 06:34:47 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Dmitry Kadashev X-Patchwork-Id: 12364683 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=-16.0 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 41681C07E96 for ; Thu, 8 Jul 2021 06:35:31 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 2345061CDE for ; Thu, 8 Jul 2021 06:35:31 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S230463AbhGHGiL (ORCPT ); Thu, 8 Jul 2021 02:38:11 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:56228 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S230447AbhGHGiJ (ORCPT ); Thu, 8 Jul 2021 02:38:09 -0400 Received: from mail-ej1-x635.google.com (mail-ej1-x635.google.com [IPv6:2a00:1450:4864:20::635]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id B9E30C061574; Wed, 7 Jul 2021 23:35:27 -0700 (PDT) Received: by mail-ej1-x635.google.com with SMTP id gb6so7596364ejc.5; Wed, 07 Jul 2021 23:35: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=gYlonjHEqq+ciO9uXQTdjBC9hqLlNtpIxlPjlB/koR0=; b=G3ZckjUACjE4bjxSM0aVHwZ+/dOxUXcShlR94lZTxRC71/rfakEcUJhiCuIbxh/2PN MFbhEOpYNEzIaFx9YF2JnmPBut2MtMAKstwBjMuwEimOcimFaHWEb8MEAw/LdFaEAJ8K phXTihF2KY33vRjNapkURa6ubE7DNfsjpoZtanngG8EoUALhSZT5D3X57fzgYwl1Gbqk RdfzP0UmJzaPpP3F+GdTpgK7K0KUljZ/Rn8tJhkoKQgzsYmjTNufTKQa4GjmYzqKxzI2 x68jaxfSxA+pCmtnHg32xeziTa8KMBbpw/vXGc7/E+PnRsByfKSkkFb4rWh6v7g15Dtf Hb+g== 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=gYlonjHEqq+ciO9uXQTdjBC9hqLlNtpIxlPjlB/koR0=; b=B8EWIkjq+jUZS7WAShNIdAUg2sV7ENk6la+iNtSqYCCF9ojFnzXCvxuVf1u3rusHvN IKpj8upMoEeKBNupXHg8BRHI/cZvjhSHfbhWzxb4hiirdS0KvXT0k+wqCNsL5RjnJtOY OUIBt1vyXwAa6QemkC/F6LQ3R6wwAUY3RGZYiMzUPKYoS8J970X4VRrEa/ZSqRzitypl pYH3QjYjghAdPeyHt2sgTUWU+uRRPkWFEspfKxXudZNPskpyGQEJk/88hzZVWIkL8wTu ohXsW+C05WU8JJF8BPv6bBBxN6AKDLrlUm9Hx9Wzkn0HzkZRZ022Ln6HNSF5XkRd9/kO a0gQ== X-Gm-Message-State: AOAM530JmJ2KwKbG/+DLpgJ+shfOilNIHC5pQ6XSxeVjEJG9B2nnOU8o xmQ9vIvSZMrlYsfTNqmfUG0= X-Google-Smtp-Source: ABdhPJxXZWesmc/DxB+dQsqyC2iaU+1r1JqJUWaJGIKUeBkWu/4ybf2ielgsN6jNAoUK6Tz/UBumNw== X-Received: by 2002:a17:907:3e9c:: with SMTP id hs28mr15407063ejc.473.1625726126280; Wed, 07 Jul 2021 23:35:26 -0700 (PDT) Received: from carbon.v ([108.61.166.58]) by smtp.googlemail.com with ESMTPSA id u21sm410260eja.59.2021.07.07.23.35.24 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 07 Jul 2021 23:35: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 v9 11/11] io_uring: add support for IORING_OP_LINKAT Date: Thu, 8 Jul 2021 13:34:47 +0700 Message-Id: <20210708063447.3556403-12-dkadashev@gmail.com> X-Mailer: git-send-email 2.30.2 In-Reply-To: <20210708063447.3556403-1-dkadashev@gmail.com> References: <20210708063447.3556403-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 f241348e64f4..b5adfd4f7de6 100644 --- a/fs/namei.c +++ b/fs/namei.c @@ -4358,7 +4358,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,