From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 66CAFC4332F for ; Mon, 20 Dec 2021 15:02:05 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S237700AbhLTPCE (ORCPT ); Mon, 20 Dec 2021 10:02:04 -0500 Received: from ams.source.kernel.org ([145.40.68.75]:36240 "EHLO ams.source.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S238577AbhLTO55 (ORCPT ); Mon, 20 Dec 2021 09:57:57 -0500 Received: from smtp.kernel.org (relay.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by ams.source.kernel.org (Postfix) with ESMTPS id E2F77B80EE2; Mon, 20 Dec 2021 14:57:54 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 1DDCCC36AF8; Mon, 20 Dec 2021 14:57:52 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linuxfoundation.org; s=korg; t=1640012273; bh=l8tORQ9zuIR5+VtJkMFRn0vyHiWieOabk+6VwicJ/3I=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=KGuZ/wxgLfN1gvSBFgrf/qP/L6P5gIrjuLqBiB9vIgL0TzVskNRE3+wul681nIANi KLfakRHHmKYw6itX+3VCDQoy8CFqa7AiRWw3VCAN2MmdcDQScxUKoYJ9F6/SVwCytT sNc9OQft1IDofvmr0faFxNBchBmpQBX5aOHMc4UY= From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , stable@vger.kernel.org, Syzbot , Willem de Bruijn , Eric Dumazet , Jakub Kicinski , Sasha Levin Subject: [PATCH 5.15 100/177] net/packet: rx_owner_map depends on pg_vec Date: Mon, 20 Dec 2021 15:34:10 +0100 Message-Id: <20211220143043.465394934@linuxfoundation.org> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20211220143040.058287525@linuxfoundation.org> References: <20211220143040.058287525@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: Willem de Bruijn [ Upstream commit ec6af094ea28f0f2dda1a6a33b14cd57e36a9755 ] Packet sockets may switch ring versions. Avoid misinterpreting state between versions, whose fields share a union. rx_owner_map is only allocated with a packet ring (pg_vec) and both are swapped together. If pg_vec is NULL, meaning no packet ring was allocated, then neither was rx_owner_map. And the field may be old state from a tpacket_v3. Fixes: 61fad6816fc1 ("net/packet: tpacket_rcv: avoid a producer race condition") Reported-by: Syzbot Signed-off-by: Willem de Bruijn Reviewed-by: Eric Dumazet Link: https://lore.kernel.org/r/20211215143937.106178-1-willemdebruijn.kernel@gmail.com Signed-off-by: Jakub Kicinski Signed-off-by: Sasha Levin --- net/packet/af_packet.c | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/net/packet/af_packet.c b/net/packet/af_packet.c index 2a2bc64f75cfd..1bc7ef49e1487 100644 --- a/net/packet/af_packet.c +++ b/net/packet/af_packet.c @@ -4457,9 +4457,10 @@ static int packet_set_ring(struct sock *sk, union tpacket_req_u *req_u, } out_free_pg_vec: - bitmap_free(rx_owner_map); - if (pg_vec) + if (pg_vec) { + bitmap_free(rx_owner_map); free_pg_vec(pg_vec, order, req->tp_block_nr); + } out: return err; } -- 2.33.0