Received: by 2002:a05:6a10:16a7:0:0:0:0 with SMTP id gp39csp417613pxb; Wed, 18 Nov 2020 07:48:09 -0800 (PST) X-Google-Smtp-Source: ABdhPJzyIiC0CWhfWN4mjHo/q88joqg3mox3t+1nAw7lXpQLj/xt10xraNRPykLNAnMtPHI4C5iX X-Received: by 2002:a17:906:9592:: with SMTP id r18mr20903259ejx.300.1605714489142; Wed, 18 Nov 2020 07:48:09 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1605714489; cv=none; d=google.com; s=arc-20160816; b=vsVFypwTuqi+jtuTld5jgAePQ0NAuLnmp+ZKLDGd1Djo7rNAjFecn72EAw4EdAChK4 A5VWg3OaHIvh6RrY96hcHclYouXMfGlvWty5D/z5Hh6ESM42qrJvqCj4ODipxC1v8jc0 3yqd26MM+Im5phWHIO7UCw0GSmRkd7WBqrSdHTTjlcDhwZwuzB1v9YbBuGBNcteITDfY jC/gV83cGSr6z4m/j5kpmBpR8O07UcHTFAmO70E4XcTfa5RTNxbkgem/q1tHWrhfJNfb nXQAjOi/kTfud8gt4Pkxc3PtWO6pfkKDl04lmhryz3CjIikPvFcrs8QE7mC8hCKXcrG0 IUnw== 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 :message-id:date:subject:cc:to:from; bh=IW5AyHUEAmsofNwt3UW6wl/Ab+wcx/iEGfVP9INdQyE=; b=bD+B8U5lo1NEHDfUCdY17sEC8PgYMfQoGcUI1r5A1OejqqU2dL+cNNCIyZpHpn2aPw aqF02RES51mUfHNRLLkyz0q5TGEh2xLTzu86JDII0fhfIPTbvL2zbhixM58Xk3vMqoZ7 D9oJKCUX1i4wTqAq9nfA3MI9oi0ypUW3/jC9UiR49yN7S4otphLqfhyrylakIy35JYrK JVqe+5anil8WhAxNqMYYU1/yE2y1u1Rtn8QQrI2euCHn2q/5cbG6XV8JC1vUScGLIuCk gDfexkPuV+jzsXVoXWgEZ6kHHvWAYkxKrJS6g0W8oI1lRM/pfSQekrJaBSb27UGnDZzk 9K4A== ARC-Authentication-Results: i=1; mx.google.com; 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 Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id a4si15484839ejf.460.2020.11.18.07.47.45; Wed, 18 Nov 2020 07:48:09 -0800 (PST) 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; 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 Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1727665AbgKRPo3 (ORCPT + 99 others); Wed, 18 Nov 2020 10:44:29 -0500 Received: from mailout02.rmx.de ([62.245.148.41]:45927 "EHLO mailout02.rmx.de" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726363AbgKRPo3 (ORCPT ); Wed, 18 Nov 2020 10:44:29 -0500 Received: from kdin02.retarus.com (kdin02.dmz1.retloc [172.19.17.49]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mailout02.rmx.de (Postfix) with ESMTPS id 4CbnDT1h6wzNmql; Wed, 18 Nov 2020 16:44:25 +0100 (CET) Received: from mta.arri.de (unknown [217.111.95.66]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-SHA384 (256/256 bits)) (No client certificate requested) by kdin02.retarus.com (Postfix) with ESMTPS id 4CbnCy3Xp7z2TTN0; Wed, 18 Nov 2020 16:43:58 +0100 (CET) Received: from N95HX1G2.wgnetz.xx (192.168.54.25) by mta.arri.de (192.168.100.104) with Microsoft SMTP Server (TLS) id 14.3.487.0; Wed, 18 Nov 2020 16:43:58 +0100 From: Christian Eggers To: Andrew Lunn , Florian Fainelli , Vladimir Oltean CC: Vivien Didelot , "David S . Miller" , Jakub Kicinski , , , Christian Eggers Subject: [PATCH net-next] net: dsa: avoid potential use-after-free error Date: Wed, 18 Nov 2020 16:43:35 +0100 Message-ID: <20201118154335.1189-1-ceggers@arri.de> X-Mailer: git-send-email 2.26.2 MIME-Version: 1.0 Content-Transfer-Encoding: 7BIT Content-Type: text/plain; charset=US-ASCII X-Originating-IP: [192.168.54.25] X-RMX-ID: 20201118-164358-4CbnCy3Xp7z2TTN0-0@kdin02 X-RMX-SOURCE: 217.111.95.66 Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org If dsa_switch_ops::port_txtstamp() returns false, clone will be freed immediately. Storing the pointer in DSA_SKB_CB(skb)->clone anyway, supports annoying use-after-free bugs. Signed-off-by: Christian Eggers Fixes 146d442c2357 ("net: dsa: Keep a pointer to the skb clone for TX timestamping") --- net/dsa/slave.c | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/net/dsa/slave.c b/net/dsa/slave.c index ff2266d2b998..7efc753e4d9d 100644 --- a/net/dsa/slave.c +++ b/net/dsa/slave.c @@ -522,10 +522,10 @@ static void dsa_skb_tx_timestamp(struct dsa_slave_priv *p, if (!clone) return; - DSA_SKB_CB(skb)->clone = clone; - - if (ds->ops->port_txtstamp(ds, p->dp->index, clone, type)) + if (ds->ops->port_txtstamp(ds, p->dp->index, clone, type)) { + DSA_SKB_CB(skb)->clone = clone; return; + } kfree_skb(clone); } -- Christian Eggers Embedded software developer Arnold & Richter Cine Technik GmbH & Co. Betriebs KG Sitz: Muenchen - Registergericht: Amtsgericht Muenchen - Handelsregisternummer: HRA 57918 Persoenlich haftender Gesellschafter: Arnold & Richter Cine Technik GmbH Sitz: Muenchen - Registergericht: Amtsgericht Muenchen - Handelsregisternummer: HRB 54477 Geschaeftsfuehrer: Dr. Michael Neuhaeuser; Stephan Schenk; Walter Trauninger; Markus Zeiler