Received: by 2002:a05:6a10:17d3:0:0:0:0 with SMTP id hz19csp2576310pxb; Mon, 19 Apr 2021 08:47:03 -0700 (PDT) X-Google-Smtp-Source: ABdhPJz++aDne+EX1tDRnMjXiJ+9YeXPIqOd/fXMAzLJgXQBCW0HN+VrS3yYXLa/h7sLxr0oaGTp X-Received: by 2002:a17:90a:db49:: with SMTP id u9mr26758260pjx.209.1618847223393; Mon, 19 Apr 2021 08:47:03 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1618847223; cv=none; d=google.com; s=arc-20160816; b=vUKLfDuHhyrV8urYlNaDD+4PXMq30MTUUDiatlXSgxbDjBppMw/ECrXIbcJeO75k80 z/1hwxQZxvUWrp30V2fD+kjsbvqzIsom1o8bC/G5YBx3KkPtDBzgfXZCDRH6dkXog7su ZQKT2gZhkm2C6kIgBn/bv1JXq9p36qqooSLuMisykweeI2fy9w7YIQ6CddrC8mNGxjZa q3KU/4WQ6cDDCl7j/808BCgZKqPV57nKmpcmdxdd3+mI76xejnmuX18SHbQZDcvf0ret rAdCq4Nz2K2prl7nT7o6r43qvw3KqgtoLr+pD5LdJ0L9D05EhZEUWBmM6mbMWwXQ8tTK r4rA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :user-agent:references:in-reply-to:message-id:date:subject:cc:to :from:dkim-signature; bh=jURktqb0If0pKdAcfFEryoVjLxAKU+/gwTtqSZEd52o=; b=TUhVMXguRflEVgU1J6598/5U+VPGC4OThDjhxOVF5wKEK9iKJELz1D3v6P9CwsDCLz wd0VefmWTVqw4rBzKEYuz6gcbYiDX2BF60b7n16O7JfxkQaxxbDWorT6L7YC0yvQ+pCx az9b5vt3xuVSog28N6RkdRwdFdi/VX2KcOyIJQ0iTisqevZHz1gkjdxA2WsTodxvD1to mR3DNLkc+8cpwreh4zvWxWlkCPZen6XR2487FjPjw0ayJ09iGRnVuCqwVaMMJomFPVSA uhS++HzBayxQ2GXbSI28gAlNPSCWQYnZMEVWFEAGJgr7DcR+u6TG6OOT0wexRP4pxPlw 2Hsw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b=TxAVer9G; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linuxfoundation.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id a73si1183123pfd.159.2021.04.19.08.46.50; Mon, 19 Apr 2021 08:47:03 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) client-ip=23.128.96.18; Authentication-Results: mx.google.com; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b=TxAVer9G; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linuxfoundation.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S241371AbhDSN2N (ORCPT + 99 others); Mon, 19 Apr 2021 09:28:13 -0400 Received: from mail.kernel.org ([198.145.29.99]:56922 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S241404AbhDSNUa (ORCPT ); Mon, 19 Apr 2021 09:20:30 -0400 Received: by mail.kernel.org (Postfix) with ESMTPSA id 3357F61027; Mon, 19 Apr 2021 13:16:32 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linuxfoundation.org; s=korg; t=1618838192; bh=iBSMgnMNLXpFc200GKSv3a5Xx9xTjN3Rr6lO71V20JQ=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=TxAVer9GDquQq8ViDEP6kvo08ayhUxf7vQacpWl9QGq9oeJWRc1rTVTm6iASrSG2u w0HrnSbHmjzzjlZynC7aafeDVl/oNPSXmfNusZ49qodYLyLB3HatZXlUpWJWoCyTeb n08rUM2MjIQJwAlTJcj4YAOlNLMueQ24IxFqkHCo= From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , stable@vger.kernel.org, Aditya Pakki , Santosh Shilimkar , "David S. Miller" , Sasha Levin Subject: [PATCH 5.10 042/103] net/rds: Avoid potential use after free in rds_send_remove_from_sock Date: Mon, 19 Apr 2021 15:05:53 +0200 Message-Id: <20210419130529.251281725@linuxfoundation.org> X-Mailer: git-send-email 2.31.1 In-Reply-To: <20210419130527.791982064@linuxfoundation.org> References: <20210419130527.791982064@linuxfoundation.org> User-Agent: quilt/0.66 MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org From: Aditya Pakki [ Upstream commit 0c85a7e87465f2d4cbc768e245f4f45b2f299b05 ] In case of rs failure in rds_send_remove_from_sock(), the 'rm' resource is freed and later under spinlock, causing potential use-after-free. Set the free pointer to NULL to avoid undefined behavior. Signed-off-by: Aditya Pakki Acked-by: Santosh Shilimkar Signed-off-by: David S. Miller Signed-off-by: Sasha Levin --- net/rds/message.c | 1 + net/rds/send.c | 2 +- 2 files changed, 2 insertions(+), 1 deletion(-) diff --git a/net/rds/message.c b/net/rds/message.c index 799034e0f513..4fc66ff0f1ec 100644 --- a/net/rds/message.c +++ b/net/rds/message.c @@ -180,6 +180,7 @@ void rds_message_put(struct rds_message *rm) rds_message_purge(rm); kfree(rm); + rm = NULL; } } EXPORT_SYMBOL_GPL(rds_message_put); diff --git a/net/rds/send.c b/net/rds/send.c index 985d0b7713ac..fe5264b9d4b3 100644 --- a/net/rds/send.c +++ b/net/rds/send.c @@ -665,7 +665,7 @@ static void rds_send_remove_from_sock(struct list_head *messages, int status) unlock_and_drop: spin_unlock_irqrestore(&rm->m_rs_lock, flags); rds_message_put(rm); - if (was_on_sock) + if (was_on_sock && rm) rds_message_put(rm); } -- 2.30.2