From mboxrd@z Thu Jan 1 00:00:00 1970 Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.remote-ip=100.103.45.18 ARC-Seal: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; cv=none; t=1793803031; b=j1UoMkvPy4qI7mxmqBCv3u091kW45YkxV24bCCqMW+asMwYs4q0VvD6cT16wkuVVAPak M75w9C51Ukjs+hI1IVHWaHW2vj7lDgpXkQN6zIVuQtwla6b2GGNGkgBXn8J3cTA7isEEV BaKHP68r1lDc4fP9nm4WZ4y1J/5WDlsbjZ+qGM+zzWVEWt5xINp1/0OAHjQkkB0iWpVS+ 9QKMpYiXuw270UUvYvOnb7NmYKAfYykRPYjxQJdADutVc5Jq1AltFjysbU9GCnG6Y92V6 1s+NsBq1FXRHvA8792KcllUETWNyLrKj61uXClBSSPepVMTc3okKe55okVgQPuaH+Gg== ARC-Message-Signature: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; c=relaxed/relaxed; t=1793803031; h=Received:DKIM-Signature:Subject:To:Cc:From:Date:Message-ID: MIME-Version:Content-Type:Content-Transfer-Encoding; bh=cjzs8QJ3XSbLJU0qUYhSPnKkvfsAveBYyIOQnnHsAE0=; b=VhkltP66x7b2NVxjfwndcU4DTX7Nq57IRVFEpUixv3r25+wJMlq5jXM/pVK4ajVwHvCP HyE/dV/IHwvdh7rTB+fbc7dY0C67juxU6A02FB+G+hMYpx0yOqoaxfIWk/mDBRtAywnEu BUbs6meDckusO3dkeqGysSc80Deuy4zDiQqZmgeXTAG/bfcTitD3hK6zJAN/sljX/j2n0 +4T8D/HIIAdTKK4Fa/NWoIDJOI/A0tXUvqhswkN+ZchQKAoNIVrV++o+Jmb1Uk4aO5cen T7YjJAeseuA3+5ygKfHsa9F8N7xcyTL3mWW54rmKO4KepWOdfJi61l50In/4KGSVdKg== ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass header.d=linuxfoundation.org header.i=@linuxfoundation.org header.a=rsa-sha256 header.s=korg header.b=rvxJI+FW; arc=none smtp.remote-ip=100.103.45.18 Received: from smtp.kernel.org (quasi.space.kernel.org [100.103.45.18]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (prime256v1)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 4C465606A326 for ; Wed, 4 Nov 2026 14:37:11 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key, unprotected) header.d=linuxfoundation.org header.i=@linuxfoundation.org header.a=rsa-sha256 header.s=korg header.b=rvxJI+FW Received: by smtp.kernel.org (Postfix) with ESMTPSA id AC3A01F000C1; Wed, 4 Nov 2026 14:37:10 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linuxfoundation.org; s=korg; t=1793803030; bh=cjzs8QJ3XSbLJU0qUYhSPnKkvfsAveBYyIOQnnHsAE0=; h=Subject:To:Cc:From:Date; b=rvxJI+FWRc0ycaThGaUCaL9oGUXRQDmtJAEZOyBEN1udHRX3fGjqgHAd+niG6Yy8b L4/2UxSex9xT2OJ1gIOjIdyL4CPZOGKfgU7fzpjBaFvesQh3Njh4cOft3N6Q1mGDda wSPGDNw9SQtuXcDnwDJGHeVl/7x3XLMDJzi2FGPY= Subject: FAILED: patch "[PATCH] ovl: fortify ovl_copy_xattr() against underlying layer" failed to apply to 5.10-stable tree To: amir73il@gmail.com,fahad@codepure.com,miklos@szeredi.hu Cc: From: Date: Wed, 04 Nov 2026 15:37:01 +0100 Message-ID: <2026110401-darwinism-protract-00ef@gregkh> X-Mailing-List: stable@vger.kernel.org List-Id: List-Post: List-Help: List-Subscribe: List-Unsubscribe: List-Owner: Precedence: list MIME-Version: 1.0 Content-Type: text/plain; charset=ANSI_X3.4-1968 Content-Transfer-Encoding: 8bit The patch below does not apply to the 5.10-stable tree. If someone wants it applied there, or to any other stable or longterm tree, then please email the backport, including the original git commit id to . To reproduce the conflict and resubmit, you may use the following commands: git fetch https://git.kernel.org/pub/scm/linux/kernel/git/stable/linux.git/ linux-5.10.y git checkout FETCH_HEAD git cherry-pick -x e6b9117076fb4c0ff4a670efa9c876d9a50d79ab # git commit -s git send-email --to '' --in-reply-to '2026110401-darwinism-protract-00ef@gregkh' --subject-prefix 'PATCH 5.10.y' 'HEAD^..' Possible dependencies: thanks, greg k-h ------------------ original commit in Linus's tree ------------------ >From e6b9117076fb4c0ff4a670efa9c876d9a50d79ab Mon Sep 17 00:00:00 2001 From: Amir Goldstein Date: Fri, 16 Oct 2026 09:33:58 +0200 Subject: [PATCH] ovl: fortify ovl_copy_xattr() against underlying layer modifications Adapt ovl_getxattr_value() to be used from ovl_copy_xattr(), by allowing to pass it a pre-allocated buffer, which can be resized and by handling the ENODATA/EOPNOTSUPP return codes in the caller. This replaces the retry loop in ovl_copy_xattr() with a single retry after resizing the buffer. If the value changed again by then, the underlying layer was modified, so return -EIO instead of retrying. As a side effect, ovl_copy_up_meta_inode_data() now returns -EIO instead of -ERANGE in this case of underlying xattr size changes. Reported-by: Fahad Alharbi Tested-by: Fahad Alharbi Suggested-by: Miklos Szeredi Link: https://lore.kernel.org/linux-fsdevel/CAJfpegsVoUyqy0dYkTvBGRZvgdv_nmzmCw_uF+LP-Vq3EhEkSg@mail.gmail.com/ Fixes: e4ad29fa0d22 ("ovl: use a minimal buffer in ovl_copy_xattr") Cc: stable@vger.kernel.org Signed-off-by: Amir Goldstein diff --git a/fs/overlayfs/copy_up.c b/fs/overlayfs/copy_up.c index c220cb5d0b70..eee22581b14f 100644 --- a/fs/overlayfs/copy_up.c +++ b/fs/overlayfs/copy_up.c @@ -72,6 +72,9 @@ static int ovl_copy_acl(struct ovl_fs *ofs, const struct path *path, return err; } +static ssize_t ovl_getxattr_value(const struct path *path, char *name, + char **value, ssize_t *value_size); + int ovl_copy_xattr(struct super_block *sb, const struct path *oldpath, struct dentry *new) { struct dentry *old = oldpath->dentry; @@ -129,34 +132,12 @@ int ovl_copy_xattr(struct super_block *sb, const struct path *oldpath, struct de break; } -retry: - size = ovl_do_getxattr(oldpath, name, value, value_size); - if (size == -ERANGE) { - size = ovl_do_getxattr(oldpath, name, NULL, 0); - /* Nothing was read into value, so it must not be used */ - if (size >= 0 && size <= value_size) - size = -EIO; - } - + size = ovl_getxattr_value(oldpath, name, &value, &value_size); if (size < 0) { error = size; break; } - if (size > value_size) { - void *new; - - new = kvmalloc(size, GFP_KERNEL); - if (!new) { - error = -ENOMEM; - break; - } - kvfree(value); - value = new; - value_size = size; - goto retry; - } - error = ovl_do_setxattr(OVL_FS(sb), new, name, value, size, 0); if (error) { if (error != -EOPNOTSUPP || ovl_must_copy_xattr(name)) @@ -1059,26 +1040,39 @@ static bool ovl_need_meta_copy_up(struct dentry *dentry, umode_t mode, return true; } -static ssize_t ovl_getxattr_value(const struct path *path, char *name, char **value) +static ssize_t ovl_getxattr_value(const struct path *path, char *name, + char **value, ssize_t *value_size) { ssize_t res; char *buf; - res = ovl_do_getxattr(path, name, NULL, 0); - if (res == -ENODATA || res == -EOPNOTSUPP) - res = 0; + res = ovl_do_getxattr(path, name, *value, *value_size); + if (res == -ERANGE) { + res = ovl_do_getxattr(path, name, NULL, 0); + /* Xattr changed underneath us? */ + if (res >= 0 && res <= *value_size) + return -EIO; + } - if (res > 0) { - buf = kzalloc(res, GFP_KERNEL); + if (res > *value_size) { + buf = kvmalloc(res, GFP_KERNEL); if (!buf) return -ENOMEM; res = ovl_do_getxattr(path, name, buf, res); - if (res < 0) - kfree(buf); - else - *value = buf; + if (res < 0) { + kvfree(buf); + /* Xattr changed underneath us? */ + if (res == -ERANGE) + return -EIO; + return res; + } + + kvfree(*value); + *value = buf; + *value_size = res; } + return res; } @@ -1089,7 +1083,7 @@ static int ovl_copy_up_meta_inode_data(struct ovl_copy_up_ctx *c) struct path upperpath; int err; char *capability = NULL; - ssize_t cap_size; + ssize_t cap_size = 0; ovl_path_upper(c->dentry, &upperpath); if (WARN_ON(upperpath.dentry == NULL)) @@ -1097,7 +1091,9 @@ static int ovl_copy_up_meta_inode_data(struct ovl_copy_up_ctx *c) if (c->stat.size) { err = cap_size = ovl_getxattr_value(&upperpath, XATTR_NAME_CAPS, - &capability); + &capability, &cap_size); + if (cap_size == -ENODATA || cap_size == -EOPNOTSUPP) + cap_size = 0; if (cap_size < 0) goto out; } @@ -1127,7 +1123,7 @@ static int ovl_copy_up_meta_inode_data(struct ovl_copy_up_ctx *c) ovl_clear_flag(OVL_VERIFIED_DIGEST, d_inode(c->dentry)); ovl_set_upperdata(d_inode(c->dentry)); out_free: - kfree(capability); + kvfree(capability); out: return err; }