From mboxrd@z Thu Jan 1 00:00:00 1970 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 A30F614A088; Tue, 3 Dec 2024 16:17:43 +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=1733242663; cv=none; b=cf5T8P5tItOS1miX/jBh5Ui74P1s89cmyb0X0bZ1Uy89cd8xUdAJf0guBtYOjLGrSCJYQaEZb/4WQyRJYNCN9TTYjr/3vRJ46ocKHLlB2QuZ1g9t5ZW03DOoqYVDFrQjwp46YUuuDBTHX5rOraBZKzXYXRlSBySN3BQhw7xg5Ik= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1733242663; c=relaxed/simple; bh=hxxxVx4CJy2nPtIPa/XXRbwoV9EuxKuo0xoUTZ6ajB0=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=opnokAWfMB374aXouWI+anPqs4n9dqBOc3Gz1Swy0J8KSnDZRAe55itS3z+xSqWfqCg735S2s6WHqpZ7yFbGcWYfvCkRuqr1swr56iK2QByvpJpULAguMlx3Bmfc2DQidRIBY6+fYFyxqOfku8TL+J1ACfuxfYoYSlidzvDrYb8= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=linuxfoundation.org header.i=@linuxfoundation.org header.b=IQjWykCv; arc=none smtp.client-ip=10.30.226.201 Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=linuxfoundation.org header.i=@linuxfoundation.org header.b="IQjWykCv" Received: by smtp.kernel.org (Postfix) with ESMTPSA id BD421C4CECF; Tue, 3 Dec 2024 16:17:42 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linuxfoundation.org; s=korg; t=1733242663; bh=hxxxVx4CJy2nPtIPa/XXRbwoV9EuxKuo0xoUTZ6ajB0=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=IQjWykCvvbbCfc5DFB+FwykBEWsEBn+/xDEmTfGqaocHsVYo+7bAwf/gM1ZseJqvb K4RbUiZoHy3ScWI+gMA/aWCx7zeJQWfUTfUzqmhyH3b1+gwDsCrtaBmftGfoIfDAf4 UlnSbiH8jpUsX23nmAs4wOdTc89fvx0EJfWvg5ks= From: Greg Kroah-Hartman To: stable@vger.kernel.org Cc: Greg Kroah-Hartman , patches@lists.linux.dev, Yang Erkun , Jeff Layton , Chuck Lever Subject: [PATCH 6.12 771/826] SUNRPC: make sure cache entry active before cache_show Date: Tue, 3 Dec 2024 15:48:18 +0100 Message-ID: <20241203144813.841670595@linuxfoundation.org> X-Mailer: git-send-email 2.47.1 In-Reply-To: <20241203144743.428732212@linuxfoundation.org> References: <20241203144743.428732212@linuxfoundation.org> User-Agent: quilt/0.67 X-stable: review X-Patchwork-Hint: ignore Precedence: bulk X-Mailing-List: stable@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: 8bit 6.12-stable review patch. If anyone has any objections, please let me know. ------------------ From: Yang Erkun commit 2862eee078a4d2d1f584e7f24fa50dddfa5f3471 upstream. The function `c_show` was called with protection from RCU. This only ensures that `cp` will not be freed. Therefore, the reference count for `cp` can drop to zero, which will trigger a refcount use-after-free warning when `cache_get` is called. To resolve this issue, use `cache_get_rcu` to ensure that `cp` remains active. ------------[ cut here ]------------ refcount_t: addition on 0; use-after-free. WARNING: CPU: 7 PID: 822 at lib/refcount.c:25 refcount_warn_saturate+0xb1/0x120 CPU: 7 UID: 0 PID: 822 Comm: cat Not tainted 6.12.0-rc3+ #1 Hardware name: QEMU Standard PC (i440FX + PIIX, 1996), BIOS 1.16.1-2.fc37 04/01/2014 RIP: 0010:refcount_warn_saturate+0xb1/0x120 Call Trace: c_show+0x2fc/0x380 [sunrpc] seq_read_iter+0x589/0x770 seq_read+0x1e5/0x270 proc_reg_read+0xe1/0x140 vfs_read+0x125/0x530 ksys_read+0xc1/0x160 do_syscall_64+0x5f/0x170 entry_SYSCALL_64_after_hwframe+0x76/0x7e Cc: stable@vger.kernel.org # v4.20+ Signed-off-by: Yang Erkun Reviewed-by: Jeff Layton Signed-off-by: Chuck Lever Signed-off-by: Greg Kroah-Hartman --- net/sunrpc/cache.c | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) --- a/net/sunrpc/cache.c +++ b/net/sunrpc/cache.c @@ -1427,7 +1427,9 @@ static int c_show(struct seq_file *m, vo seq_printf(m, "# expiry=%lld refcnt=%d flags=%lx\n", convert_to_wallclock(cp->expiry_time), kref_read(&cp->ref), cp->flags); - cache_get(cp); + if (!cache_get_rcu(cp)) + return 0; + if (cache_check(cd, cp, NULL)) /* cache_check does a cache_put on failure */ seq_puts(m, "# ");