Received: by 2002:a05:6a10:17d3:0:0:0:0 with SMTP id hz19csp2095845pxb; Mon, 12 Apr 2021 14:21:56 -0700 (PDT) X-Google-Smtp-Source: ABdhPJxOdIDsEhQtdcfAQ/S04zmQgiJ2AySVCaPO2vZmBTM1FuoGzmOM2RZZMTFamlk+QmJv4UGc X-Received: by 2002:a17:906:3544:: with SMTP id s4mr29631586eja.73.1618262516268; Mon, 12 Apr 2021 14:21:56 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1618262516; cv=none; d=google.com; s=arc-20160816; b=lw04Ur3GVY63L8qpreEhvniOk72h32XwKPOZuS2li4yC1ML1bU3ExdprYZwpoUySry icQygi9oUZmnytD2ZguUHj060cnlN57+5DvP9pJJb5yTdGZPAz8E6Y+wMIs8A0xF8Oum 2qk8YRqVLMKdyWw1+nJg/HMgiIiH6RadmcVLkgxWHlkgGmBf26Un6+rtmQkM/RXENAPh FduQuWcGfH62VzUgV9LTRIaW2/M0HJ/+qqSOaTUoCLjKU8AXxBVKdtzzbpMNgJipvBF2 IyapZZG+bSEvaTiwA9G/vOKic1pdjF1xLnqmbIhjUK/ppyKTut5pa6S9M+QPfsME1NKd Fxsg== 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=TPX/HcBRSrldRPby0OWgwoexGIqZhjNccaPhv5KBazY=; b=QlEW0usOCanch8q9LiFZJ2YdJJ8Z6UyxBGvtgwWclHf7yNJyhD9W4DPFgpFGHETyBf ZjPtGkUeL2OnIwcnJRyYWVXriFjf6+ugqnV7bFjNAdadkVSQ9sobApulLlCkv8+LE1d9 iLe0A/NzRowYiHzIrVXW4lJ2R4rejU8/ihiT17JyXq60j0yj7meG9mVHGJ20F9z7Nihu tOeFFk5ko9LjL7JCuIHPzY320QKxZQrxvKBmxhn+fEwqBbjE1QiLQAkOr14318FoCOk3 +CC3XcW23gA7p+3I1LUT89lq9oVm2emDePF5YzQtbdXsDuOivPkofRmgU8IvQS/jGuYd NfWA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b=cg7NEZAx; 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 r21si453144edy.321.2021.04.12.14.21.33; Mon, 12 Apr 2021 14:21:56 -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=cg7NEZAx; 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 S241033AbhDLJL0 (ORCPT + 99 others); Mon, 12 Apr 2021 05:11:26 -0400 Received: from mail.kernel.org ([198.145.29.99]:49588 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S238229AbhDLI4T (ORCPT ); Mon, 12 Apr 2021 04:56:19 -0400 Received: by mail.kernel.org (Postfix) with ESMTPSA id C3B5861243; Mon, 12 Apr 2021 08:56:00 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linuxfoundation.org; s=korg; t=1618217761; bh=E4On03olDXlXaD6Da4m40Fka5Ezpp6tXS7AB3kXFs14=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=cg7NEZAx4g4euB7Lhp0BuPD/JDibJfbFhPwqw1XfC+M66qrLb5bE1C6J1kvjkSN7K K2dceQWTOxdEjjBVDCUljJpeDXIxWLiWo36g2bHcpsklH1vaZaHZ8+EP3JFXibfWav gL5s81hwEt1zuIgax/UjmTzdKcFVX6mJTXscIMiM= From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , stable@vger.kernel.org, Lv Yunlong , =?UTF-8?q?H=C3=A5kon=20Bugge?= , "David S. Miller" , Sasha Levin Subject: [PATCH 5.10 134/188] net/rds: Fix a use after free in rds_message_map_pages Date: Mon, 12 Apr 2021 10:40:48 +0200 Message-Id: <20210412084018.096557943@linuxfoundation.org> X-Mailer: git-send-email 2.31.1 In-Reply-To: <20210412084013.643370347@linuxfoundation.org> References: <20210412084013.643370347@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: Lv Yunlong [ Upstream commit bdc2ab5c61a5c07388f4820ff21e787b4dfd1ced ] In rds_message_map_pages, the rm is freed by rds_message_put(rm). But rm is still used by rm->data.op_sg in return value. My patch assigns ERR_CAST(rm->data.op_sg) to err before the rm is freed to avoid the uaf. Fixes: 7dba92037baf3 ("net/rds: Use ERR_PTR for rds_message_alloc_sgs()") Signed-off-by: Lv Yunlong Reviewed-by: HÃ¥kon Bugge Signed-off-by: David S. Miller Signed-off-by: Sasha Levin --- net/rds/message.c | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/net/rds/message.c b/net/rds/message.c index 071a261fdaab..799034e0f513 100644 --- a/net/rds/message.c +++ b/net/rds/message.c @@ -347,8 +347,9 @@ struct rds_message *rds_message_map_pages(unsigned long *page_addrs, unsigned in rm->data.op_nents = DIV_ROUND_UP(total_len, PAGE_SIZE); rm->data.op_sg = rds_message_alloc_sgs(rm, num_sgs); if (IS_ERR(rm->data.op_sg)) { + void *err = ERR_CAST(rm->data.op_sg); rds_message_put(rm); - return ERR_CAST(rm->data.op_sg); + return err; } for (i = 0; i < rm->data.op_nents; ++i) { -- 2.30.2