From patchwork Thu Jun 24 11:14: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: 12341867 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-15.7 required=3.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,FREEMAIL_FORGED_FROMDOMAIN,FREEMAIL_FROM, HEADER_FROM_DIFFERENT_DOMAINS,INCLUDES_CR_TRAILER,INCLUDES_PATCH, MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS,URIBL_BLOCKED,USER_AGENT_GIT autolearn=unavailable autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id D9848C49EAF for ; Thu, 24 Jun 2021 11:15:11 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id B9C53613B3 for ; Thu, 24 Jun 2021 11:15:11 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S232426AbhFXLR3 (ORCPT ); Thu, 24 Jun 2021 07:17:29 -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 S232425AbhFXLR2 (ORCPT ); Thu, 24 Jun 2021 07:17:28 -0400 Received: from mail-lf1-x12a.google.com (mail-lf1-x12a.google.com [IPv6:2a00:1450:4864:20::12a]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id BD19EC061756; Thu, 24 Jun 2021 04:15:08 -0700 (PDT) Received: by mail-lf1-x12a.google.com with SMTP id j4so9591922lfc.8; Thu, 24 Jun 2021 04:15: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=QyHp2xzhpqD2nwO3PN1Ayttz+R1SUObrYVCQMwaBZ6w=; b=eJK9CfMbWMp6gtZmvXaI3nDqd6lQ3xbY9bkfRIqlhIZn2Mp5hwFkFY1XG6yfXrEBLr IYCDVF8JnN+CeRenQfeqEsZhXjFHZ6KeJ2dX4UbuLY192Xx5z5m6t+I3mP+sQqgCWTYv SfZW3XqRE7nkMjvcWHtj720bevxV8fvKHc6Mo3Srvqu7v9ceQ8bPlMMawa9Z02ix7RD3 oEbNvodYBsbhbbEXZlOyNC4OKZMJg0Htxg4BmjmXnrlBAAidXPHDkxxrl4zwpoedhqu+ Cm2Jr3w9A8BuMzCK5tIQhPavr1qRnXoDM0ApKmYHle3fSgfZVMj1HRNIhxigSNuA72C0 KZPw== 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=QyHp2xzhpqD2nwO3PN1Ayttz+R1SUObrYVCQMwaBZ6w=; b=QVU1+rYzqW98CuVw8Halu2rE+olLDz+AxJ6nYf4fYxpqd8oHBdZToLSVDDVxCnTE5R sRcKKtTu84+80kAPHsqjkEX9pVMvO96GzxEf6Cd839RoYe1R0umaVGKa6vZ1kksAIGQi Xc5ClIz2tg6CMxYX1aUksDvIxpd3iP67OfaC166fhU/CXJd5ML0WTtY7lNWyZOf/1Sy+ 1g6ThFC0XA4IKjOBUGv9/fblltWfdRmvihf0nS9ADfLM3XctBkQvJVPpcH5gda//eWm5 yinGyCQH2iNHV3d2wYlPkUSZQXz8tTmR6hvpQnDyruZV2M2kjbshvqyh8B3y+xx0Ideb H4fA== X-Gm-Message-State: AOAM532eg+3s+4+Y5IotEXNuHFpIB0WRztnCzIxFVACLgdbVIh1nEYha AsIBo8JVG1Ikw1QB6mFB26Q= X-Google-Smtp-Source: ABdhPJwhEj2g3NjgyIlvNxFXWPGYkuxNOZEP90SZf3jlOawlDx6cRT0158+Q+oFMh1TMlGQFf3c9Gg== X-Received: by 2002:ac2:4d2d:: with SMTP id h13mr3500292lfk.456.1624533307170; Thu, 24 Jun 2021 04:15:07 -0700 (PDT) Received: from carbon.v ([94.143.149.146]) by smtp.googlemail.com with ESMTPSA id q21sm195293lfp.233.2021.06.24.04.15.05 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 24 Jun 2021 04:15: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 v6 1/9] fs: make do_mkdirat() take struct filename Date: Thu, 24 Jun 2021 18:14:44 +0700 Message-Id: <20210624111452.658342-2-dkadashev@gmail.com> X-Mailer: git-send-email 2.30.2 In-Reply-To: <20210624111452.658342-1-dkadashev@gmail.com> References: <20210624111452.658342-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 Acked-by: Christian Brauner --- fs/internal.h | 1 + fs/namei.c | 22 ++++++++++++++++------ 2 files changed, 17 insertions(+), 6 deletions(-) diff --git a/fs/internal.h b/fs/internal.h index 6aeae7ef3380..848e165ef0f1 100644 --- a/fs/internal.h +++ b/fs/internal.h @@ -77,6 +77,7 @@ long do_unlinkat(int dfd, struct filename *name); int may_linkat(struct user_namespace *mnt_userns, struct path *link); int do_renameat2(int olddfd, struct filename *oldname, int newdfd, struct filename *newname, unsigned int flags); +long do_mkdirat(int dfd, struct filename *name, umode_t mode); /* * namespace.c diff --git a/fs/namei.c b/fs/namei.c index 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 24 11:14: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: 12341869 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-12.9 required=3.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,FREEMAIL_FORGED_FROMDOMAIN,FREEMAIL_FROM, HEADER_FROM_DIFFERENT_DOMAINS,INCLUDES_CR_TRAILER,INCLUDES_PATCH, MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS,UNWANTED_LANGUAGE_BODY, URIBL_BLOCKED,USER_AGENT_GIT autolearn=unavailable autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 34D97C49EA6 for ; Thu, 24 Jun 2021 11:15:13 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 1469A613F7 for ; Thu, 24 Jun 2021 11:15:13 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S232432AbhFXLRa (ORCPT ); Thu, 24 Jun 2021 07:17:30 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:56232 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S232428AbhFXLRa (ORCPT ); Thu, 24 Jun 2021 07:17:30 -0400 Received: from mail-lf1-x131.google.com (mail-lf1-x131.google.com [IPv6:2a00:1450:4864:20::131]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 0ED2BC061574; Thu, 24 Jun 2021 04:15:10 -0700 (PDT) Received: by mail-lf1-x131.google.com with SMTP id h15so9533744lfv.12; Thu, 24 Jun 2021 04:15:09 -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=9qDoYzfl0bIPxzQm1x+MMcHUZDjEANw5MIs77Mv++MA=; b=rbnuKqs2nQwSXP6WvLVJhlh6Yqvyv/5ylWQZ20rCOa3mbdvlKtdNwHtr3UDE1oQV+m 3jO50HkA4jilDzehwFBNAPYysd+L2l+FFZNYJh3jkd3GnARncu3KDVDp2UCHgjH9ClVL n6PiAPP7EzmblBxcrJECS+6mLPkBtU1l9hrVIGbLJZszggX/9CZSZNOmhS2P55WasQO4 C+pGr+0qJL+bOgQYF9lpq0EuaNdfd+FKYrmv0Nz1W5Iel7Aw6o/PZa52ghfCb1wJ+sYR ouD1n1QSTCZtNCa9fpYtIk1TC9fM/9T5qEGFMydGfiC1IXA8miFqsWE3iWWbLcblCeO8 /Xww== 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=9qDoYzfl0bIPxzQm1x+MMcHUZDjEANw5MIs77Mv++MA=; b=iFtVZ3s5ymO/En0bn3Z+rfaJaRw04yqyA4/QzJX96zZ6o6c0UhS+nUOHoLfaAIXG+W jxuFsvR9XMbdgxpPbo+n8L6/dzbx2hYKuC6/wsRCKC6KIOeqw+mdZPzs0YQfmxliXQ1E u8NUNAMLQSzLdmHybxFhMrbiHiW9TB79k6webnUg59zYZpa8MIPXZTZxvPB+4A7KNKMl svp4oxmdaYSBcxZ3eLr7Fl9QG5SKWdt3edaNaGAEkOwmcmaqtjQ0sCGe168j8S/HpP4B Zew3zgOAg6bH/A5kUgHd/umRgy8iFHa5qCErR6J/sDk33I+wu5nPVr9RC8+RfXGaSVZV o1lA== X-Gm-Message-State: AOAM530EoUyz1mjcktNCLR00lPUQo0DnuafC5nc4BLqfC6KLjMp1ocym ynN43dS7FSpYOxyTMpPy7+FeAcR7Xm/pSQ== X-Google-Smtp-Source: ABdhPJx7z74mo6SGqEyer211Zu/L5FKsM9uCQO9UmW0FaEC6RTROucTFmOyGOJ6pM6mscqodsQS5vA== X-Received: by 2002:a05:6512:230e:: with SMTP id o14mr3444223lfu.124.1624533308454; Thu, 24 Jun 2021 04:15:08 -0700 (PDT) Received: from carbon.v ([94.143.149.146]) by smtp.googlemail.com with ESMTPSA id q21sm195293lfp.233.2021.06.24.04.15.07 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 24 Jun 2021 04:15: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 v6 2/9] io_uring: add support for IORING_OP_MKDIRAT Date: Thu, 24 Jun 2021 18:14:45 +0700 Message-Id: <20210624111452.658342-3-dkadashev@gmail.com> X-Mailer: git-send-email 2.30.2 In-Reply-To: <20210624111452.658342-1-dkadashev@gmail.com> References: <20210624111452.658342-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 Acked-by: Christian Brauner Reviewed-by: Pavel Begunkov --- 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 e7997f9bf879..7aa08ed78452 100644 --- a/fs/io_uring.c +++ b/fs/io_uring.c @@ -673,6 +673,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; @@ -825,6 +832,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; }; @@ -1039,6 +1047,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); @@ -3548,6 +3557,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) { @@ -5956,6 +6007,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", @@ -6117,6 +6170,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) { @@ -6245,6 +6301,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 f1f9ac114b51..49a24a149eeb 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 24 11:14: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: 12341871 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-15.7 required=3.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,FREEMAIL_FORGED_FROMDOMAIN,FREEMAIL_FROM, HEADER_FROM_DIFFERENT_DOMAINS,INCLUDES_CR_TRAILER,INCLUDES_PATCH, MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS,URIBL_BLOCKED,USER_AGENT_GIT autolearn=unavailable autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 0EEB4C49EB9 for ; Thu, 24 Jun 2021 11:15:14 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id EEFDF613B3 for ; Thu, 24 Jun 2021 11:15:13 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S232437AbhFXLRb (ORCPT ); Thu, 24 Jun 2021 07:17:31 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:56236 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S232430AbhFXLRa (ORCPT ); Thu, 24 Jun 2021 07:17:30 -0400 Received: from mail-lf1-x12c.google.com (mail-lf1-x12c.google.com [IPv6:2a00:1450:4864:20::12c]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 5BC5AC06175F; Thu, 24 Jun 2021 04:15:11 -0700 (PDT) Received: by mail-lf1-x12c.google.com with SMTP id j4so9592117lfc.8; Thu, 24 Jun 2021 04:15:11 -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=PsIkIlYkcRuVZO2iraM96+UBjw71A+O5XYihkmv99aY=; b=SWsU/P3D0kaQR2TvWhtm8l2HrdbIVx85lqNEUyzVr4YQJJfwz/yy/Qv8AFbPPhxlWj VWsGrf4YzFPYO6MEIN5WpvwG5Oyh4ikkqq2ULtsaY3jbn0BhNnphKr34Ora7zbX9rllB gQXdDmzHITw+AfG73IVyYABmpQ34WcdLWaznKBOScNEEukD5BBiI/lcXeHWl2DYDA+xn XTykEoyS+Ti1zULLpfvBzrDZlOsN71um2qclntQrMblCnIDXsAHURdEe70JOENkFM+HK DBmkY31x1eh2aBIyZRf+PZHuNsIH0TL00LGmNIP69BarF1TjfC/SIWjFDLAoa3Zn/oy3 7zIQ== 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=PsIkIlYkcRuVZO2iraM96+UBjw71A+O5XYihkmv99aY=; b=DjPHwbXG2lCYHFnyK+oTG2u9bdT6IORvukIXnMrbKgIMmyxWmiwTg28XPKWFdAORmV qbEBajyxqDlkXlnnrsUkFJH9TcI9zSIjce0VZNZxV+o/FSPd3G+yqQ/rbLKyCtXdDepW Bh/9MqoxgCQhRUr5sDPMmbmfEOyqx3/jMM9GV0qKx4uoDsaj4kcAVF0yZcsETYwMSd6S 9YYEwV3Ls1K7hl4FGjEx29vp5cUsZOOgQwW338r7sGi5m+voLQYJ3+Uv2G+26yobg4gW t7zjHD/Lf1TCkIjar1qt/yCzTiePXLsv47tkPuWQF0lZT1v1pmVtS6N8YUMf+Q/Ixmpp lOSg== X-Gm-Message-State: AOAM530zNLM6PYydvDo3Po2URdgrPAUVqZKb/YCZExIBUJjL8m/Jz8bN o0MIgEqkVqzLph3HJEThsnA= X-Google-Smtp-Source: ABdhPJwymf6vqvQOLZDszG61wVFkmMLL5CLN4xOOgf20TvIQABfzE9Q+8/AAKCzHtKYGbz8dFJI+yQ== X-Received: by 2002:ac2:442c:: with SMTP id w12mr3475317lfl.303.1624533309782; Thu, 24 Jun 2021 04:15:09 -0700 (PDT) Received: from carbon.v ([94.143.149.146]) by smtp.googlemail.com with ESMTPSA id q21sm195293lfp.233.2021.06.24.04.15.08 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 24 Jun 2021 04:15: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 v6 3/9] fs: make do_mknodat() take struct filename Date: Thu, 24 Jun 2021 18:14:46 +0700 Message-Id: <20210624111452.658342-4-dkadashev@gmail.com> X-Mailer: git-send-email 2.30.2 In-Reply-To: <20210624111452.658342-1-dkadashev@gmail.com> References: <20210624111452.658342-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 Acked-by: Christian Brauner --- 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 24 11:14: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: 12341873 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-15.7 required=3.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,FREEMAIL_FORGED_FROMDOMAIN,FREEMAIL_FROM, HEADER_FROM_DIFFERENT_DOMAINS,INCLUDES_CR_TRAILER,INCLUDES_PATCH, MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS,URIBL_BLOCKED,USER_AGENT_GIT autolearn=unavailable autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 99B07C49EA6 for ; Thu, 24 Jun 2021 11:15:18 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 83D92613B3 for ; Thu, 24 Jun 2021 11:15:18 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S232412AbhFXLRf (ORCPT ); Thu, 24 Jun 2021 07:17:35 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:56248 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S232421AbhFXLRb (ORCPT ); Thu, 24 Jun 2021 07:17:31 -0400 Received: from mail-lf1-x132.google.com (mail-lf1-x132.google.com [IPv6:2a00:1450:4864:20::132]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 9F3EAC061574; Thu, 24 Jun 2021 04:15:12 -0700 (PDT) Received: by mail-lf1-x132.google.com with SMTP id d16so9615011lfn.3; Thu, 24 Jun 2021 04:15: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=L2KbzsLRkfXUNVSPy7TFTX4HqFkjy2iFgmcesZmodrg=; b=BSGo4b7VCQS1gF53MLnCET69aQIZx2s3Pw33dnaeODLCV63de/FDNU7zavQgHvO+5v hEdq9PbHtSknuEQMI/8AYjPcY81bUMkDiG4B2MQb30ETS3uDK3XgUdVBytuQDdAwhFf6 59ydi3e9d6Zt4soPiQ1fyrDVIDZL8Au7fFkwtNxHlVJAq3P/jyfGGybQXm9ladnWUPFq v10DWKn8Ldm09D0L/LcsuYjvOlsH+rBPKWsZ2FVfbq37hVCmFwm9Y5GvgC/6k+KIOgoF IUGGzNHHFSQj+MZpx0o9pE1cnW5NRWxh7O2TBLUJjfn48/QOdGk8DUoqlFkk6QK4ruI5 57Ew== 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=L2KbzsLRkfXUNVSPy7TFTX4HqFkjy2iFgmcesZmodrg=; b=SGNun0SbG7OnCF5Ax9slR/t7dZUcGCa3CQ1fdyUP+It0aiIKF4798FR+yDMhkx2PIQ 90/IUM9Nsv3SCgurqnZM0NmSAe5X8tqsu3b1OXQRSdzALR7NMvuSBX7G7I4JC5FP/spV qQ+r3LrQnh+9cM5rEPqNsuo8F2dCMyipiwjV/uAfvqgOCcvV+VUQOrmwiBS4nIUSRnV4 UPHxewEs7BV11IXXLL1R53yHD3JFpPTgLNYmSbjwakdTrezrv6lfmhq58WMb83Dh0DXN lsQlHkO3cP85zscnokeRzwc6ubhOsKyWRRI3S6jHO+IKh/0QHcQ1FDhLPZYJtBMcjZTB h/zg== X-Gm-Message-State: AOAM532tJKxIpFZXdycez0J3fdp5cDWQosUpxN6MiBfYH7clsEHbKuUq Vc+nEM5Jw995qBtdrn2cFWw= X-Google-Smtp-Source: ABdhPJxrjV8b5v3JrHUurMP5IS4mnUdZN3dELmfIr2Xm31ltf7lYeL7ggZMu1SUHkEJHjgjA1cBFHw== X-Received: by 2002:a05:6512:169f:: with SMTP id bu31mr3484958lfb.486.1624533311049; Thu, 24 Jun 2021 04:15:11 -0700 (PDT) Received: from carbon.v ([94.143.149.146]) by smtp.googlemail.com with ESMTPSA id q21sm195293lfp.233.2021.06.24.04.15.09 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 24 Jun 2021 04:15:10 -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 v6 4/9] fs: make do_symlinkat() take struct filename Date: Thu, 24 Jun 2021 18:14:47 +0700 Message-Id: <20210624111452.658342-5-dkadashev@gmail.com> X-Mailer: git-send-email 2.30.2 In-Reply-To: <20210624111452.658342-1-dkadashev@gmail.com> References: <20210624111452.658342-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 Acked-by: Christian Brauner --- 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 24 11:14:48 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Dmitry Kadashev X-Patchwork-Id: 12341875 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-15.7 required=3.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,FREEMAIL_FORGED_FROMDOMAIN,FREEMAIL_FROM, HEADER_FROM_DIFFERENT_DOMAINS,INCLUDES_CR_TRAILER,INCLUDES_PATCH, MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS,URIBL_BLOCKED,USER_AGENT_GIT autolearn=unavailable autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 80B54C49EAF for ; Thu, 24 Jun 2021 11:15:19 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 66DA0600CC for ; Thu, 24 Jun 2021 11:15:19 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S232442AbhFXLRg (ORCPT ); Thu, 24 Jun 2021 07:17:36 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:56256 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S232338AbhFXLRd (ORCPT ); Thu, 24 Jun 2021 07:17:33 -0400 Received: from mail-lj1-x234.google.com (mail-lj1-x234.google.com [IPv6:2a00:1450:4864:20::234]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 15C3BC061756; Thu, 24 Jun 2021 04:15:14 -0700 (PDT) Received: by mail-lj1-x234.google.com with SMTP id f13so7208440ljp.10; Thu, 24 Jun 2021 04:15:14 -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=iPq9xrKb0sRL7Yr9n1OmNxiPLN2GfT6ZyRhYwm7ARhlN0/DRkMHt2sFM7RGXlgBmCV IMFjahnn5wtgJUJI47fapqOkiwwIjs4A9WEJ6fG6zbw0TWz6faa7a7bonY5Hvlsv5GR/ h0QzJ85j9RBHBPEY/bKHGnMq4gL+WdMZa0qY4g5eRaVCH60XEJCCUF0vp5AmMt+HpTm7 8mFcQbensaJuqiymZ32luFOi7inXI6IW23lUhUPqFgTabKGovtPwlyaiy7W3fGQrGtXM LmKtKpxjgM+dLRRuKjBDkqrFbnfxDYWxv9GeF5YyesWUq+4B8xHMJoYJNK+wEMpdvr2N 2/Iw== 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=KhMOIi2uA3U6a5QQbi0CWWw8WchlRwQKGijqhbpzzKtjJpYG1puh+wHsZCQmqIY8x+ Zz60CUzDvDDK4wDkN5xHFJLdAW9cVt9USSxdBxkfjgHVGXYHGWpuYET8+Rh4iqq3XWAi 2YDgoYLHIZowBXCIFdQ2JgHQWpxd3pGElZOmT8mCwdkNv9FHiv6sTL6lwEtkMJOduLHR NOsE+lMa94bnLpGlL3U91vv977Glg5vlTeSvbXXmlUbWR1A2D+nJ/fIqEvlLddMxt8Nm Rm2ZqylYnBOhV+aBzkLTDUghzUEkO53hPDNp3uTULkLmew2QfGZainaNfaox+AJUOmRh 30Cw== X-Gm-Message-State: AOAM530UrvsmsoCVuBDUvaovMFZQowc1ZBuK6QghZlBP4REOGMwkHSc2 6VDrN3BhCWVV7OQ1MwUrCiU= X-Google-Smtp-Source: ABdhPJxku+acLC+qRFUlPCKbuqqKavPd77Hh1oluLVaX7b7XEZQu2t7SgzsHbaqTBdNQSbvIdp+1vA== X-Received: by 2002:a2e:8941:: with SMTP id b1mr3566449ljk.284.1624533312471; Thu, 24 Jun 2021 04:15:12 -0700 (PDT) Received: from carbon.v ([94.143.149.146]) by smtp.googlemail.com with ESMTPSA id q21sm195293lfp.233.2021.06.24.04.15.11 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 24 Jun 2021 04:15:11 -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 v6 5/9] namei: add getname_uflags() Date: Thu, 24 Jun 2021 18:14:48 +0700 Message-Id: <20210624111452.658342-6-dkadashev@gmail.com> X-Mailer: git-send-email 2.30.2 In-Reply-To: <20210624111452.658342-1-dkadashev@gmail.com> References: <20210624111452.658342-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 24 11:14:49 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Dmitry Kadashev X-Patchwork-Id: 12341877 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-15.7 required=3.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,FREEMAIL_FORGED_FROMDOMAIN,FREEMAIL_FROM, HEADER_FROM_DIFFERENT_DOMAINS,INCLUDES_CR_TRAILER,INCLUDES_PATCH, MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS,URIBL_BLOCKED,USER_AGENT_GIT autolearn=unavailable autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 4D729C49EAB for ; Thu, 24 Jun 2021 11:15:21 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 398E8600CC for ; Thu, 24 Jun 2021 11:15:21 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S232450AbhFXLRh (ORCPT ); Thu, 24 Jun 2021 07:17:37 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:56264 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S232400AbhFXLRf (ORCPT ); Thu, 24 Jun 2021 07:17:35 -0400 Received: from mail-lj1-x231.google.com (mail-lj1-x231.google.com [IPv6:2a00:1450:4864:20::231]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 5CAE7C06175F; Thu, 24 Jun 2021 04:15:15 -0700 (PDT) Received: by mail-lj1-x231.google.com with SMTP id k8so7217718lja.4; Thu, 24 Jun 2021 04:15: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=Vv6DVh3tEsvpayNYC4FRBkF8ClCa9cXNvJfjsWO+/EA=; b=Ore1rgw05VR+TEHM/j4REJ3EYQoTY1iS68M1HC2lRAh6EDKZZXtwpSrqibsD5l6vwn Ct6/GpDjVnshk8c+FDxx1stgtFGDtORB8o5tPd7H7CjFIIip/BNyANiBtrOy9/OPvNXO UMMohMffagpuWtoz2WUIq5ng6K10QouafaHyJp7QncMYLXc/4yqvARsdhI1h3vnakDqA L3sjuLf3FoNwEFkXZNJvzW33PuhW7sBMLblgEJUs/pm//dY9YGfOEGv0leoUfxPJbG/d eGsB/RytYTUJjZkF5WdeWAvMa1p1oFeKhctGOtZv8JkA6f5NBiS9jNcsXj1s3PMG0bUl qNzA== 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=Vv6DVh3tEsvpayNYC4FRBkF8ClCa9cXNvJfjsWO+/EA=; b=WWUtZ8zTbnZZmQDjBFA6MIVH+pf0x6upqLIz4khgCbWfD5nQuox3ZYQ2MUo8ckbTVV O8I2ZNAWD2AlUQDaAyi+cwf12U6Jv/s6oKfo5vRlKRBGIcA901qKD2L3sb7Vq06a3xMC +tDS6RiS5M5p8YpV3kMAkp0mQfFQ4M45DlGz8YOzd1Td6e+p2daHXCIG3OrPP8RPJHV7 Qw2pajeGvBrrML5HOF9UWLbcg64/GHpmRGTtWbLfE5UlKeRNAw5a7K4dil/NnogT36t7 U/tQ/WWx2JQ58pNd/99QccFtJPqsGl/qkEsQ/Dcy14HyLRebPMzcWCstK8tNSAXy7DtL uCTA== X-Gm-Message-State: AOAM530TiKhEq6kvMbHzO6EaoaY6xk/PweWN+4/ww0rxKw/Dn8YAIvSN RvFpzBexThjdmDeYPQWE6afx3fuCby4lYw== X-Google-Smtp-Source: ABdhPJwNPwqBU/dG7BIaGIoPMIlaXPpy51wHOQNCXSPGQ9IyK+YyQ/i9JpmqRDzCOz/TB3zfGMCuYQ== X-Received: by 2002:a2e:2e14:: with SMTP id u20mr3564651lju.12.1624533313716; Thu, 24 Jun 2021 04:15:13 -0700 (PDT) Received: from carbon.v ([94.143.149.146]) by smtp.googlemail.com with ESMTPSA id q21sm195293lfp.233.2021.06.24.04.15.12 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 24 Jun 2021 04:15:13 -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 v6 6/9] fs: make do_linkat() take struct filename Date: Thu, 24 Jun 2021 18:14:49 +0700 Message-Id: <20210624111452.658342-7-dkadashev@gmail.com> X-Mailer: git-send-email 2.30.2 In-Reply-To: <20210624111452.658342-1-dkadashev@gmail.com> References: <20210624111452.658342-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 Acked-by: Christian Brauner --- 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 24 11:14:50 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Dmitry Kadashev X-Patchwork-Id: 12341879 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-15.7 required=3.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,FREEMAIL_FORGED_FROMDOMAIN,FREEMAIL_FROM, HEADER_FROM_DIFFERENT_DOMAINS,INCLUDES_CR_TRAILER,INCLUDES_PATCH, MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS,URIBL_BLOCKED,USER_AGENT_GIT autolearn=unavailable autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 94DCDC48BDF for ; Thu, 24 Jun 2021 11:15:24 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 7E888611CE for ; Thu, 24 Jun 2021 11:15:24 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S232430AbhFXLRj (ORCPT ); Thu, 24 Jun 2021 07:17:39 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:56268 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S232440AbhFXLRf (ORCPT ); Thu, 24 Jun 2021 07:17:35 -0400 Received: from mail-lj1-x233.google.com (mail-lj1-x233.google.com [IPv6:2a00:1450:4864:20::233]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 9A4C8C061760; Thu, 24 Jun 2021 04:15:16 -0700 (PDT) Received: by mail-lj1-x233.google.com with SMTP id c16so7207885ljh.0; Thu, 24 Jun 2021 04:15:16 -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=+1IHeLQmFnCkiRM6Le09tuowGzlsNL/9ZhUl0moeekU=; b=UlNba2a9ma6y+J9Kv2fW/386Zp2+Gmujt/QJjDt9x7Md8rM+MPfa5JX64hmwGStLSk u/MzuKc08ZtS9cUTm/JrEAPfu8w5+6/C2iQkRDQj8WsJ2tkZZIBvgwHvpf6iXuGdrUh1 YObJ/5bYyc9b8U/cFoAPEJ22IEWaZ2Y9z5+iTVib3xq1GpUMAQppY61VLoEkeDAqUxpK 6+Gq2FtZH1rK9DWP6xEXQtkbCLKwAmF1BlYQzxwj63Qtw4uheKvgulpUz2jWqGPktOmR AV49/M9S/pE76rmy7UeDXbNR19Tj/AoLq/OQQQuTbExleEBCL/d+zCF1oZ89tHwIO58h w+DQ== 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=+1IHeLQmFnCkiRM6Le09tuowGzlsNL/9ZhUl0moeekU=; b=lYsura1I6g1lcwC1fBPzIFAUfl4UWSzeupZk/+CBvc9PsJ0r+n8m05BC2D8BkrIt51 taDUm4rEcVk7ShdIaIwjZOmwscbUmtXs7WmXc2UkZbapIfuZMmvLbmcN+1SNrdenWX5/ Zw2/rZ7zN/aDzs/oD4aZNq+qLcbymS5i8bAmBAeua1UZOr6PI0J/SDaxwHjbE6GOIB00 GU6yeM4Vuqc5PFGHtr/LAdRaJ/F9Mu9ZkRFYl2FowDxEgDDOALz5D2XTIVhnesiF9iv5 xevvsl1dsV7MutZZvCrkU7WPKQgEDZ0ro6I4KAMU1k6R6kl/5CHhScaIOA9m29GBCtXq LtVg== X-Gm-Message-State: AOAM533UuyhTBkM6bCwYr9COq0M2ZqI4I2P43aNPk+5p5LaT0AOeA6/i 6Lv373RQTaWHK7s84yo8Ju4= X-Google-Smtp-Source: ABdhPJyvD95YLFujaf0giD5sCvYw0iC3O8AgnlO47bGiKY0X1tFfaJTW+1dg9jKkzkPtn51SifEAQg== X-Received: by 2002:a2e:8750:: with SMTP id q16mr3481727ljj.92.1624533314962; Thu, 24 Jun 2021 04:15:14 -0700 (PDT) Received: from carbon.v ([94.143.149.146]) by smtp.googlemail.com with ESMTPSA id q21sm195293lfp.233.2021.06.24.04.15.13 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 24 Jun 2021 04:15:14 -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 v6 7/9] fs: update do_*() helpers to return ints Date: Thu, 24 Jun 2021 18:14:50 +0700 Message-Id: <20210624111452.658342-8-dkadashev@gmail.com> X-Mailer: git-send-email 2.30.2 In-Reply-To: <20210624111452.658342-1-dkadashev@gmail.com> References: <20210624111452.658342-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 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 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 24 11:14:51 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Dmitry Kadashev X-Patchwork-Id: 12341883 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-15.7 required=3.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,FREEMAIL_FORGED_FROMDOMAIN,FREEMAIL_FROM, HEADER_FROM_DIFFERENT_DOMAINS,INCLUDES_CR_TRAILER,INCLUDES_PATCH, MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS,URIBL_BLOCKED,USER_AGENT_GIT autolearn=unavailable autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 7E97FC49EA6 for ; Thu, 24 Jun 2021 11:15:32 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 6C6EE600CC for ; Thu, 24 Jun 2021 11:15:32 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S232480AbhFXLRs (ORCPT ); Thu, 24 Jun 2021 07:17:48 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:56284 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S232118AbhFXLRh (ORCPT ); Thu, 24 Jun 2021 07:17:37 -0400 Received: from mail-lf1-x134.google.com (mail-lf1-x134.google.com [IPv6:2a00:1450:4864:20::134]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id CF3CCC061760; Thu, 24 Jun 2021 04:15:17 -0700 (PDT) Received: by mail-lf1-x134.google.com with SMTP id d16so9615520lfn.3; Thu, 24 Jun 2021 04:15: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=1KNgQk+iy7YsDX0I+gkA6jbhtLveDWzi1UxDTxURyJk=; b=jdfioBcgTHWXEO34cbrzxBSwx/uq69rpDwGTYds0zIvMEreYVYr26XLYxxObVn+m2D JoSoNEnLdME5kxZQryZSdBWVSsy1bgt8KscMfhBO+J2BqE66Wt2vbxla5QkZpQwZe5jy 94ndCxbe78KoxFi8J3y+/QEVayf6ML2IvdI7Q43gG9Es0jxjEU4DT8nke8yRzgjIMMQV WJDX0LpEgYH6voknaS5RCohlOR1daCiHatBbAV/xL3CrZn6ZmSUUZ9q4/OdyfbLbaJng XkxgQuyxGG9XN77JvU6cLERH28c+GUhIu3TqJT1cCNC/EZOj1bSAYV8qebtDkwnDqSb1 SAug== 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=1KNgQk+iy7YsDX0I+gkA6jbhtLveDWzi1UxDTxURyJk=; b=uZ7Eya+UAmGk4EvdihLqJEWhymKcqW2+EKu5OCvQfTV/uLbz7xmIbXBEr486PO510X vO3P7PnsYEMgLvJGa+PyKsYIRHCgVWyxAn4ftIjSx0pEz8QXEa09YyY8wecjjsAyneDV OwZmYIf/Jw2a67oZBh+K/OA6SZc4eW31/p2YIZOOj0o6kthE7hgHndGGch/nYhXXbGJx KxVFMlG/LJ5g4sfv7q5VgPArvsVfVVPJRPhtIM8MN6YjnJ9KWW7YYgHFTTo85GokOPFk DWt1/MTCfm4VXOpkncQeL5+mpQWYqNs0dPmmfAsE357hp3ulLru/urU1BvMmXGwf5wsw wcHA== X-Gm-Message-State: AOAM530ga4t3jq6zkK92k2m5naLCJtM72mF7PVi2PJ18/TBEzwFdQGUQ ls6blQNLUtLKTQTUbYiCwiA= X-Google-Smtp-Source: ABdhPJzoHHxmv8xlFm8HD+l7/ea9//h0iSu2MS2le9wSnDhNaDaVYkGSEf0x7hWk6jBLqzruFi8wNw== X-Received: by 2002:ac2:4db0:: with SMTP id h16mr3517610lfe.579.1624533316229; Thu, 24 Jun 2021 04:15:16 -0700 (PDT) Received: from carbon.v ([94.143.149.146]) by smtp.googlemail.com with ESMTPSA id q21sm195293lfp.233.2021.06.24.04.15.15 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 24 Jun 2021 04:15:15 -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 v6 8/9] io_uring: add support for IORING_OP_SYMLINKAT Date: Thu, 24 Jun 2021 18:14:51 +0700 Message-Id: <20210624111452.658342-9-dkadashev@gmail.com> X-Mailer: git-send-email 2.30.2 In-Reply-To: <20210624111452.658342-1-dkadashev@gmail.com> References: <20210624111452.658342-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 Acked-by: Christian Brauner Reviewed-by: Pavel Begunkov --- 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 7aa08ed78452..c161f06a3cea 100644 --- a/fs/io_uring.c +++ b/fs/io_uring.c @@ -680,6 +680,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; @@ -833,6 +840,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; }; @@ -1048,6 +1056,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); @@ -3599,6 +3608,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) { @@ -6009,6 +6066,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", @@ -6173,6 +6232,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) { @@ -6304,6 +6367,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 49a24a149eeb..796f37ab4ce3 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 24 11:14:52 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Dmitry Kadashev X-Patchwork-Id: 12341881 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-15.7 required=3.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,FREEMAIL_FORGED_FROMDOMAIN,FREEMAIL_FROM, HEADER_FROM_DIFFERENT_DOMAINS,INCLUDES_CR_TRAILER,INCLUDES_PATCH, MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS,URIBL_BLOCKED,USER_AGENT_GIT autolearn=unavailable autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 691ABC49EAF for ; Thu, 24 Jun 2021 11:15:30 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 55E67600CC for ; Thu, 24 Jun 2021 11:15:30 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S232453AbhFXLRr (ORCPT ); Thu, 24 Jun 2021 07:17:47 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:56292 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S232452AbhFXLRj (ORCPT ); Thu, 24 Jun 2021 07:17:39 -0400 Received: from mail-lj1-x22f.google.com (mail-lj1-x22f.google.com [IPv6:2a00:1450:4864:20::22f]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 490F5C061766; Thu, 24 Jun 2021 04:15:19 -0700 (PDT) Received: by mail-lj1-x22f.google.com with SMTP id u2so1954361ljo.1; Thu, 24 Jun 2021 04:15:19 -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=4vN1HPJGM7EHfZQb4+fkMPYAbTfsiTYN23x5DHBLnOA=; b=bMX3s/hKznI0lDavNEMmFSz7rPNjyCWuN5ETD38T9VqtIx4PH/zwieiANp9XVY0cXD eNDKIPWNm88Sha53CqnDdtn+MmoT74zFFZ7PjMMGBICwQbLEgl1Pykm3voypN8r5+GUr ve26PcTS28NWyAdycXSomf2riTvEHPPE5pD9LVuc+nNf4tGqokllkrgQtVUqWa2aQt0W gb99+JqUxsNXdAsKlZfmilEwA++OFVPHYlnB1rFeuLQ52X1YCSkDDqe4cz859GNKA3BA 6IAtRhOlASjFzKNCPEgfvQTol9hwmfXtE5m6CQ1Iz/sox+oZ4eIHTnP/FWtQoj//fxZd fVyw== 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=4vN1HPJGM7EHfZQb4+fkMPYAbTfsiTYN23x5DHBLnOA=; b=fg+zOxZX6NfdsJtAFBpP3eykhdSyJSmHd7AbmAq+zXW3CN9Pwdt0BmQ6aYfyurNUzC wm9SUpO3mxlo7NcHAKkr/kbojKEg4V1nrV+oC5dmGukg6Onk5W0YOtxiwyvQiKEK0BFM V6ZFRzKobuQQKpHqjRoj16W3UmzNg7vHfGQeGt24bCignoWqY76H9WG4Mm7hXXo0ohtw oQ7yAXExgVSBX4tfWlptsWVGEl7WGkuYnENYvyXa874O20gxRwzckX+53u18p3kZF44X Gvg1+TrIODx4yRWI0Qo4McB59Waai9Drmc0F8gm7ivUr+9b1bpTwJEV69YAizWssojmF SpFA== X-Gm-Message-State: AOAM531N/cVebpwL0fQLW6XnQWlrQYS5UzdmD8SsWLNIJr18VLRz7k93 UDqsHvuKaegMApAI/CnbZeU= X-Google-Smtp-Source: ABdhPJwU6Kc7FlPT+RzZGMGsoUK2k3f8uwG+CzgTIjEL5eAhIwMyu2+lyHx29HJILTXVLgERfNnqbw== X-Received: by 2002:a05:651c:546:: with SMTP id q6mr3472438ljp.73.1624533317668; Thu, 24 Jun 2021 04:15:17 -0700 (PDT) Received: from carbon.v ([94.143.149.146]) by smtp.googlemail.com with ESMTPSA id q21sm195293lfp.233.2021.06.24.04.15.16 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 24 Jun 2021 04:15:17 -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 v6 9/9] io_uring: add support for IORING_OP_LINKAT Date: Thu, 24 Jun 2021 18:14:52 +0700 Message-Id: <20210624111452.658342-10-dkadashev@gmail.com> X-Mailer: git-send-email 2.30.2 In-Reply-To: <20210624111452.658342-1-dkadashev@gmail.com> References: <20210624111452.658342-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 Acked-by: Christian Brauner Reviewed-by: Pavel Begunkov --- 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 c161f06a3cea..14a90e4e4149 100644 --- a/fs/io_uring.c +++ b/fs/io_uring.c @@ -687,6 +687,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; @@ -841,6 +850,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; }; @@ -1057,6 +1067,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); @@ -3656,6 +3667,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) { @@ -6068,6 +6130,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", @@ -6236,6 +6300,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) { @@ -6370,6 +6438,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 796f37ab4ce3..c735fc22e459 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,