Return-Path: Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S936162AbdGTLiZ (ORCPT ); Thu, 20 Jul 2017 07:38:25 -0400 Received: from mail-db5eur01on0086.outbound.protection.outlook.com ([104.47.2.86]:61120 "EHLO EUR01-DB5-obe.outbound.protection.outlook.com" rhost-flags-OK-OK-OK-FAIL) by vger.kernel.org with ESMTP id S934768AbdGTLiX (ORCPT ); Thu, 20 Jul 2017 07:38:23 -0400 From: Bogdan Purcareata To: Dan Carpenter CC: Ruxandra Ioana Radulescu , "gregkh@linuxfoundation.org" , "linux-kernel@vger.kernel.org" , "devel@driverdev.osuosl.org" Subject: RE: [PATCH 1/2] staging: fsl-dpaa2/eth: Fix skb use after free Thread-Topic: [PATCH 1/2] staging: fsl-dpaa2/eth: Fix skb use after free Thread-Index: AQHTAUctuA5hb4j290u8/OLGiWOnIKJckQMAgAADKlA= Date: Thu, 20 Jul 2017 11:38:18 +0000 Message-ID: References: <1500548318-23170-1-git-send-email-bogdan.purcareata@nxp.com> <20170720111733.vjn3i2s3shzf7u4d@mwanda> In-Reply-To: <20170720111733.vjn3i2s3shzf7u4d@mwanda> Accept-Language: en-US Content-Language: en-US X-MS-Has-Attach: X-MS-TNEF-Correlator: authentication-results: oracle.com; dkim=none (message not signed) header.d=none;oracle.com; dmarc=none action=none header.from=nxp.com; x-originating-ip: [192.88.146.1] x-ms-publictraffictype: Email x-microsoft-exchange-diagnostics: 1;DB6PR0402MB2838;7:GLJAyK6vAnxzJOpmXU9esnk3orNHM0ZOUu+VQ6+7Tc1pUqQO7poa8XnOgmbGq2wOFYi5gsNOI3pfI4zqkI10CouaSUxVYrkpvkggeWL/SwTD+9YW5nqBncgWhPjx6gppy+aeKetX9uhWFBse3vNd5f4O5C71lBY0LQIwyJ3yZlbD0/0Fa91Ym37j18X1dzr/WECfPwKU8blkIb8eAoY8KgRK0UCRbVG+turbeu2TuQoz37nh3yQKzTOfRzc4ciY1Ws8A4gXW7SKkx4BfroAeeSSxbQUbv9P7Dq8vWIYJiIHnabLyFb2bzxs8OYTfiof2JpCDMJ19SyWN4jmCK8wdd2yPRHY5P3cStykuOi/8z0S/L42MY52MKMzkkRqElu2xG/iv7lPYUWUUhL7aA90t9J0xXrF6baJ/NMRagvEXgxw+SrMciN5A0iQ/cSyXN9ozKn3HtNlxuJ/5+ZrxexBnxJyQab6ixzqXP3n/9uZIS0mH3PO9ShbFhA0kDvfiyLE4rLJ9Aia5vO3R5wJgPtUzMC+vRh7f9EC82IkHS7Gsh/oLTvBXxOL05+2GS9ifww/CNxuvk4wC3Cd0hcf/v/yuOXvn9sU027ih+AhOxQlh4XEGfI0DWzuVuJ6+k+KI/StkqxE99lHDzBMFcIQiOaQArr7nbKCWfn7vqa0PaDqD8xoCiPrn8NlGU4OwF6vLJQaFyFOmCtwYIRZObvG6vwYPmzIr5dc7/s/3aONTZ3co7XSFBUVzWteGCfFvAJgce81Md1HoogsqUFzAUPXf5iV37VDZFWMBsGlmfsJ5nZy9l6g= x-forefront-antispam-report: SFV:SKI;SCL:-1SFV:NSPM;SFS:(10009020)(6009001)(39400400002)(39850400002)(39410400002)(39450400003)(39860400002)(39840400002)(24454002)(13464003)(377454003)(3280700002)(66066001)(74316002)(305945005)(6506006)(25786009)(3660700001)(4326008)(38730400002)(53936002)(2900100001)(99286003)(6436002)(55016002)(54906002)(9686003)(14454004)(81166006)(2906002)(110136004)(86362001)(575784001)(8676002)(6246003)(5250100002)(7736002)(53546010)(2950100002)(6916009)(189998001)(8936002)(33656002)(229853002)(478600001)(7696004)(76176999)(6116002)(3846002)(5660300001)(102836003)(50986999)(54356999);DIR:OUT;SFP:1101;SCL:1;SRVR:DB6PR0402MB2838;H:DB5PR04MB1240.eurprd04.prod.outlook.com;FPR:;SPF:None;MLV:sfv;LANG:en; x-ms-office365-filtering-correlation-id: 29f04aca-4ec4-4d71-1d53-08d4cf63d159 x-ms-office365-filtering-ht: Tenant x-microsoft-antispam: UriScan:;BCL:0;PCL:0;RULEID:(300000500095)(300135000095)(300000501095)(300135300095)(22001)(300000502095)(300135100095)(2017030254075)(300000503095)(300135400095)(48565401081)(2017052603031)(201703131423075)(201703031133081)(300000504095)(300135200095)(300000505095)(300135600095)(300000506095)(300135500095);SRVR:DB6PR0402MB2838; x-ms-traffictypediagnostic: DB6PR0402MB2838: x-exchange-antispam-report-test: UriScan:(236129657087228)(9452136761055)(185117386973197)(146099531331640)(209349559609743); x-microsoft-antispam-prvs: x-exchange-antispam-report-cfa-test: BCL:0;PCL:0;RULEID:(100000700101)(100105000095)(100000701101)(100105300095)(100000702101)(100105100095)(6040450)(601004)(2401047)(8121501046)(5005006)(2017060910075)(93006095)(93001095)(10201501046)(100000703101)(100105400095)(3002001)(6055026)(6041248)(20161123560025)(20161123555025)(20161123564025)(20161123562025)(20161123558100)(201703131423075)(201702281528075)(201703061421075)(201703061406153)(6072148)(100000704101)(100105200095)(100000705101)(100105500095);SRVR:DB6PR0402MB2838;BCL:0;PCL:0;RULEID:(100000800101)(100110000095)(100000801101)(100110300095)(100000802101)(100110100095)(100000803101)(100110400095)(100000804101)(100110200095)(100000805101)(100110500095);SRVR:DB6PR0402MB2838; x-forefront-prvs: 0374433C81 spamdiagnosticoutput: 1:99 spamdiagnosticmetadata: NSPM Content-Type: text/plain; charset="us-ascii" MIME-Version: 1.0 X-OriginatorOrg: nxp.com X-MS-Exchange-CrossTenant-originalarrivaltime: 20 Jul 2017 11:38:18.5509 (UTC) X-MS-Exchange-CrossTenant-fromentityheader: Hosted X-MS-Exchange-CrossTenant-id: 686ea1d3-bc2b-4c6f-a92c-d99c5c301635 X-MS-Exchange-Transport-CrossTenantHeadersStamped: DB6PR0402MB2838 Sender: linux-kernel-owner@vger.kernel.org List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Content-Transfer-Encoding: 8bit X-MIME-Autoconverted: from quoted-printable to 8bit by nfs id v6KBcUxs015652 Content-Length: 2053 Lines: 42 > -----Original Message----- > From: Dan Carpenter [mailto:dan.carpenter@oracle.com] > Sent: Thursday, July 20, 2017 2:18 PM > To: Bogdan Purcareata > Cc: Ruxandra Ioana Radulescu ; > gregkh@linuxfoundation.org; linux-kernel@vger.kernel.org; > devel@driverdev.osuosl.org > Subject: Re: [PATCH 1/2] staging: fsl-dpaa2/eth: Fix skb use after free > > On Thu, Jul 20, 2017 at 10:58:37AM +0000, Bogdan Purcareata wrote: > > Once a Tx frame descriptor is enqueued, an interrupt might be triggered > > to process the Tx confirmation and free the skb, hitting a memory use > > after free when updating the tx_bytes statistic based on skb->len. > > > > Use the frame descriptor length instead. > > > > Signed-off-by: Bogdan Purcareata > > --- > > drivers/staging/fsl-dpaa2/ethernet/dpaa2-eth.c | 2 +- > > 1 file changed, 1 insertion(+), 1 deletion(-) > > > > diff --git a/drivers/staging/fsl-dpaa2/ethernet/dpaa2-eth.c > b/drivers/staging/fsl-dpaa2/ethernet/dpaa2-eth.c > > index b9a0a31..0f3e497 100644 > > --- a/drivers/staging/fsl-dpaa2/ethernet/dpaa2-eth.c > > +++ b/drivers/staging/fsl-dpaa2/ethernet/dpaa2-eth.c > > @@ -616,7 +616,7 @@ static netdev_tx_t dpaa2_eth_tx(struct sk_buff *skb, > struct net_device *net_dev) > > free_tx_fd(priv, &fd, NULL); > > } else { > > percpu_stats->tx_packets++; > > - percpu_stats->tx_bytes += skb->len; > > + percpu_stats->tx_bytes += dpaa2_fd_get_len(&fd); > > This feels like the wrong thing. Can't we just save skb->len earlier > in the function and use it here? This is the common case right? So > we'd be saving slightly wrong information for almost every packet. The "len" field in the frame descriptor means the length of the actual data, like the "len" field in the skb. It's set to skb->len both for linear (build_single_fd) and fragmented (build_sg_fd) skbs. I thought it would be more straightforward to use it rather than define an additional local variable solely for this purpose. Thank you! Bogdan P.