From patchwork Tue Jan 31 17:31:45 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Aleksandr Mikhalitsyn X-Patchwork-Id: 1734979 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@legolas.ozlabs.org Authentication-Results: legolas.ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=lists.ubuntu.com (client-ip=91.189.94.19; helo=huckleberry.canonical.com; envelope-from=kernel-team-bounces@lists.ubuntu.com; receiver=) Authentication-Results: legolas.ozlabs.org; dkim=fail reason="signature verification failed" (2048-bit key; unprotected) header.d=canonical.com header.i=@canonical.com header.a=rsa-sha256 header.s=20210705 header.b=iFvpnY6u; dkim-atps=neutral Received: from huckleberry.canonical.com (huckleberry.canonical.com [91.189.94.19]) (using TLSv1.2 with cipher ECDHE-ECDSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by legolas.ozlabs.org (Postfix) with ESMTPS id 4P5sYm5SvPz23jC for ; Wed, 1 Feb 2023 04:32:11 +1100 (AEDT) Received: from localhost ([127.0.0.1] helo=huckleberry.canonical.com) by huckleberry.canonical.com with esmtp (Exim 4.86_2) (envelope-from ) id 1pMuUA-00055S-Gk; Tue, 31 Jan 2023 17:31:58 +0000 Received: from smtp-relay-internal-1.internal ([10.131.114.114] helo=smtp-relay-internal-1.canonical.com) by huckleberry.canonical.com with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.86_2) (envelope-from ) id 1pMuU8-00055F-8L for kernel-team@lists.ubuntu.com; Tue, 31 Jan 2023 17:31:56 +0000 Received: from mail-ej1-f70.google.com (mail-ej1-f70.google.com [209.85.218.70]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits) server-digest SHA256) (No client certificate requested) by smtp-relay-internal-1.canonical.com (Postfix) with ESMTPS id E44D341AC7 for ; Tue, 31 Jan 2023 17:31:55 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=canonical.com; s=20210705; t=1675186315; bh=6SwGyTQNVR44ZL5gSiJ2gRx4nklyCwZnoSnyGE9f3Mo=; h=From:To:Subject:Date:Message-Id:MIME-Version; b=iFvpnY6ueqpMxc4p7GGZLiDPjLc8gBuFIjIY3vUt1Ow5Sr6KzKC0FAiWtSD2wc8pR atC4NO+FttXWIGntT8Ly9TFJl8Qyk1W8lFMpwIm//B2H7u/Ss15UctQlKlYqD2rbfh 85PHaPm5eCAzMDojb0ikrtgb83poP9kAhh4BfqCIQnlK+eD8TcF/0/wb+vUYAy9k2h Fb+OP09VFQZSEi/kksi6W8UooTeMBSIrKIeliEnwUeksF4DI6tanLlulcvM4c/HEY/ FDkVws2E+Xn5M9v/NJrzVN0RV+csPHH2zuo/a7WB4Oi8lFbdYTHdBnKt4zvg9vb1cI Xquhvfw6sxliQ== Received: by mail-ej1-f70.google.com with SMTP id du14-20020a17090772ce00b0087108bbcfa6so10164627ejc.7 for ; Tue, 31 Jan 2023 09:31:55 -0800 (PST) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=content-transfer-encoding:mime-version:message-id:date:subject:to :from:x-gm-message-state:from:to:cc:subject:date:message-id:reply-to; bh=6SwGyTQNVR44ZL5gSiJ2gRx4nklyCwZnoSnyGE9f3Mo=; b=A+jCXn6txufMSDaUi/FSI0PIz688vgBcU76sGG1bf43ayctfjb+4hAPs2KCuFK9HJF jEbX4U/KYVtvrViD4KYJqbeOK/jNiiJRPsv5MOpHIyX369RpXC3w8SWNiQAFkVmix4tZ ofj34INnsPZXMqK7BOcL5Et4y/HBLiuQ6Q06GBnKfXQDbu5IzWBiqXtIS+fp1uUACY48 qPzVbUQrmYyCRBamikz4DSAgGCwho2hwhCz+t2UJg9Xcm6q3l9ebMbfsqYS0MitJAa8w 95fA0RoqcAh1yPFciSafMrRad2vmjUfOvFUtTwD0OCyMllp7rsH+pGZBCb9vwNDLHxkZ i8iA== X-Gm-Message-State: AO0yUKUnBE9Vj2nzGfeht3uOuEO2fWpU6rArZeeQ6gt0jIt8paPgnBLj HAn6+GFYEpxTAN9q2psXHIaqCy0UB/iEaW0xAePYRoCbzypR8CX/f5U67m883ZHZu127Dkjhi4M cwfRyl0vXrKSTiTeP9Y/puvvoh0E7rlxEQHsE/rtPow== X-Received: by 2002:a17:906:c002:b0:887:5f45:d688 with SMTP id e2-20020a170906c00200b008875f45d688mr10063620ejz.41.1675186315324; Tue, 31 Jan 2023 09:31:55 -0800 (PST) X-Google-Smtp-Source: AK7set82nsKCnfUYUkL79r4XqSne/cEu3Uv7sLM4eTplW2oYMcJObBDD5NoC2ilzpGuW7h9DHWV1AQ== X-Received: by 2002:a17:906:c002:b0:887:5f45:d688 with SMTP id e2-20020a170906c00200b008875f45d688mr10063608ejz.41.1675186315070; Tue, 31 Jan 2023 09:31:55 -0800 (PST) Received: from amikhalitsyn.. (ip5f5bf399.dynamic.kabel-deutschland.de. [95.91.243.153]) by smtp.gmail.com with ESMTPSA id qu21-20020a170907111500b00884c611145fsm5056182ejb.62.2023.01.31.09.31.54 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 31 Jan 2023 09:31:54 -0800 (PST) From: Alexander Mikhalitsyn To: kernel-team@lists.ubuntu.com Subject: [SRU][J][PATCH 1/2] UBUNTU: SAUCE: shiftfs: always rely on init_user_ns Date: Tue, 31 Jan 2023 18:31:45 +0100 Message-Id: <20230131173146.552420-1-aleksandr.mikhalitsyn@canonical.com> X-Mailer: git-send-email 2.34.1 MIME-Version: 1.0 X-BeenThere: kernel-team@lists.ubuntu.com X-Mailman-Version: 2.1.20 Precedence: list List-Id: Kernel team discussions List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: kernel-team-bounces@lists.ubuntu.com Sender: "kernel-team" From: Andrea Righi With the porting of shiftfs from 5.15 to 5.17 some filesystem-related functions are now passing struct user_namespace as argument, however shiftfs logic is still relying on the fact that these functions need to use the main filesystem namespace. Make sure to always use init_user_ns to prevent breakage of system components that rely on shiftfs. Without this fix lxd was showing some issues, like failing to create any file inside a container when shiftfs was used (e.g., using zfs as storage pool). Signed-off-by: Andrea Righi --- fs/shiftfs.c | 50 ++++++++++++++++++++++++-------------------------- 1 file changed, 24 insertions(+), 26 deletions(-) diff --git a/fs/shiftfs.c b/fs/shiftfs.c index 76c54bc12018..a21624c529f0 100644 --- a/fs/shiftfs.c +++ b/fs/shiftfs.c @@ -308,8 +308,7 @@ static const char *shiftfs_get_link(struct dentry *dentry, struct inode *inode, return p; } -static int shiftfs_setxattr(struct user_namespace *ns, - struct dentry *dentry, struct inode *inode, +static int shiftfs_setxattr(struct dentry *dentry, struct inode *inode, const char *name, const void *value, size_t size, int flags) { @@ -318,7 +317,7 @@ static int shiftfs_setxattr(struct user_namespace *ns, const struct cred *oldcred; oldcred = shiftfs_override_creds(dentry->d_sb); - err = vfs_setxattr(ns, lowerd, name, value, size, flags); + err = vfs_setxattr(&init_user_ns, lowerd, name, value, size, flags); revert_creds(oldcred); shiftfs_copyattr(lowerd->d_inode, inode); @@ -363,7 +362,7 @@ static int shiftfs_removexattr(struct user_namespace *ns, const struct cred *oldcred; oldcred = shiftfs_override_creds(dentry->d_sb); - err = vfs_removexattr(ns, lowerd, name); + err = vfs_removexattr(&init_user_ns, lowerd, name); revert_creds(oldcred); /* update c/mtime */ @@ -379,8 +378,8 @@ static int shiftfs_xattr_set(const struct xattr_handler *handler, int flags) { if (!value) - return shiftfs_removexattr(ns, dentry, name); - return shiftfs_setxattr(ns, dentry, inode, name, value, size, flags); + return shiftfs_removexattr(&init_user_ns, dentry, name); + return shiftfs_setxattr(dentry, inode, name, value, size, flags); } static int shiftfs_inode_test(struct inode *inode, void *data) @@ -394,8 +393,7 @@ static int shiftfs_inode_set(struct inode *inode, void *data) return 0; } -static int shiftfs_create_object(struct user_namespace *ns, - struct inode *diri, struct dentry *dentry, +static int shiftfs_create_object(struct inode *diri, struct dentry *dentry, umode_t mode, const char *symlink, struct dentry *hardlink, bool excl) { @@ -457,7 +455,7 @@ static int shiftfs_create_object(struct user_namespace *ns, inode->i_state |= I_CREATING; spin_unlock(&inode->i_lock); - inode_init_owner(ns, inode, diri, mode); + inode_init_owner(&init_user_ns, inode, diri, mode); modei = inode->i_mode; } @@ -468,22 +466,22 @@ static int shiftfs_create_object(struct user_namespace *ns, if (hardlink) { lowerd_link = hardlink->d_fsdata; - err = vfs_link(lowerd_link, ns, loweri_dir, lowerd_new, NULL); + err = vfs_link(lowerd_link, &init_user_ns, loweri_dir, lowerd_new, NULL); } else { switch (modei & S_IFMT) { case S_IFDIR: - err = vfs_mkdir(ns, loweri_dir, lowerd_new, modei); + err = vfs_mkdir(&init_user_ns, loweri_dir, lowerd_new, modei); break; case S_IFREG: - err = vfs_create(ns, loweri_dir, lowerd_new, modei, excl); + err = vfs_create(&init_user_ns, loweri_dir, lowerd_new, modei, excl); break; case S_IFLNK: - err = vfs_symlink(ns, loweri_dir, lowerd_new, symlink); + err = vfs_symlink(&init_user_ns, loweri_dir, lowerd_new, symlink); break; case S_IFSOCK: /* fall through */ case S_IFIFO: - err = vfs_mknod(ns, loweri_dir, lowerd_new, modei, 0); + err = vfs_mknod(&init_user_ns, loweri_dir, lowerd_new, modei, 0); break; default: err = -EINVAL; @@ -545,7 +543,7 @@ static int shiftfs_create(struct user_namespace *ns, { mode |= S_IFREG; - return shiftfs_create_object(ns, dir, dentry, mode, NULL, NULL, excl); + return shiftfs_create_object(dir, dentry, mode, NULL, NULL, excl); } static int shiftfs_mkdir(struct user_namespace *ns, struct inode *dir, struct dentry *dentry, @@ -553,13 +551,13 @@ static int shiftfs_mkdir(struct user_namespace *ns, struct inode *dir, struct de { mode |= S_IFDIR; - return shiftfs_create_object(ns, dir, dentry, mode, NULL, NULL, false); + return shiftfs_create_object(dir, dentry, mode, NULL, NULL, false); } static int shiftfs_link(struct dentry *hardlink, struct inode *dir, struct dentry *dentry) { - return shiftfs_create_object(&init_user_ns, dir, dentry, 0, NULL, hardlink, false); + return shiftfs_create_object(dir, dentry, 0, NULL, hardlink, false); } static int shiftfs_mknod(struct user_namespace *ns, @@ -569,13 +567,13 @@ static int shiftfs_mknod(struct user_namespace *ns, if (!S_ISFIFO(mode) && !S_ISSOCK(mode)) return -EPERM; - return shiftfs_create_object(ns, dir, dentry, mode, NULL, NULL, false); + return shiftfs_create_object(dir, dentry, mode, NULL, NULL, false); } static int shiftfs_symlink(struct user_namespace *ns, struct inode *dir, struct dentry *dentry, const char *symlink) { - return shiftfs_create_object(ns, dir, dentry, S_IFLNK, symlink, NULL, false); + return shiftfs_create_object(dir, dentry, S_IFLNK, symlink, NULL, false); } static int shiftfs_rm(struct inode *dir, struct dentry *dentry, bool rmdir) @@ -716,12 +714,12 @@ static int shiftfs_permission(struct user_namespace *ns, struct inode *inode, in return -ECHILD; } - err = generic_permission(ns, inode, mask); + err = generic_permission(&init_user_ns, inode, mask); if (err) return err; oldcred = shiftfs_override_creds(inode->i_sb); - err = inode_permission(ns, loweri, mask); + err = inode_permission(&init_user_ns, loweri, mask); revert_creds(oldcred); return err; @@ -760,7 +758,7 @@ static int shiftfs_tmpfile(struct user_namespace *ns, return -EOPNOTSUPP; oldcred = shiftfs_override_creds(dir->i_sb); - err = loweri->i_op->tmpfile(ns, loweri, lowerd, mode); + err = loweri->i_op->tmpfile(&init_user_ns, loweri, lowerd, mode); revert_creds(oldcred); return err; @@ -776,7 +774,7 @@ static int shiftfs_setattr(struct user_namespace *ns, struct dentry *dentry, str struct shiftfs_super_info *sbinfo = sb->s_fs_info; int err; - err = setattr_prepare(ns, dentry, attr); + err = setattr_prepare(&init_user_ns, dentry, attr); if (err) return err; @@ -793,7 +791,7 @@ static int shiftfs_setattr(struct user_namespace *ns, struct dentry *dentry, str inode_lock(loweri); oldcred = shiftfs_override_creds(dentry->d_sb); - err = notify_change(ns, lowerd, &newattr, NULL); + err = notify_change(&init_user_ns, lowerd, &newattr, NULL); revert_creds(oldcred); inode_unlock(loweri); @@ -980,10 +978,10 @@ shiftfs_posix_acl_xattr_set(const struct xattr_handler *handler, shift_acl_xattr_ids(inode->i_sb->s_user_ns, loweri->i_sb->s_user_ns, (void *)value, size); - err = shiftfs_setxattr(ns, dentry, inode, handler->name, value, + err = shiftfs_setxattr(dentry, inode, handler->name, value, size, flags); } else { - err = shiftfs_removexattr(ns, dentry, handler->name); + err = shiftfs_removexattr(&init_user_ns, dentry, handler->name); } if (!err)