From patchwork Thu Jun 3 05:18:27 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Dmitry Kadashev X-Patchwork-Id: 12296187 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.8 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,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 578EAC47082 for ; Thu, 3 Jun 2021 05:19:17 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 3BA66611CC for ; Thu, 3 Jun 2021 05:19:17 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S229697AbhFCFU7 (ORCPT ); Thu, 3 Jun 2021 01:20:59 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:36250 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229663AbhFCFU5 (ORCPT ); Thu, 3 Jun 2021 01:20:57 -0400 Received: from mail-ed1-x52c.google.com (mail-ed1-x52c.google.com [IPv6:2a00:1450:4864:20::52c]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 383D5C061756; Wed, 2 Jun 2021 22:18:57 -0700 (PDT) Received: by mail-ed1-x52c.google.com with SMTP id b11so5638548edy.4; Wed, 02 Jun 2021 22:18:57 -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=Xp1EXKPrsRbSPLaqx+abK9C+016qOT2YFPeg3T/SDS4=; b=BXEGHFJ9x1ouzOmTIqfPRg6LnBvLgFv9rGbTzey44PbnRkXrkMDRLK/wq3E2G70NX3 U7c6e+22lPqznLQgLMGVbmanjh2uLLusssU1NMMNSuM7QxAPFQaW/Ps2GU+BVQT12ok/ rPstre7Q/InPsibsgwBI9nEnKNo+zQ9EUVRuYWi4v18FlzNvQgKLJE5RB/Dsvh0jkj/L DNcWLBSIuDIRI3feSMyvhVe3HPtr4KXh79z+AUARkKfUlZpY6g5C0dZ6H7HZDbxJmWJZ 7H1PyPKolSgzliHcHPzMNkVx3idV13XbnrrRIhfZfjAYbX3durH5KBSOqTnBRsiwJCY4 dMmg== 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=Xp1EXKPrsRbSPLaqx+abK9C+016qOT2YFPeg3T/SDS4=; b=YEpNVXrSmOeA4m8iwocV73nINEfW68waISD2BkB2235BPEHEMiJyauDQ/pby/Z75AH 30ql97H1x3eUvY1jf3V30rBgpqlyn7SjJBd+6c6h+/3+glO+8mm9thGQAfsUkAawXrdT V0oObSlAUAoxJ2spKFzV/EK0xsp/RMyl4InMZ3lRvlQBKvqAynxEYRde3ufTj7lzhqAA EsS0BUKihr/YvwQqBurAWPuqhQTcU8gUCR+5Whp0oWJeK2URVleKEWzWhMmeVQaaxKCQ 6nMDPIT599MxKUXcFx097YwyKTujN1tBaedd9YrIpWFuTwAPBh0ksBWgmub9nkuGaCOb 6CiA== X-Gm-Message-State: AOAM532ckydNVlBx4wz9Ftq66eDVrW/1/jOlvoUOwLjCvceZGHd5PIsT bU/YIrFhaxSwBdBePwcM4tc= X-Google-Smtp-Source: ABdhPJwzvj5mWR0vRbFhlw/2QxZx9+vKupPz1Kxi4SBwEXh2Jq6gcI6tDwJNrKMdR1vnymhPIBUtmA== X-Received: by 2002:aa7:ce82:: with SMTP id y2mr30529857edv.264.1622697535849; Wed, 02 Jun 2021 22:18:55 -0700 (PDT) Received: from carbon.v ([108.61.166.58]) by smtp.googlemail.com with ESMTPSA id f7sm963668ejz.95.2021.06.02.22.18.54 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 02 Jun 2021 22:18:55 -0700 (PDT) From: Dmitry Kadashev To: Jens Axboe , Alexander Viro , Christian Brauner Cc: Pavel Begunkov , linux-fsdevel@vger.kernel.org, io-uring@vger.kernel.org, Dmitry Kadashev Subject: [PATCH v5 01/10] fs: make do_mkdirat() take struct filename Date: Thu, 3 Jun 2021 12:18:27 +0700 Message-Id: <20210603051836.2614535-2-dkadashev@gmail.com> X-Mailer: git-send-email 2.30.2 In-Reply-To: <20210603051836.2614535-1-dkadashev@gmail.com> References: <20210603051836.2614535-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 Signed-off-by: Dmitry Kadashev --- 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 79b0ff9b151e..49317c018341 100644 --- a/fs/namei.c +++ b/fs/namei.c @@ -3556,7 +3556,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); @@ -3612,7 +3612,6 @@ static struct dentry *filename_create(int dfd, struct filename *name, error = err2; goto fail; } - putname(name); return dentry; fail: dput(dentry); @@ -3627,6 +3626,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) { @@ -3817,7 +3826,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; @@ -3825,7 +3834,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); @@ -3843,17 +3852,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 Thu Jun 3 05:18:28 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Dmitry Kadashev X-Patchwork-Id: 12296179 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.8 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,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 62868C4709A for ; Thu, 3 Jun 2021 05:19:08 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 37279613EE for ; Thu, 3 Jun 2021 05:19:08 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S229682AbhFCFUv (ORCPT ); Thu, 3 Jun 2021 01:20:51 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:36254 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229617AbhFCFUt (ORCPT ); Thu, 3 Jun 2021 01:20:49 -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 C9C41C06175F; Wed, 2 Jun 2021 22:18:58 -0700 (PDT) Received: by mail-ej1-x62e.google.com with SMTP id l1so7302432ejb.6; Wed, 02 Jun 2021 22:18:58 -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=WqosZyHugw2yjt+Q+BMFX3mViYVJ9n0QC9Nc//NKvHo=; b=Ljl8d2GCRZEYzx1kK63gw6VSQJAbx2+dkwYrLHM3Z017+aNDNDCdp2uq5DLemx2atd nWQ3ShTsw+Zf9vhxTD32Dkx2/95wKlhk8vTxtHsEkjQs/U4Xh47RDbHa7Usgs12XUa2/ E6TaH2xJ4vjPGgCe31PeustIJxyCHwf7CSqZB3wJwio+HuMU3FiyBR/5j4hXQOBydLoc vZyqX2mbQH1Em9AqZUaVPtQn2YNjQKyDOA7+c4hhmADa/st5+5gm7JFByazhff72ch5m gg24pKEVbASYW2eywo4+4ZemLxIN0COZBDGhKdP7bZB41UH/T5buSD+AcqD91miCz0Gx utZA== 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=WqosZyHugw2yjt+Q+BMFX3mViYVJ9n0QC9Nc//NKvHo=; b=oLMeuAtiUP3d3Op5q05f4X8V0iC0hsZgvadnIulfBfLm/0xIHdzv87F/EX6EqYkgE0 txcUKytyZdG5bLPJ1Z60THgbqeSLD5LJkuIUqh1i7p+h5TlBT6NZYvp8iDh7mo89G4ls Q1zMJF/LxkxqOoXO6SUsOK2tVa83oWGFF63Y8ixXHRzANrMh1qy9IhdgkyfCbFBFEvaY f4aj+vDoXMoMcYxSFRoy41qN8pWxomvxi2qNA6YpCSd6eUz3h1xaoV0DMzr1rCSLF2fe /7QQzeSZh2eVkrlc367QtoCRihcxlh2hrxg1OU9NS7tNbkPIPmofNFatqr2M8pkKL1du 8NtQ== X-Gm-Message-State: AOAM530w82hLkT0s4ejlVVP297VuZIORjOnJGHPPONnt0k+HuejhRv9q o8dMn83OT3v5I2DQJUQUpvlI6gpoe/AuRw== X-Google-Smtp-Source: ABdhPJyfR2OyoKaUczcQ+iSunDexWVJ5ma5+lHK8LnR1Lo9U0MlmeZDfThHNSzahFREr2IQyOXhnqA== X-Received: by 2002:a17:906:d150:: with SMTP id br16mr16255211ejb.190.1622697537440; Wed, 02 Jun 2021 22:18:57 -0700 (PDT) Received: from carbon.v ([108.61.166.58]) by smtp.googlemail.com with ESMTPSA id f7sm963668ejz.95.2021.06.02.22.18.56 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 02 Jun 2021 22:18:57 -0700 (PDT) From: Dmitry Kadashev To: Jens Axboe , Alexander Viro , Christian Brauner Cc: Pavel Begunkov , linux-fsdevel@vger.kernel.org, io-uring@vger.kernel.org, Dmitry Kadashev Subject: [PATCH v5 02/10] io_uring: add support for IORING_OP_MKDIRAT Date: Thu, 3 Jun 2021 12:18:28 +0700 Message-Id: <20210603051836.2614535-3-dkadashev@gmail.com> X-Mailer: git-send-email 2.30.2 In-Reply-To: <20210603051836.2614535-1-dkadashev@gmail.com> References: <20210603051836.2614535-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. Signed-off-by: Dmitry Kadashev --- fs/io_uring.c | 55 +++++++++++++++++++++++++++++++++++ include/uapi/linux/io_uring.h | 1 + 2 files changed, 56 insertions(+) diff --git a/fs/io_uring.c b/fs/io_uring.c index a1ca6badff36..8ab4eb559520 100644 --- a/fs/io_uring.c +++ b/fs/io_uring.c @@ -665,6 +665,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; @@ -809,6 +816,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; }; @@ -1021,6 +1029,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); @@ -3530,6 +3539,44 @@ 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->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_links(req); + io_req_complete(req, ret); + return 0; +} + static int io_shutdown_prep(struct io_kiocb *req, const struct io_uring_sqe *sqe) { @@ -5936,6 +5983,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", @@ -6077,6 +6126,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; } req->flags &= ~REQ_F_NEED_CLEANUP; } @@ -6203,6 +6255,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 e1ae46683301..bf9d720d371f 100644 --- a/include/uapi/linux/io_uring.h +++ b/include/uapi/linux/io_uring.h @@ -137,6 +137,7 @@ enum { IORING_OP_SHUTDOWN, IORING_OP_RENAMEAT, IORING_OP_UNLINKAT, + IORING_OP_MKDIRAT, /* this goes last, obviously */ IORING_OP_LAST, From patchwork Thu Jun 3 05:18:29 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Dmitry Kadashev X-Patchwork-Id: 12296189 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.8 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,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 70B7FC47098 for ; Thu, 3 Jun 2021 05:19:17 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 4BAFC613F6 for ; Thu, 3 Jun 2021 05:19:17 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S229656AbhFCFVA (ORCPT ); Thu, 3 Jun 2021 01:21:00 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:36262 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229746AbhFCFU6 (ORCPT ); Thu, 3 Jun 2021 01:20:58 -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 D7E60C061760; Wed, 2 Jun 2021 22:19:00 -0700 (PDT) Received: by mail-ed1-x535.google.com with SMTP id cb9so5657085edb.1; Wed, 02 Jun 2021 22:19:00 -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=MkFs7GOSKkUTZGz9Kob9gnsknMUkw6urfLA/Fs3ZvX8=; b=P2ZyoCizdR8kC57pNYXGUKMsuoDdsCzd5buakmd6QPy8tO4khSoBQg21DjOeS2WQjZ RSGd2/YwINdZ22CYCC2myrQzFUwD1A7mJrCTuOnJM0lzqJ9EmbdU9a50dtrCOh085eIn olbWBtRnblhucmy6tzykdkYmYQrskAEPznsWuDE0E6dGUEQhj+0x2f3A0lbbxMYVWNVc 1/0sqb3x5kVQ5vdm0iIwaHPpCVeM/3NCDhkY7K8ggEH6kO9otzzaaV32HdDGN7GofsFy YzuEEzapePOzICHy4c3Xaf7/9ByAtr5hilfIKWLIX7RTO0Jn4FUqm/LVC5WczAtCcWNp /j4g== 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=MkFs7GOSKkUTZGz9Kob9gnsknMUkw6urfLA/Fs3ZvX8=; b=HRKRuQrJcWSW/+z6k9m4/zOa3WHQyCtNcJEM1dmQhKugr9X3QsGu4zfP2CDNelRLQC eKWgrVXHrnYSirUdCKsRijZEc2e74OQYIULg/uhQS7bPzKSpX5o8inaR9GCpiRIQTiS0 ODP8jCcYUJp04LROQ/g63GUtdynAqCa8NfrUa70h4yvTASVzh20Seu9gqzPEY64qcDRz fB7MJbyTSSwBPIBK+QqDlLpKcu70BWhdbevwDzlFbCUu+EkfCsMJ2hw7rDZVGjqZVfMY NUnRluazSdMd+TXZtnSFWO+SFtXHJmN8k5cjBFJ0EuYzzqEm6OaW+kfyZMNzMKoNqAro 8mtg== X-Gm-Message-State: AOAM530fLjpUITRJCXneA+dsnXebNuYChT+wZqf1A02oSbZH9X5yhqe3 JpDZCBFtKb6tO6XEYudIj84= X-Google-Smtp-Source: ABdhPJy8vr8w2G+BBIiMHGgZj6xSA0lYNmdaZlJxrXNgDzVdPw0oZgPX6ZcPG5zsw3PNsYIVrqjIGg== X-Received: by 2002:a05:6402:2688:: with SMTP id w8mr1085454edd.130.1622697539086; Wed, 02 Jun 2021 22:18:59 -0700 (PDT) Received: from carbon.v ([108.61.166.58]) by smtp.googlemail.com with ESMTPSA id f7sm963668ejz.95.2021.06.02.22.18.57 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 02 Jun 2021 22:18:58 -0700 (PDT) From: Dmitry Kadashev To: Jens Axboe , Alexander Viro , Christian Brauner Cc: Pavel Begunkov , linux-fsdevel@vger.kernel.org, io-uring@vger.kernel.org, Dmitry Kadashev Subject: [PATCH v5 03/10] fs: make do_mknodat() take struct filename Date: Thu, 3 Jun 2021 12:18:29 +0700 Message-Id: <20210603051836.2614535-4-dkadashev@gmail.com> X-Mailer: git-send-email 2.30.2 In-Reply-To: <20210603051836.2614535-1-dkadashev@gmail.com> References: <20210603051836.2614535-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: Al Viro Cc: Christian Brauner Link: https://lore.kernel.org/io-uring/20210330071700.kpjoyp5zlni7uejm@wittgenstein/ Signed-off-by: Dmitry Kadashev --- fs/namei.c | 17 ++++++++++------- 1 file changed, 10 insertions(+), 7 deletions(-) diff --git a/fs/namei.c b/fs/namei.c index 49317c018341..9fc981e28788 100644 --- a/fs/namei.c +++ b/fs/namei.c @@ -3724,7 +3724,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; @@ -3735,9 +3735,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); @@ -3745,7 +3745,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) { @@ -3764,24 +3764,27 @@ 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: + if (!IS_ERR(name)) + 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 Jun 3 05:18:30 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Dmitry Kadashev X-Patchwork-Id: 12296185 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.8 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,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 388F7C47082 for ; Thu, 3 Jun 2021 05:19:14 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 1A6F4613EE for ; Thu, 3 Jun 2021 05:19:14 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S229738AbhFCFUz (ORCPT ); Thu, 3 Jun 2021 01:20:55 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:36272 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229697AbhFCFUz (ORCPT ); Thu, 3 Jun 2021 01:20:55 -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 2258FC061761; Wed, 2 Jun 2021 22:19:02 -0700 (PDT) Received: by mail-ed1-x52e.google.com with SMTP id o5so5633472edc.5; Wed, 02 Jun 2021 22:19:02 -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=1gTNac3jobz9d5k3GILSgSEapm+k+pjGiF70eN3Yn3M=; b=X+laeIg+nigSlOYKSBNpnPfaHFAKaYf/Cggen6MyU8PRmSRzciuwhyWLgz5wDdATuP fp7He/E4AXlKe8Y7a8KZlz94Z/DBY4CMOFjPTfjtNDv7niyOzIkPP8jV0RGDpwC/MW5U vsx/uLOKbCGWtHeM5YPGcDz+LXtB6pbRmyUyh3Vzd0MepejXp+DocCc8yxLCXqxzSjR1 n7K55mmzIF4lw4JQrDJ6PfmwSpst9qqlxummXGOHAt4XEMayHCGJa2rjJlscmxDbWeBa HKnLQxdXYgyfWGbV6bhYGxTPtPZkgS47aXiZ+Xm0aYUKM10BlErIuH7tPgO2VsFBdKZU eQpw== 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=1gTNac3jobz9d5k3GILSgSEapm+k+pjGiF70eN3Yn3M=; b=piMsC7AlBDkoEap/xDZYzjhh82ofy5dt8YXywROawMaXQjSPLh/rmtDkb2BMHKo4LW S+McLV1OKNXbqb51+jFkbNiwVm2yN+IUE7Emc6ty557D51eRTOY4Ocxq2OXIcDEDgm76 NcO4fNX6XheUfZ0T4XXh5gtfvSzkPeN/LNWtJuOboAD/bgRHAKNY/YA+67N9Na+kZMAL Qw9csO7ME5OK84ef8blnU2avO6jbnU5xMGmpVlQr1+dG+HECA/wJN23uTAes9dlEaybM Sre5qpp7FckuYvMXpdQ+NO0HW9QJF6/78fUoddG+0DokgqLjPLrb1NMaxEniJ27zFMP9 r4ow== X-Gm-Message-State: AOAM5313RKh2BIKyED2PL8vGJyyaRUITDkpPVZxNlbvRMmpuL1+n0hHI STFyvYa4AnbseO8r84Nn/rc= X-Google-Smtp-Source: ABdhPJx3cnPxYHvbBBT+53ATg2Pg90+FwAEOeX9+MI5ekVGiJ2ZqdeOi0Sk3zDKzRyFKg6HSuRVb4w== X-Received: by 2002:a05:6402:26d1:: with SMTP id x17mr42069339edd.14.1622697540735; Wed, 02 Jun 2021 22:19:00 -0700 (PDT) Received: from carbon.v ([108.61.166.58]) by smtp.googlemail.com with ESMTPSA id f7sm963668ejz.95.2021.06.02.22.18.59 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 02 Jun 2021 22:19:00 -0700 (PDT) From: Dmitry Kadashev To: Jens Axboe , Alexander Viro , Christian Brauner Cc: Pavel Begunkov , linux-fsdevel@vger.kernel.org, io-uring@vger.kernel.org, Dmitry Kadashev Subject: [PATCH v5 04/10] fs: make do_symlinkat() take struct filename Date: Thu, 3 Jun 2021 12:18:30 +0700 Message-Id: <20210603051836.2614535-5-dkadashev@gmail.com> X-Mailer: git-send-email 2.30.2 In-Reply-To: <20210603051836.2614535-1-dkadashev@gmail.com> References: <20210603051836.2614535-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: Al Viro Cc: Christian Brauner Link: https://lore.kernel.org/io-uring/20210330071700.kpjoyp5zlni7uejm@wittgenstein/ Signed-off-by: Dmitry Kadashev --- fs/namei.c | 28 ++++++++++++++++------------ 1 file changed, 16 insertions(+), 12 deletions(-) diff --git a/fs/namei.c b/fs/namei.c index 9fc981e28788..76572d703e82 100644 --- a/fs/namei.c +++ b/fs/namei.c @@ -4189,23 +4189,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) { @@ -4220,20 +4220,24 @@ static long do_symlinkat(const char __user *oldname, int newdfd, lookup_flags |= LOOKUP_REVAL; goto retry; } -out_putname: - putname(from); +out_putboth: + if (!IS_ERR(to)) + putname(to); +out_putfrom: + if (!IS_ERR(from)) + putname(from); return error; } 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 Jun 3 05:18:31 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Dmitry Kadashev X-Patchwork-Id: 12296195 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.8 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,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 7B536C47097 for ; Thu, 3 Jun 2021 05:20:19 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 5D379611CC for ; Thu, 3 Jun 2021 05:20:19 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S229765AbhFCFWB (ORCPT ); Thu, 3 Jun 2021 01:22:01 -0400 Received: from mail-ed1-f46.google.com ([209.85.208.46]:34421 "EHLO mail-ed1-f46.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229479AbhFCFWB (ORCPT ); Thu, 3 Jun 2021 01:22:01 -0400 Received: by mail-ed1-f46.google.com with SMTP id cb9so5657192edb.1; Wed, 02 Jun 2021 22:20:02 -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=cjY5NIv8T/UjPF6/khgDh63aie+4OSg4ezXbryOnIVo=; b=L+lGiB8phnEr2PFwvu29s12yFsAgkqufFtWzpf3YDgkfKM56DjCSZzcPkV6m6JLzoc 4wR/Rrl32QvUAJ5ntz1X4CUEakwXIWjAVK7nAhMaKvz9kvssHVJw+SEo49cL8mW405iz OYoPlEzp+F3bYmpRfIyAviBYW4+YKPlhQ3gMUCBXnkdFLV8IoJD2vC3xheqw6PgVpEv3 wHz6YTBAw7eShlY3SQjiQqAAKw9kgru34mQGddAGsSlKlYlXIbR7ZVC9Hq20+DEh4TBG 4UbjYO4L6GxDg7uSvuMXmOjY5/7C+h3Zs1TJUqZP0LPr2+q/H8PCTpJHZziq25dZEnYX VBzw== 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=cjY5NIv8T/UjPF6/khgDh63aie+4OSg4ezXbryOnIVo=; b=fBBVTUSrxyLOy9g+s3b3Z9xehorbKmjloyR6hwpF/37nkNrw7AKTFUAS24+V3vpXkq H4GWBFHEEaPLU84fgeKLs7Bsrp8LlIkwCo5pJzgVKLoMpPnhhMY+7qLCT4SW/G0nQYDs u3GOAI4E1TQyE5C+H9yfNV9KF5KlW6Tb4J7EIyqtSNYxvJa0pQ9H/GTBp8pqwlZdl0ZW yXwoiEZeng1S1tYwYTqkh1hlP3LMDnmbWbPhmw50tFH1Pmr9F1Xp528Pk1adA5ptCBiT rHBlfRFTnSLxsezQPlkHb5lFkGT3M7/5tOJyGhYHRUbm64mTEoeiVECiQ1aI8hKxlfGw 8bkQ== X-Gm-Message-State: AOAM530/gEDQBsry9eyb2d5SAtE4lXdkhpFMTQ+GpLmQUIDOML4Pv0rA YzyE1Rnm0ZfEzwlWQOSxQ8Q= X-Google-Smtp-Source: ABdhPJxBQ1Ua7O8zOK+V7Vo+n9XvLnoMiqPIi1V4hs69VpXooJkakqO4wwdVGDk1CA1RCwJmVrELww== X-Received: by 2002:aa7:cb84:: with SMTP id r4mr41879537edt.187.1622697542301; Wed, 02 Jun 2021 22:19:02 -0700 (PDT) Received: from carbon.v ([108.61.166.58]) by smtp.googlemail.com with ESMTPSA id f7sm963668ejz.95.2021.06.02.22.19.00 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 02 Jun 2021 22:19:02 -0700 (PDT) From: Dmitry Kadashev To: Jens Axboe , Alexander Viro , Christian Brauner Cc: Pavel Begunkov , linux-fsdevel@vger.kernel.org, io-uring@vger.kernel.org, Dmitry Kadashev Subject: [PATCH v5 05/10] namei: add getname_uflags() Date: Thu, 3 Jun 2021 12:18:31 +0700 Message-Id: <20210603051836.2614535-6-dkadashev@gmail.com> X-Mailer: git-send-email 2.30.2 In-Reply-To: <20210603051836.2614535-1-dkadashev@gmail.com> References: <20210603051836.2614535-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: 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 76572d703e82..010455938826 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 Jun 3 05:18:32 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Dmitry Kadashev X-Patchwork-Id: 12296183 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.8 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,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 8A298C47098 for ; Thu, 3 Jun 2021 05:19:09 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 71ED161168 for ; Thu, 3 Jun 2021 05:19:09 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S229617AbhFCFUv (ORCPT ); Thu, 3 Jun 2021 01:20:51 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:36286 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229625AbhFCFUt (ORCPT ); Thu, 3 Jun 2021 01:20:49 -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 3F864C061763; Wed, 2 Jun 2021 22:19:05 -0700 (PDT) Received: by mail-ed1-x52d.google.com with SMTP id b11so5638802edy.4; Wed, 02 Jun 2021 22:19:05 -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=/6gjdhgoWsNs8yhzShxT5LW5mWmiDjbTWTCS2K2k6hw=; b=qZwGEcKJKf7fFx/7QMmkVo49tnEFODFvLpvknTX70ik+O5mToLdvt/KNxLoBSUSifv tvpzRlofU5jkJBBuPW/iK25nwdFeaow/LGNmyaSWZAn+jGQaxszyz2U7rVzioesvouJg 1gkaA6E4PU5ERfBtGYb58NO6yloO7PAUPgoK/DNTAHE3lXVN5UtLF19llDnv2DnMgCe0 IvkQxXN+fJbu4NWw1ijpp8EdiPsq3y9uWLZrP94iP+E4p2N2pWUm+0jDKIQnLmmF5rEh l1kP6jtdnP3UIh691esjYzaGuYz7WcVrPjJo752lCkRQykIjLmatUG+0p0cTDmCWXOEq RW+w== 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=/6gjdhgoWsNs8yhzShxT5LW5mWmiDjbTWTCS2K2k6hw=; b=b48RGrDQpG6/Xk7bgEQIHglGktmrc/CB1j09YvoK6rY8j402fLefG9EmrpVDRrCOEI Bu5vps5/0nhoSSLNyCzC7OKbanPDhunMnQLfmh8lzW42DXuPEZEQRLWUM1FwYGWYWZLh 8t2K2oTRePM5LN8pU27waTT1qQlL20itUHKg3BFT/gDIKAfTGsyLKzhtutWNNyHWsdeF YwPYYYQIPYDyXIrzK+eZ/zgEXqLfEe0EGJJ0zS3aKXePfgFknVlA4ZQzW6PUSPGn62Op QZ1G8eUIA0FRGPeMbsqS7fpS43z8qihuXxS2Jo2guPiXvvgNIh7eVqTQHJpvhIfmVctJ N9pw== X-Gm-Message-State: AOAM531Q2xTdP39nBWyaaNZEYSeg7IiKzorILqGMihFlogslogm0nzBm etRdxONKTa4eYyCXlbXKRik= X-Google-Smtp-Source: ABdhPJx7dW1So4NaV3x8lKR0UwkjqmHbIVb/kA1eOrZNjUJ927m07GJzE1lNMupQfRA9YOhBZ97rAw== X-Received: by 2002:a05:6402:274b:: with SMTP id z11mr23872798edd.225.1622697543867; Wed, 02 Jun 2021 22:19:03 -0700 (PDT) Received: from carbon.v ([108.61.166.58]) by smtp.googlemail.com with ESMTPSA id f7sm963668ejz.95.2021.06.02.22.19.02 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 02 Jun 2021 22:19:03 -0700 (PDT) From: Dmitry Kadashev To: Jens Axboe , Alexander Viro , Christian Brauner Cc: Pavel Begunkov , linux-fsdevel@vger.kernel.org, io-uring@vger.kernel.org, Dmitry Kadashev Subject: [PATCH v5 06/10] fs: make do_linkat() take struct filename Date: Thu, 3 Jun 2021 12:18:32 +0700 Message-Id: <20210603051836.2614535-7-dkadashev@gmail.com> X-Mailer: git-send-email 2.30.2 In-Reply-To: <20210603051836.2614535-1-dkadashev@gmail.com> References: <20210603051836.2614535-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: Al Viro Cc: Christian Brauner Link: https://lore.kernel.org/io-uring/20210330071700.kpjoyp5zlni7uejm@wittgenstein/ Signed-off-by: Dmitry Kadashev --- fs/namei.c | 59 +++++++++++++++++++++++++++++++++++++----------------- 1 file changed, 41 insertions(+), 18 deletions(-) diff --git a/fs/namei.c b/fs/namei.c index 010455938826..07b1619dd343 100644 --- a/fs/namei.c +++ b/fs/namei.c @@ -2447,7 +2447,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; @@ -2469,7 +2469,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, prevent extra freeing + // below + new = ERR_PTR(error); + goto out_putpath; + } error = -EXDEV; if (old_path.mnt != new_path.mnt) @@ -4408,8 +4424,14 @@ 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: + if (!IS_ERR(old)) + putname(old); +out_putnew: + if (!IS_ERR(new)) + putname(new); return error; } @@ -4417,12 +4439,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 Jun 3 05:18:33 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Dmitry Kadashev X-Patchwork-Id: 12296197 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.8 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,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 A489EC47082 for ; Thu, 3 Jun 2021 05:20:20 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 9148761168 for ; Thu, 3 Jun 2021 05:20:20 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S229774AbhFCFWD (ORCPT ); Thu, 3 Jun 2021 01:22:03 -0400 Received: from mail-ej1-f49.google.com ([209.85.218.49]:43698 "EHLO mail-ej1-f49.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229479AbhFCFWC (ORCPT ); Thu, 3 Jun 2021 01:22:02 -0400 Received: by mail-ej1-f49.google.com with SMTP id ci15so7259501ejc.10; Wed, 02 Jun 2021 22:20:05 -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=pWdnqBn8XRSM/Unr4zlccrzRL0CGq6yKJ1Y9tLojFEg=; b=pfo3Re9VCtcjyqJpzdb4Z2B+CSIo6LiV/ZNHOIJej3ZabalaEBTUSNu0Q53a+qk8IR PfXselMLVXlCOYLSCp3Gcibc6vPvcrFz3nfeYlTqfPfdv3g6jFyfNzCd6K++V3J3TSUE +D0VhEFDhAdHOsKtxfHwZM4xo7/2Mn/i5uLjUMRvwFq/t38OdeQ/JUX6itQDVPNvnBE/ DqW0pycKrCsHhL6FIHwf6oW6fCc6CyoiDJetfneasw1LBbmogJFoUJ+eQ1ZaR0ne0EO/ 1fi5ah9RZNByUo9iiCFTNcvDiVBidm+Wbamk01FqhizPHAYtXM5B8LznqXB3GABO0SxN RKOA== 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=pWdnqBn8XRSM/Unr4zlccrzRL0CGq6yKJ1Y9tLojFEg=; b=n9tEqDGbZlxVKn87fMW9ph8BKYi2GLmqdx1/C1ODWJHV+ULrX6akSmKFZwr3xjtIwh Jv0R5QawFP5iYz9G4zmLjvxzNAndJlrqSus+dp8MosKV+nc7LuW4+R8gYNs7GJbM89O9 AqxPaeWzCUg36FINdAOtpdSYjx7Z1WBmkNJigx44PZlMqyX7c8sVZR/VXdbC9djDi87k xltBQ/IMgm2hfPCcKNXabGYz+itDZqO5Tc03u4WkTo7hwkEBgrTjA+oSthDhOtHgsfr7 rW8P8O2xKy5K92hBbDxBN/mB3LRM66FURNdNJOEKhZqIE5UmEcZwppwv6fKo9DLwmczJ YIbA== X-Gm-Message-State: AOAM531fCy2klRLJO09ug9HINft2Z1uCqTqqF6+zxpDgIXPf7sk2XeT6 O7fTz3zqljCJIOtcD4BQTFw= X-Google-Smtp-Source: ABdhPJzTcFpqI02ZcCxZ3POD6ughxsN0f8iRen9rxH9vzz7dwbUffd5avEONl8wlLr9Whm/JRFOYpw== X-Received: by 2002:a17:906:4747:: with SMTP id j7mr28974351ejs.419.1622697545354; Wed, 02 Jun 2021 22:19:05 -0700 (PDT) Received: from carbon.v ([108.61.166.58]) by smtp.googlemail.com with ESMTPSA id f7sm963668ejz.95.2021.06.02.22.19.04 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 02 Jun 2021 22:19:05 -0700 (PDT) From: Dmitry Kadashev To: Jens Axboe , Alexander Viro , Christian Brauner Cc: Pavel Begunkov , linux-fsdevel@vger.kernel.org, io-uring@vger.kernel.org, Dmitry Kadashev Subject: [PATCH v5 07/10] fs: update do_*() helpers to return ints Date: Thu, 3 Jun 2021 12:18:33 +0700 Message-Id: <20210603051836.2614535-8-dkadashev@gmail.com> X-Mailer: git-send-email 2.30.2 In-Reply-To: <20210603051836.2614535-1-dkadashev@gmail.com> References: <20210603051836.2614535-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: Al Viro Cc: Christian Brauner Link: https://lore.kernel.org/io-uring/20210514143202.dmzfcgz5hnauy7ze@wittgenstein/ Signed-off-by: Dmitry Kadashev --- 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 07b1619dd343..f99de6e294ad 100644 --- a/fs/namei.c +++ b/fs/namei.c @@ -3743,7 +3743,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; @@ -3848,7 +3848,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; @@ -3943,7 +3943,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; @@ -4081,7 +4081,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; @@ -4208,7 +4208,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 Jun 3 05:18:34 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Dmitry Kadashev X-Patchwork-Id: 12296191 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.8 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,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 239D2C47097 for ; Thu, 3 Jun 2021 05:19:27 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 0E0A961168 for ; Thu, 3 Jun 2021 05:19:27 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S229754AbhFCFVJ (ORCPT ); Thu, 3 Jun 2021 01:21:09 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:36296 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229479AbhFCFVJ (ORCPT ); Thu, 3 Jun 2021 01:21:09 -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 31273C06174A; Wed, 2 Jun 2021 22:19:08 -0700 (PDT) Received: by mail-ej1-x634.google.com with SMTP id ci15so7259572ejc.10; Wed, 02 Jun 2021 22:19:08 -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=yUMTxJMtrIi0JQV4gg8vuuIPcQQdP8TYlw+/Ck8CwhI=; b=hYhtOs8rU5cMJXpwB0wxwH8LCloPTDBA52+e4IfZ9lBr2zqW6g4FqCxt6s3PROntsY LezgIfTpKs1jgTS6odMtT9K4VrQZ+VhEa0n3Zkjnm8yVSKmicuBzNePe2ufXAUf/KAqR gAYyVy4xUdcDPCL/bbE0azNKW9aA2WPF1eHsdYTaX7B0xo3t7pwbXFESjbMpKFc5CoB0 VOcquron1DuGOnpkbwavRyipnqXuMuqt/+Gu+/veJ4wsQ5ggpz31YHhUsCGGdKJYH+24 hIha27LU9vm8m1mIdGTpmr44N5Fke/QksDpMcrtmz5C246CH3D4BXSAbfOYa02PHYWJ1 R80Q== 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=yUMTxJMtrIi0JQV4gg8vuuIPcQQdP8TYlw+/Ck8CwhI=; b=aXfF/PfkpBlr0GHKHZHgbtHjD8TRwr1ZDNzDxOLq4TD21Jp4q0ktXlur4MkYABmGiA mrqZb1czS77nZ82ut9E8ECzB36DLm70xCNgCUTB2fwv75dfrhhPYY2yYYjgsjzKrV/JC pQluoilMStncVawcYHDGKYyN0X7hrNom8hGsVZ1Pn1laTpp6i51awJMVJtVIhJ54Cj3b mw2vQU7bK8r9UxZjmOCcxwxf38qBx08cH+gm67BLFXmWxaDJk/y7NkSByABXssZqrlQ7 csQoP2lMhFckSYebnO8perw3qSqeEl54gnhk6KHXK6hLItt+86rBIVhGSu65DgFufb/i LT8w== X-Gm-Message-State: AOAM5326Rz2ABvqwIzPU3Hy2U186VJcMeOfxxSTybMJVWW6Zi0OjWXaO gWery298fsDlrmwCi0BsoxM= X-Google-Smtp-Source: ABdhPJzRW05EHE7Ovaw8rOwgwu7M+wnkrjtepHKdSiXarQikH2et9C0OaHXwK8XIjemGFKYoBWNYYw== X-Received: by 2002:a17:906:e10d:: with SMTP id gj13mr20161946ejb.150.1622697546856; Wed, 02 Jun 2021 22:19:06 -0700 (PDT) Received: from carbon.v ([108.61.166.58]) by smtp.googlemail.com with ESMTPSA id f7sm963668ejz.95.2021.06.02.22.19.05 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 02 Jun 2021 22:19:06 -0700 (PDT) From: Dmitry Kadashev To: Jens Axboe , Alexander Viro , Christian Brauner Cc: Pavel Begunkov , linux-fsdevel@vger.kernel.org, io-uring@vger.kernel.org, Dmitry Kadashev Subject: [PATCH v5 08/10] io_uring: add support for IORING_OP_SYMLINKAT Date: Thu, 3 Jun 2021 12:18:34 +0700 Message-Id: <20210603051836.2614535-9-dkadashev@gmail.com> X-Mailer: git-send-email 2.30.2 In-Reply-To: <20210603051836.2614535-1-dkadashev@gmail.com> References: <20210603051836.2614535-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. Suggested-by: Christian Brauner Link: https://lore.kernel.org/io-uring/20210514145259.wtl4xcsp52woi6ab@wittgenstein/ Signed-off-by: Dmitry Kadashev --- fs/internal.h | 1 + fs/io_uring.c | 64 ++++++++++++++++++++++++++++++++++- fs/namei.c | 3 +- include/uapi/linux/io_uring.h | 1 + 4 files changed, 66 insertions(+), 3 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 8ab4eb559520..5fdba9b381e5 100644 --- a/fs/io_uring.c +++ b/fs/io_uring.c @@ -672,6 +672,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; @@ -817,6 +824,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; }; @@ -1030,6 +1038,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); @@ -3572,7 +3581,51 @@ static int io_mkdirat(struct io_kiocb *req, int issue_flags) req->flags &= ~REQ_F_NEED_CLEANUP; if (ret < 0) - req_set_fail_links(req); + req_set_fail(req); + io_req_complete(req, ret); + 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->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; } @@ -5985,6 +6038,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", @@ -6129,6 +6184,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; } req->flags &= ~REQ_F_NEED_CLEANUP; } @@ -6258,6 +6317,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 f99de6e294ad..f5b0379d2f8c 100644 --- a/fs/namei.c +++ b/fs/namei.c @@ -4208,8 +4208,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 bf9d720d371f..7b8a78d9c947 100644 --- a/include/uapi/linux/io_uring.h +++ b/include/uapi/linux/io_uring.h @@ -138,6 +138,7 @@ enum { IORING_OP_RENAMEAT, IORING_OP_UNLINKAT, IORING_OP_MKDIRAT, + IORING_OP_SYMLINKAT, /* this goes last, obviously */ IORING_OP_LAST, From patchwork Thu Jun 3 05:18:35 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Dmitry Kadashev X-Patchwork-Id: 12296199 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.8 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,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 6037FC47082 for ; Thu, 3 Jun 2021 05:20:24 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 3DD64613EE for ; Thu, 3 Jun 2021 05:20:24 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S229789AbhFCFWH (ORCPT ); Thu, 3 Jun 2021 01:22:07 -0400 Received: from mail-ej1-f50.google.com ([209.85.218.50]:33625 "EHLO mail-ej1-f50.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229479AbhFCFWH (ORCPT ); Thu, 3 Jun 2021 01:22:07 -0400 Received: by mail-ej1-f50.google.com with SMTP id g20so7387145ejt.0; Wed, 02 Jun 2021 22:20:08 -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=V0ZAIxaEcDtjGgd2KDmvA4K6LyrI8LXXSNsuTMTR3P0=; b=Jdu3sEwBprZvz5AoxtfhLOEMKJbzLqUOG5l3E8xdUAN47NsQtrW5cK9JtYTVhdRT3v WGRorpR+cp6D2IlR3mTyMQWabjKrmJabZ7QA2EFSw/GcSTb3jqoHs5S56fujGCySRkZ/ x5XK/bW1QKjAGODmWXRA3PTCDDfQQ90haMdKKExeJrkwbZ3FpFOpBAY9ECZpj0y+U3Ki yV4gjwxmM7pj/sympF6p4pXdFftrb3H+SGgs3Jgppw0mpUpqhx0ivRd246mWYYlDYs7y ywV6zZ6IR7rabFEgYP5a89fl/kD904K6+RysL5QSqmOCqbOxPRJwOZ5h3Fszyc8nnwnZ U4ew== 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=V0ZAIxaEcDtjGgd2KDmvA4K6LyrI8LXXSNsuTMTR3P0=; b=N9vBJ2CmgWUhqbE08YYKEz8HOgnBQsk5aAFWUijssYPzOvYjFiOw/AMGmpM03zKkj0 kWqBt7B/ihsc8sJPepfe9p5qKCxhbUUtCypNgXUrnyHY3R5h+331ywsMWsIMyZaMzVtP Ha0X1zavoeiWh7WlJS1d6UHCDd6GHWdyBRmaPjAPs7Ht4NuU4sxvnOqTDbwiFzI6y+9R fnlL1YikJ4H7mygNunAx7kK6gJ/vG8piJ0aGxhpSAUFZaydYc5xg9mvNauVDO8waNZxX BbSOhNIPnSHxHx62SsBy7No6fbOvCdPW/GQ/ocmrRrcLJvIhILUolVXpqlc1sPnjlAbY aQgA== X-Gm-Message-State: AOAM531XR6sHEA8ptRtq7Y3xA8XwY+wM8DfYt/OFXSsoKi5iPruUwh5c Lu9bxO466YxlqKgNkbS3uno= X-Google-Smtp-Source: ABdhPJx/wQC6FL/5QXjKOAgdc+xxKZYlyHO70zOObs/hXuvZUKzbYOUKTh731uxVPsT6IfIITqYx7w== X-Received: by 2002:a17:906:c1ca:: with SMTP id bw10mr38192062ejb.512.1622697548406; Wed, 02 Jun 2021 22:19:08 -0700 (PDT) Received: from carbon.v ([108.61.166.58]) by smtp.googlemail.com with ESMTPSA id f7sm963668ejz.95.2021.06.02.22.19.06 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 02 Jun 2021 22:19:08 -0700 (PDT) From: Dmitry Kadashev To: Jens Axboe , Alexander Viro , Christian Brauner Cc: Pavel Begunkov , linux-fsdevel@vger.kernel.org, io-uring@vger.kernel.org, Dmitry Kadashev Subject: [PATCH v5 09/10] io_uring: add support for IORING_OP_LINKAT Date: Thu, 3 Jun 2021 12:18:35 +0700 Message-Id: <20210603051836.2614535-10-dkadashev@gmail.com> X-Mailer: git-send-email 2.30.2 In-Reply-To: <20210603051836.2614535-1-dkadashev@gmail.com> References: <20210603051836.2614535-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. Suggested-by: Christian Brauner Link: https://lore.kernel.org/io-uring/20210514145259.wtl4xcsp52woi6ab@wittgenstein/ Signed-off-by: Dmitry Kadashev --- fs/internal.h | 2 ++ fs/io_uring.c | 67 +++++++++++++++++++++++++++++++++++ fs/namei.c | 2 +- include/uapi/linux/io_uring.h | 2 ++ 4 files changed, 72 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 5fdba9b381e5..31e1aa7dd90b 100644 --- a/fs/io_uring.c +++ b/fs/io_uring.c @@ -679,6 +679,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; @@ -825,6 +834,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; }; @@ -1039,6 +1049,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); @@ -3630,6 +3641,53 @@ 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->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) { @@ -6040,6 +6098,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", @@ -6188,6 +6248,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; } req->flags &= ~REQ_F_NEED_CLEANUP; } @@ -6320,6 +6384,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 f5b0379d2f8c..b85e457c43b7 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 7b8a78d9c947..510e64a0a9c3 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 */ union { @@ -139,6 +140,7 @@ enum { IORING_OP_UNLINKAT, IORING_OP_MKDIRAT, IORING_OP_SYMLINKAT, + IORING_OP_LINKAT, /* this goes last, obviously */ IORING_OP_LAST, From patchwork Thu Jun 3 05:18:36 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Dmitry Kadashev X-Patchwork-Id: 12296193 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.8 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,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 0F3D0C47097 for ; Thu, 3 Jun 2021 05:20:13 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id E16A561168 for ; Thu, 3 Jun 2021 05:20:12 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S229761AbhFCFVz (ORCPT ); Thu, 3 Jun 2021 01:21:55 -0400 Received: from mail-ej1-f53.google.com ([209.85.218.53]:43712 "EHLO mail-ej1-f53.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229479AbhFCFVy (ORCPT ); Thu, 3 Jun 2021 01:21:54 -0400 Received: by mail-ej1-f53.google.com with SMTP id ci15so7259721ejc.10; Wed, 02 Jun 2021 22:20: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=LdPXeisfjR9wg3D/KtinjwWcwB9HMs8tLTITCUSU3Zg=; b=SrIDphEHdV5JBR3sOK3zWVtY3Tolq/bnVxbXNB+UQRpJLTRRJMrt0mdhr9UyDnhLTQ ggckFa18tY0kixrN0q2pz4EMox3ynN9w0aPTcsebIpmBO/Jsma6h75kHUEBBQG8bxAah msHV/7pK4j34lE0sNjiG41Z3z0rBrowuGpZOQghW1cdV45Jko6ohY1Pu+TwdhOSzkJBp HzsupU3j/HxT6T7A5xpdMYkobh6MfX8i4m+1jKz/rHvBhU9DEZw8Vvvn+izMa7hoDo72 jgiV9vvu15pqFKw9/ALy+y5gkflX9o2f9NnAiYJMgJct5ezY9n+asiAh9M7jxSqMFlBc LinQ== 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=LdPXeisfjR9wg3D/KtinjwWcwB9HMs8tLTITCUSU3Zg=; b=lQFpHFr/Ej4r8kttpgF5DAEJxZpMXhRHUESiX8EmC3mC7ou6q+uJu6q2N0kF17U6xE FX6naYGGDWtILOmug+bMgy5QdQGSqC1TG561e2Y/B38Ws/yWMZ9Dzhj2RTN7eE2uyjz1 C7mNhji2aiF2ZU9n9Nc5e6Ex5WsCzNUGmY30tYAt+gHb3WfsRNZRaSmkQCWIAAnex/Gr J/TLqFxsxkMwIfTCxGIxC/LPpNNBr2GXp77AZGJVeq68IHBQyCnwMirTxi7rk/4vqFLM HmarJMjBmWQogEddc+PdruL0fWhZ3I/MsOQpka2DEHmFYkqNh8pOIfeC202BikW1AEAF 0/Zw== X-Gm-Message-State: AOAM5307kh91Tabogl4+HfDEWepWULoeNIBlKX2H7Rzw1l9cyYd4TQnc anwtpFUXpz8Oc9OZIo+yTss= X-Google-Smtp-Source: ABdhPJyAmEdFPt37PH9Ey69Jhrxsm8vO0pOBh4+jKFymc2GGmnHoWTtx+Dr2RgOO7hZ/ny3y3hcgIg== X-Received: by 2002:a17:906:b855:: with SMTP id ga21mr10513704ejb.550.1622697549921; Wed, 02 Jun 2021 22:19:09 -0700 (PDT) Received: from carbon.v ([108.61.166.58]) by smtp.googlemail.com with ESMTPSA id f7sm963668ejz.95.2021.06.02.22.19.08 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 02 Jun 2021 22:19:09 -0700 (PDT) From: Dmitry Kadashev To: Jens Axboe , Alexander Viro , Christian Brauner Cc: Pavel Begunkov , linux-fsdevel@vger.kernel.org, io-uring@vger.kernel.org, Dmitry Kadashev Subject: [PATCH v5 10/10] io_uring: add support for IORING_OP_MKNODAT Date: Thu, 3 Jun 2021 12:18:36 +0700 Message-Id: <20210603051836.2614535-11-dkadashev@gmail.com> X-Mailer: git-send-email 2.30.2 In-Reply-To: <20210603051836.2614535-1-dkadashev@gmail.com> References: <20210603051836.2614535-1-dkadashev@gmail.com> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: linux-fsdevel@vger.kernel.org IORING_OP_MKNODAT behaves like mknodat(2) and takes the same flags and arguments. Suggested-by: Christian Brauner Link: https://lore.kernel.org/io-uring/20210514145259.wtl4xcsp52woi6ab@wittgenstein/ Signed-off-by: Dmitry Kadashev --- fs/internal.h | 2 ++ fs/io_uring.c | 56 +++++++++++++++++++++++++++++++++++ fs/namei.c | 2 +- include/uapi/linux/io_uring.h | 2 ++ 4 files changed, 61 insertions(+), 1 deletion(-) diff --git a/fs/internal.h b/fs/internal.h index 15a7d210cc67..c6fb9974006f 100644 --- a/fs/internal.h +++ b/fs/internal.h @@ -81,6 +81,8 @@ 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); +int do_mknodat(int dfd, struct filename *name, umode_t mode, + unsigned int dev); /* * namespace.c diff --git a/fs/io_uring.c b/fs/io_uring.c index 31e1aa7dd90b..475632374af8 100644 --- a/fs/io_uring.c +++ b/fs/io_uring.c @@ -688,6 +688,14 @@ struct io_hardlink { int flags; }; +struct io_mknod { + struct file *file; + int dfd; + umode_t mode; + struct filename *filename; + unsigned int dev; +}; + struct io_completion { struct file *file; struct list_head list; @@ -835,6 +843,7 @@ struct io_kiocb { struct io_mkdir mkdir; struct io_symlink symlink; struct io_hardlink hardlink; + struct io_mknod mknod; /* use only after cleaning per-op data, see io_clean_op() */ struct io_completion compl; }; @@ -1050,6 +1059,7 @@ static const struct io_op_def io_op_defs[] = { [IORING_OP_MKDIRAT] = {}, [IORING_OP_SYMLINKAT] = {}, [IORING_OP_LINKAT] = {}, + [IORING_OP_MKNODAT] = {}, }; static bool io_disarm_next(struct io_kiocb *req); @@ -3687,6 +3697,44 @@ static int io_linkat(struct io_kiocb *req, int issue_flags) io_req_complete(req, ret); return 0; } +static int io_mknodat_prep(struct io_kiocb *req, + const struct io_uring_sqe *sqe) +{ + struct io_mknod *mkn = &req->mknod; + const char __user *fname; + + if (unlikely(req->flags & REQ_F_FIXED_FILE)) + return -EBADF; + + mkn->dfd = READ_ONCE(sqe->fd); + mkn->mode = READ_ONCE(sqe->len); + fname = u64_to_user_ptr(READ_ONCE(sqe->addr)); + mkn->dev = READ_ONCE(sqe->mknod_dev); + + mkn->filename = getname(fname); + if (IS_ERR(mkn->filename)) + return PTR_ERR(mkn->filename); + + req->flags |= REQ_F_NEED_CLEANUP; + return 0; +} + +static int io_mknodat(struct io_kiocb *req, int issue_flags) +{ + struct io_mknod *mkn = &req->mknod; + int ret; + + if (issue_flags & IO_URING_F_NONBLOCK) + return -EAGAIN; + + ret = do_mknodat(mkn->dfd, mkn->filename, mkn->mode, mkn->dev); + + 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) @@ -6100,6 +6148,8 @@ static int io_req_prep(struct io_kiocb *req, const struct io_uring_sqe *sqe) return io_symlinkat_prep(req, sqe); case IORING_OP_LINKAT: return io_linkat_prep(req, sqe); + case IORING_OP_MKNODAT: + return io_mknodat_prep(req, sqe); } printk_once(KERN_WARNING "io_uring: unhandled opcode %d\n", @@ -6252,6 +6302,9 @@ static void io_clean_op(struct io_kiocb *req) putname(req->hardlink.oldpath); putname(req->hardlink.newpath); break; + case IORING_OP_MKNODAT: + putname(req->mknod.filename); + break; } req->flags &= ~REQ_F_NEED_CLEANUP; } @@ -6387,6 +6440,9 @@ static int io_issue_sqe(struct io_kiocb *req, unsigned int issue_flags) case IORING_OP_LINKAT: ret = io_linkat(req, issue_flags); break; + case IORING_OP_MKNODAT: + ret = io_mknodat(req, issue_flags); + break; default: ret = -EINVAL; break; diff --git a/fs/namei.c b/fs/namei.c index b85e457c43b7..a4b1848b5dd1 100644 --- a/fs/namei.c +++ b/fs/namei.c @@ -3743,7 +3743,7 @@ static int may_mknod(umode_t mode) } } -static int do_mknodat(int dfd, struct filename *name, umode_t mode, +int do_mknodat(int dfd, struct filename *name, umode_t mode, unsigned int dev) { struct user_namespace *mnt_userns; diff --git a/include/uapi/linux/io_uring.h b/include/uapi/linux/io_uring.h index 510e64a0a9c3..824b37f53a28 100644 --- a/include/uapi/linux/io_uring.h +++ b/include/uapi/linux/io_uring.h @@ -45,6 +45,7 @@ struct io_uring_sqe { __u32 rename_flags; __u32 unlink_flags; __u32 hardlink_flags; + __u32 mknod_dev; }; __u64 user_data; /* data to be passed back at completion time */ union { @@ -141,6 +142,7 @@ enum { IORING_OP_MKDIRAT, IORING_OP_SYMLINKAT, IORING_OP_LINKAT, + IORING_OP_MKNODAT, /* this goes last, obviously */ IORING_OP_LAST,