Received: by 2002:ab2:6857:0:b0:1ef:ffd0:ce49 with SMTP id l23csp2491298lqp; Sun, 24 Mar 2024 23:22:21 -0700 (PDT) X-Forwarded-Encrypted: i=3; AJvYcCX3JTfmXDE5Wf34ZevyCN1ozP8o+g1+bV2wv5s6gACqKhYRfE1dSkMwel+gq6gpcbLbJbFFr18p5DQLLq0JxVMRwbZ7ulGjI55oj4q49w== X-Google-Smtp-Source: AGHT+IFGztH+meJaAuuyjuT26UDFZrHxkId2SKfVS4Dlf17af+MnPPfngUztW55TrCnl3CpnAK1A X-Received: by 2002:a50:9ec9:0:b0:56b:cda3:6de6 with SMTP id a67-20020a509ec9000000b0056bcda36de6mr3708219edf.42.1711347741715; Sun, 24 Mar 2024 23:22:21 -0700 (PDT) ARC-Seal: i=2; a=rsa-sha256; t=1711347741; cv=pass; d=google.com; s=arc-20160816; b=lHsqNWpkRTkhxw4Fp5/k3SKk1LJF9TxhCFVQHk6+3DhmbVkYRl7Azra5PgCDFj5Rml w4cG1gDBn9o5HyaGgxbPzohH6flDnomkSMS9zTKUTrGR4Q65F3KoBmDD6ql4Pg7Yvq+C UbL0p0TAyQCk8/kUwpweWTvmzFwfgN2OIJayVeINhCg0/D5u5ke+ZHyudW3d5q4ZDCDU GuZlOI9eEoDJ1YQvRstInJhwKq9iYwxue00Wh/hbmXE0jHFz7a2e+hjDUHUvRZgVQndT LW/7PH9bTFLDozCBJ3oyDT7XUVQYZWmoDi4AHh8fEEixoXyVCxWw8frrMqhL3jfqMcn6 Ni/Q== 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=iwwpsPccCtOn6nm0r1UexmgjnHXVbAVaLI0L+B1mDgw=; fh=Uz1B+o+VWDBLD8wsX0OJ/UBCy0+BprZzgpiNkp0GQcM=; b=Xg6F00oSoRBBacfoqxHo35wbmO4NlvB+cjGSABpkt4V5dII/AWk37nBbU3XdD176Ap F1rZmbYiKbY4tgdZjJbgeXc0Goka4giSdJqpr4RfIjNgYqX2iw1B2lyTP8NQZpOZQUzU N1fV6DKhm8V9DM9SsTfFHP2WXOgMHuoyT+8JNW5UwO4qOBNz0EYAv5u3cvqfqSLxshs3 Q1eQ3J/CQLwSRX7HsW/amE8NIxPIwrgebDf4Ar1hy2xsFNfBnqZZvxL1Ryh0kf62mGqa lqGq6jIB0spOC+M1zhJ0dGWu2X0M17lAJQUcZNCr+tZkNJCPMktKuDtqbDQzmabKxuwm uwxw==; dara=google.com ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@kernel.org header.s=k20201202 header.b=cXRUUe+R; arc=pass (i=1 dkim=pass dkdomain=kernel.org); spf=pass (google.com: domain of linux-kernel+bounces-114623-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:4601:e00::3 as permitted sender) smtp.mailfrom="linux-kernel+bounces-114623-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 z11-20020a056402274b00b0056bfa690942si1906596edd.548.2024.03.24.23.22.21 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sun, 24 Mar 2024 23:22:21 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel+bounces-114623-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=cXRUUe+R; arc=pass (i=1 dkim=pass dkdomain=kernel.org); spf=pass (google.com: domain of linux-kernel+bounces-114623-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:4601:e00::3 as permitted sender) smtp.mailfrom="linux-kernel+bounces-114623-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 52ED61F2AA1D for ; Mon, 25 Mar 2024 06:21:25 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 7D38E2A4928; Sun, 24 Mar 2024 23:56:09 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b="cXRUUe+R" 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 6587E234D87; Sun, 24 Mar 2024 23:18:08 +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=1711322289; cv=none; b=R8RNacZbSQhoRxxgCOrVE6VUspUsFXYifvOF5q7LNzfcFzD6CEBc68TTElIKwqx9iGq1QWEjQn4RDOjqMI5i6qSq2JWv3kryCjRig9h/CyiyU1P9xyBFzvTiVPDyMOTVSNirsDye9rbugEOg1G0xMRNA3PvMKJ+iCkBvLNmD+34= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1711322289; c=relaxed/simple; bh=yYO9KRfCndalG65ITRxpc4yjL9HO5ZNlZM30I0MbeX0=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=KA+YbJTZ74kEkT0vENCCibvbNH8Tu6bZk+8yy84rEOD9RtstvHuw+JccLHvJ99E29doQ7dBrACmClJ98787Ideo4rmCvKiHISBuxwjiSqIg3u2QRlvWfFCPV8MbzkzOCJic/pJqq+KvTPtI+fydDvVwWuHbCILTp684d1MfQfPo= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=cXRUUe+R; arc=none smtp.client-ip=10.30.226.201 Received: by smtp.kernel.org (Postfix) with ESMTPSA id 6CC84C43394; Sun, 24 Mar 2024 23:18:07 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1711322288; bh=yYO9KRfCndalG65ITRxpc4yjL9HO5ZNlZM30I0MbeX0=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=cXRUUe+RUW7RxfJr4LS/i3LgD+WQxUmyq9Vpbe9AQE4nI17o5NulaY+pVITigfCrh GV0gy8elzrsazkQCZQuxxlbFfDwpGQKnQITGfl4+5KQkr2D38NfgtCtvbk/CAUz+g5 /EgsJ4PrkKsRphxyL8ENYwlu4Rin5i9dauTxC49IEVn0TD8tPLxhVz1suqcoQa22m8 Q5dyyPF58MFa+sKhviQgTAereN7aNpLbyEEZtmzamWRKsAiI/jNrXADd1kROzjoTnn XMAhCQg892Is0/bFgSYs6F0F8WZwcTL7BmEtQJ4HyFGHWIEG62XubWd2Xkt05W/qS0 B3fhwBrv0jMag== 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.1 371/451] NFSv4.2: fix nfs4_listxattr kernel BUG at mm/usercopy.c:102 Date: Sun, 24 Mar 2024 19:10:47 -0400 Message-ID: <20240324231207.1351418-372-sashal@kernel.org> X-Mailer: git-send-email 2.43.0 In-Reply-To: <20240324231207.1351418-1-sashal@kernel.org> References: <20240324231207.1351418-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 ec3f0103e1a7f..7cc74f7451d67 100644 --- a/fs/nfs/nfs4proc.c +++ b/fs/nfs/nfs4proc.c @@ -10592,29 +10592,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