Received: by 2002:ab2:6857:0:b0:1ef:ffd0:ce49 with SMTP id l23csp2397983lqp; Sun, 24 Mar 2024 17:45:58 -0700 (PDT) X-Forwarded-Encrypted: i=3; AJvYcCVn6GwKn8tqF5Ot6pVMAnFgDypFq0T/8ayCfNEoGE+/uPunoyGLJDAGuvdCK4VVkyj1g6NCLt1SsF1JJhcr6Npse6LkQaEGFpBUSRbEGw== X-Google-Smtp-Source: AGHT+IEXNWX2bVSwPbCtLSYWbTbxMe7/J5w4m1bhIFi/lePsMOzmeLDJTreGW+8l+Jxh8MKxaSkw X-Received: by 2002:a17:906:c003:b0:a45:b91f:2f95 with SMTP id e3-20020a170906c00300b00a45b91f2f95mr3337014ejz.72.1711327558347; Sun, 24 Mar 2024 17:45:58 -0700 (PDT) ARC-Seal: i=2; a=rsa-sha256; t=1711327558; cv=pass; d=google.com; s=arc-20160816; b=WMqvmsRfEEKLlIZYPMtFVQBp2QVvubVw5APv+nB2312Y172cz5UIQ+MTJrvaXc+URV OqvhQnNQduLMjcS1JxhXa8rakgfJHhcmD11H+nBwfX4NZkkuopv5zLHCEOJlAhkqPQoE tmY685UCfzSnio3+gdCLhA4f5eHWrWNKtwn+WNDGJHqO0OzHMYpURXDkGAje5rxd1RV4 NqSzwl6SUG5jTly6WPLWZ0InUX2a3XOdfqGSKvdCgiRSoqYoMgrbRbt8qDF3UtAomOFc HAuNc7G68R0WBpFo6w91XzVEeCxVX49FtPiPKBevjnnQPnvNC+vzhfeAPznuDOzs+RYO ULzA== ARC-Message-Signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=content-transfer-encoding:mime-version:list-unsubscribe :list-subscribe:list-id:precedence:references:in-reply-to:message-id :date:subject:cc:to:from:dkim-signature; bh=2Nx8UA2opdxDAUlXoz8+8Z6VTfvh/HegztkdB/FPdQA=; fh=Uz1B+o+VWDBLD8wsX0OJ/UBCy0+BprZzgpiNkp0GQcM=; b=JLCh3h7GmBxywSV36O5TL8UvgqQYs5yrfvCZfMQp74pDTkIBAs3zkOJ8zdHXkDwSDE jRZAPFY1GCDVzk9wJL+t/v64J1MfPCVYNC/DthgOEmzkKl70cYweRlH/YDX5VmKiwHAf YBt1cyQB0rrg4KVs0juznbG/NcsoGXS8zEAVuwGcS7x58M5mSY/XORp6a9qCtu+ejsqD qXnuENwF4ctkSc2VzoIG6tsijyEOjDGWQ5uTQyZfih50swKoYOBaCmLPJrIgqvwgHwOo itW46onCYRYXG1fu2rO0F+JspTInABlpEg4aCdRBPIPAeHpVUYX8vU+6tFn/kpr6Ofza Qp5w==; dara=google.com ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@kernel.org header.s=k20201202 header.b=lT02dLz6; arc=pass (i=1 dkim=pass dkdomain=kernel.org); spf=pass (google.com: domain of linux-kernel+bounces-113468-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:4601:e00::3 as permitted sender) smtp.mailfrom="linux-kernel+bounces-113468-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Return-Path: Received: from am.mirrors.kernel.org (am.mirrors.kernel.org. [2604:1380:4601:e00::3]) by mx.google.com with ESMTPS id u11-20020a17090617cb00b00a46021ef910si2162751eje.854.2024.03.24.17.45.58 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sun, 24 Mar 2024 17:45:58 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel+bounces-113468-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:4601:e00::3 as permitted sender) client-ip=2604:1380:4601:e00::3; Authentication-Results: mx.google.com; dkim=pass header.i=@kernel.org header.s=k20201202 header.b=lT02dLz6; arc=pass (i=1 dkim=pass dkdomain=kernel.org); spf=pass (google.com: domain of linux-kernel+bounces-113468-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:4601:e00::3 as permitted sender) smtp.mailfrom="linux-kernel+bounces-113468-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Received: from smtp.subspace.kernel.org (wormhole.subspace.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by am.mirrors.kernel.org (Postfix) with ESMTPS id 95ADF1F2552B for ; Mon, 25 Mar 2024 00:44:39 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 3B3121B2F9D; Sun, 24 Mar 2024 22:44:30 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b="lT02dLz6" Received: from smtp.kernel.org (aws-us-west-2-korg-mail-1.web.codeaurora.org [10.30.226.201]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 4E2921B2F7C; Sun, 24 Mar 2024 22:44:29 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=10.30.226.201 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1711320269; cv=none; b=o9xt6uxgaz67MgmWAKP0O0kZ49/xBKHOZ8SOllCbculLAVd2zqTahMiAZEV4Aosx+wdVQvwlVMUlefaxlv5Y/hewg3RsIwmHX7d4qB42aLecI+LHgpNX94O4MhPYmcxFM88tbrQSDCUZr3COMutavz++cjVby/YVlapI9P3mGuc= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1711320269; c=relaxed/simple; bh=qM1U2wXCsRZOl0yJeh2zTqlMsGMvm1pacSCvynlzoqM=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=RrjdUvUuBZCRQ6eu0DBeumKzcTu4zAwTOnTDog+VhrH1iaYSNEZ1HjBUEl3D/WDmzOewvqqCCNrzr4s97dcaxsLacZhEov+583H7OraKira1eQ6WK/WFCc9w8A4JLHi4DH4V+Tw64pctmGYjJnYW8by4gGCkqn5dcDSdpA6+XUQ= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=lT02dLz6; arc=none smtp.client-ip=10.30.226.201 Received: by smtp.kernel.org (Postfix) with ESMTPSA id 60E60C433C7; Sun, 24 Mar 2024 22:44:28 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1711320269; bh=qM1U2wXCsRZOl0yJeh2zTqlMsGMvm1pacSCvynlzoqM=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=lT02dLz6P0Fdo1o5WXAquu2h+KsLJFUgYe15pbwJv2gxFNL2ZwMFEqEGfMLY//K/D u07gP8hASW99TP4aNa2eIk7W60uNZhtEbPBT5z7EICKoXMLZEGb87FKc0hq6ymaWKl lz4tmXjgQE5DBRn3U+9maLE7NM1vDBOZlVpUF7KU5kZffp24JmkemxyqUT0CI2SxSX lNSvJOmssy39sc4dlubb3lzICI3TYnhS39bvV4xJ1FctEPpPciZJjckPD1iNbiAm+W QCiLNAVRUmSqxi57D1atKaPdYCfIFQtmjzVaJMYcpncIZCgrzkiTmuXxyMq6cXZrON mACdpaEm7fWKg== From: Sasha Levin To: linux-kernel@vger.kernel.org, stable@vger.kernel.org Cc: Jorge Mora , Jorge Mora , Benjamin Coddington , Trond Myklebust , Sasha Levin Subject: [PATCH 6.8 577/715] NFSv4.2: fix nfs4_listxattr kernel BUG at mm/usercopy.c:102 Date: Sun, 24 Mar 2024 18:32:36 -0400 Message-ID: <20240324223455.1342824-578-sashal@kernel.org> X-Mailer: git-send-email 2.43.0 In-Reply-To: <20240324223455.1342824-1-sashal@kernel.org> References: <20240324223455.1342824-1-sashal@kernel.org> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 X-stable: review X-Patchwork-Hint: Ignore Content-Transfer-Encoding: 8bit From: Jorge Mora [ Upstream commit 251a658bbfceafb4d58c76b77682c8bf7bcfad65 ] A call to listxattr() with a buffer size = 0 returns the actual size of the buffer needed for a subsequent call. When size > 0, nfs4_listxattr() does not return an error because either generic_listxattr() or nfs4_listxattr_nfs4_label() consumes exactly all the bytes then size is 0 when calling nfs4_listxattr_nfs4_user() which then triggers the following kernel BUG: [ 99.403778] kernel BUG at mm/usercopy.c:102! [ 99.404063] Internal error: Oops - BUG: 00000000f2000800 [#1] SMP [ 99.408463] CPU: 0 PID: 3310 Comm: python3 Not tainted 6.6.0-61.fc40.aarch64 #1 [ 99.415827] Call trace: [ 99.415985] usercopy_abort+0x70/0xa0 [ 99.416227] __check_heap_object+0x134/0x158 [ 99.416505] check_heap_object+0x150/0x188 [ 99.416696] __check_object_size.part.0+0x78/0x168 [ 99.416886] __check_object_size+0x28/0x40 [ 99.417078] listxattr+0x8c/0x120 [ 99.417252] path_listxattr+0x78/0xe0 [ 99.417476] __arm64_sys_listxattr+0x28/0x40 [ 99.417723] invoke_syscall+0x78/0x100 [ 99.417929] el0_svc_common.constprop.0+0x48/0xf0 [ 99.418186] do_el0_svc+0x24/0x38 [ 99.418376] el0_svc+0x3c/0x110 [ 99.418554] el0t_64_sync_handler+0x120/0x130 [ 99.418788] el0t_64_sync+0x194/0x198 [ 99.418994] Code: aa0003e3 d000a3e0 91310000 97f49bdb (d4210000) Issue is reproduced when generic_listxattr() returns 'system.nfs4_acl', thus calling lisxattr() with size = 16 will trigger the bug. Add check on nfs4_listxattr() to return ERANGE error when it is called with size > 0 and the return value is greater than size. Fixes: 012a211abd5d ("NFSv4.2: hook in the user extended attribute handlers") Signed-off-by: Jorge Mora Reviewed-by: Benjamin Coddington Signed-off-by: Trond Myklebust Signed-off-by: Sasha Levin --- fs/nfs/nfs4proc.c | 16 ++++++++++------ 1 file changed, 10 insertions(+), 6 deletions(-) diff --git a/fs/nfs/nfs4proc.c b/fs/nfs/nfs4proc.c index 23819a7565085..b2ff8c7a21494 100644 --- a/fs/nfs/nfs4proc.c +++ b/fs/nfs/nfs4proc.c @@ -10615,29 +10615,33 @@ const struct nfs4_minor_version_ops *nfs_v4_minor_ops[] = { static ssize_t nfs4_listxattr(struct dentry *dentry, char *list, size_t size) { ssize_t error, error2, error3; + size_t left = size; - error = generic_listxattr(dentry, list, size); + error = generic_listxattr(dentry, list, left); if (error < 0) return error; if (list) { list += error; - size -= error; + left -= error; } - error2 = nfs4_listxattr_nfs4_label(d_inode(dentry), list, size); + error2 = nfs4_listxattr_nfs4_label(d_inode(dentry), list, left); if (error2 < 0) return error2; if (list) { list += error2; - size -= error2; + left -= error2; } - error3 = nfs4_listxattr_nfs4_user(d_inode(dentry), list, size); + error3 = nfs4_listxattr_nfs4_user(d_inode(dentry), list, left); if (error3 < 0) return error3; - return error + error2 + error3; + error += error2 + error3; + if (size && error > size) + return -ERANGE; + return error; } static void nfs4_enable_swap(struct inode *inode) -- 2.43.0