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 CDFF94C7F; Mon, 23 Jun 2025 13:31:02 +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=1750685462; cv=none; b=YVVMDAkUgMY2x0nFz9Yh//x/ssndyuvg5XC+3cf+98EbstZQ1XtMZbKGaCcbALHojZHU/JcTXRbEC3G6iJF5WffXNCPlp391cvc93HiQ3pemNXY7BKzBSU50/KdWgBf2FJ/UqcySSzwwHucQtFmtVlxlzYc7yPB0UwsOhzjWfC8= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1750685462; c=relaxed/simple; bh=Wp7aTzOd6p6oXJHevi5UwZ7MS7HTcYwci3sIsVwKcDA=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=Ifp2SEYSzIBubOBjbT9h09I3YrE7cTluD7X9Cf4w1Iq8FEzI1leNLM5OAVAJkmfxxdNnA/CSBLy0H5HEfbupR1yHMGa61NsjQdlLVZWWt2uKwwJhEVus9tYLODgPXQxYSEQJehzYYUI7t4/5BKtEusjN47FZnpJHok3Qv4iDrR4= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=linuxfoundation.org header.i=@linuxfoundation.org header.b=TEA4/Tb8; 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="TEA4/Tb8" Received: by smtp.kernel.org (Postfix) with ESMTPSA id 64409C4CEEA; Mon, 23 Jun 2025 13:31:02 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linuxfoundation.org; s=korg; t=1750685462; bh=Wp7aTzOd6p6oXJHevi5UwZ7MS7HTcYwci3sIsVwKcDA=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=TEA4/Tb8HIK0NC/D1gbsiTXTbvHg0cijQJEByrccmXj6cdy6B3RlqcEIHFY4anPkH JxJfFpEls+ZGEIa4PblT7mewDDr/qYE3lrdYlsHjdsIKaXAe4dz93E+/XUkSNBvFf1 hTRAjXOvI17ZuY31nQHu9cQKBELEOB66MKOlwLSU= From: Greg Kroah-Hartman To: stable@vger.kernel.org Cc: Greg Kroah-Hartman , patches@lists.linux.dev, Jeongjun Park , syzbot+a2b84e569d06ca3a949c@syzkaller.appspotmail.com, Liam Howlett , Lorenzo Stoakes , "Matthew Wilcox (Oracle)" , Vasiliy Kulikov , Andrew Morton Subject: [PATCH 5.4 121/222] ipc: fix to protect IPCS lookups using RCU Date: Mon, 23 Jun 2025 15:07:36 +0200 Message-ID: <20250623130615.739079769@linuxfoundation.org> X-Mailer: git-send-email 2.50.0 In-Reply-To: <20250623130611.896514667@linuxfoundation.org> References: <20250623130611.896514667@linuxfoundation.org> User-Agent: quilt/0.68 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 5.4-stable review patch. If anyone has any objections, please let me know. ------------------ From: Jeongjun Park commit d66adabe91803ef34a8b90613c81267b5ded1472 upstream. syzbot reported that it discovered a use-after-free vulnerability, [0] [0]: https://lore.kernel.org/all/67af13f8.050a0220.21dd3.0038.GAE@google.com/ idr_for_each() is protected by rwsem, but this is not enough. If it is not protected by RCU read-critical region, when idr_for_each() calls radix_tree_node_free() through call_rcu() to free the radix_tree_node structure, the node will be freed immediately, and when reading the next node in radix_tree_for_each_slot(), the already freed memory may be read. Therefore, we need to add code to make sure that idr_for_each() is protected within the RCU read-critical region when we call it in shm_destroy_orphaned(). Link: https://lkml.kernel.org/r/20250424143322.18830-1-aha310510@gmail.com Fixes: b34a6b1da371 ("ipc: introduce shm_rmid_forced sysctl") Signed-off-by: Jeongjun Park Reported-by: syzbot+a2b84e569d06ca3a949c@syzkaller.appspotmail.com Cc: Jeongjun Park Cc: Liam Howlett Cc: Lorenzo Stoakes Cc: Matthew Wilcox (Oracle) Cc: Vasiliy Kulikov Cc: Signed-off-by: Andrew Morton Signed-off-by: Greg Kroah-Hartman --- ipc/shm.c | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) --- a/ipc/shm.c +++ b/ipc/shm.c @@ -417,8 +417,11 @@ static int shm_try_destroy_orphaned(int void shm_destroy_orphaned(struct ipc_namespace *ns) { down_write(&shm_ids(ns).rwsem); - if (shm_ids(ns).in_use) + if (shm_ids(ns).in_use) { + rcu_read_lock(); idr_for_each(&shm_ids(ns).ipcs_idr, &shm_try_destroy_orphaned, ns); + rcu_read_unlock(); + } up_write(&shm_ids(ns).rwsem); }