Received: by 10.213.65.68 with SMTP id h4csp2147294imn; Sun, 8 Apr 2018 20:56:48 -0700 (PDT) X-Google-Smtp-Source: AIpwx4+t96HY97igbLb6On+Czm4jGqAYJMLW4CzoyvieIHz5kOpjzKx4kKUAgxM7FtVZ5+AY4UPG X-Received: by 2002:a17:902:8d82:: with SMTP id v2-v6mr37453455plo.101.1523246208708; Sun, 08 Apr 2018 20:56:48 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1523246208; cv=none; d=google.com; s=arc-20160816; b=dzl/MBDKub/DpE/Fz6nDq3GjkYNEFk6QfAtAbNjcs4TPHLlFRoYGO7tFt0nZ72IBRt /ItsEhx2G37f1AUgjqF2gJqPzPWiTmk9HSvVFbD4YhKMY83CotwdtHCwr/ZIHZp7rbi3 DNcVHT7mDApV5+V3mEMDcfYqyexN5rIlGt+TYM3gaO6WETFya2xXvhVDQGKY3H0+3DFq DzHRq0SP4osk/e2s0s6MYnq0/2U8p26JfC7WAIW9fM84CLcp3EAmGnnM8r+/Ygp+NK+o rpJfOD7BUIwzd0am3C5TyRrSuz6zOnzUsEBq6RNRBe2OY5OsKP9kZfPcoTtlOxWwTb1l euZw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:mime-version:content-transfer-encoding :spamdiagnosticmetadata:spamdiagnosticoutput:content-language :accept-language:in-reply-to:references:message-id:date:thread-index :thread-topic:subject:cc:to:from:dkim-signature :arc-authentication-results; bh=ynQjRCtn02SgZ6Y4sKpMZbj9uyTwC2zSxCFbk0h37vk=; b=LwL7jwCLK7+gU1zePXoyngqspXgyINom4CTYI/n3AIxL8z7+tVLEGNMIvvlKKiRe40 F4RUPx+dPoSSv7+W0uaz31zZRJ/6uMCoIZM1U2DXLsCE7c6H4DSDDnYnDS7ycjfXYx3L gstAB9GG2eBURp07ByahN4UfN5M3VnaY/I/xhfuLn+xnIWFSwCT6zOlP/gq7tpFAL/r7 /HfbFMHzpEmP2GCvUh36vCGalX4FyoPxDk1BKHzcBiuNPMFWzMLoV+y80Ck3ySZ1jnT5 /4nyuPDExpa44EIGqhCE4WQg0atU3TYyGpIqdUv2yDYnShqJhuSGpceqvis9dxqQrxTo OdkQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@microsoft.com header.s=selector1 header.b=JvSCoUZG; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=REJECT sp=REJECT dis=NONE) header.from=microsoft.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id 60-v6si15437064plb.679.2018.04.08.20.56.11; Sun, 08 Apr 2018 20:56:48 -0700 (PDT) Received-SPF: pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; dkim=pass header.i=@microsoft.com header.s=selector1 header.b=JvSCoUZG; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=REJECT sp=REJECT dis=NONE) header.from=microsoft.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1754768AbeDIDui (ORCPT + 99 others); Sun, 8 Apr 2018 23:50:38 -0400 Received: from mail-by2nam03on0122.outbound.protection.outlook.com ([104.47.42.122]:11088 "EHLO NAM03-BY2-obe.outbound.protection.outlook.com" rhost-flags-OK-OK-OK-FAIL) by vger.kernel.org with ESMTP id S1754057AbeDIAT3 (ORCPT ); Sun, 8 Apr 2018 20:19:29 -0400 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=microsoft.com; s=selector1; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version; bh=ynQjRCtn02SgZ6Y4sKpMZbj9uyTwC2zSxCFbk0h37vk=; b=JvSCoUZGnXUBqPyWun30wk2QYUbzOVoaNzhvXX2Kec0HVDwAOH4D4rYI6rFW5qUUPhSI+c/3letzpmt4cZiUfQI4EXdKAPe4+pvtv1aYOrqjUxiowMvQ0KgxkORNKds8raa0+/WwIQU/B/zQsyptCodZZOj5HSjP8wRRgO1M7M8= Received: from DM5PR2101MB1032.namprd21.prod.outlook.com (52.132.128.13) by DM5PR2101MB1063.namprd21.prod.outlook.com (52.132.128.39) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.696.0; Mon, 9 Apr 2018 00:19:23 +0000 Received: from DM5PR2101MB1032.namprd21.prod.outlook.com ([fe80::8109:aef0:a777:7059]) by DM5PR2101MB1032.namprd21.prod.outlook.com ([fe80::8109:aef0:a777:7059%2]) with mapi id 15.20.0696.003; Mon, 9 Apr 2018 00:19:23 +0000 From: Sasha Levin To: "stable@vger.kernel.org" , "linux-kernel@vger.kernel.org" CC: Andy Spencer , "David S . Miller" , Sasha Levin Subject: [PATCH AUTOSEL for 4.15 107/189] gianfar: prevent integer wrapping in the rx handler Thread-Topic: [PATCH AUTOSEL for 4.15 107/189] gianfar: prevent integer wrapping in the rx handler Thread-Index: AQHTz5g96A+9eAIDV0Sr+epalbYDjw== Date: Mon, 9 Apr 2018 00:18:10 +0000 Message-ID: <20180409001637.162453-107-alexander.levin@microsoft.com> References: <20180409001637.162453-1-alexander.levin@microsoft.com> In-Reply-To: <20180409001637.162453-1-alexander.levin@microsoft.com> Accept-Language: en-US Content-Language: en-US X-MS-Has-Attach: X-MS-TNEF-Correlator: x-originating-ip: [52.168.54.252] x-ms-publictraffictype: Email x-microsoft-exchange-diagnostics: 1;DM5PR2101MB1063;7:05w1PrN2NKZsKff+WEADUBs1vfOonZyUdmPC7sZ6kt6oJAeAtbDQM1YyBjtHiv9glM6NNiSmIe4U48nHTaHmcywLsx5YTLIu4S5YkfctQO6S/i0/4yNtE03oJSqXSxlSVQ61ffqpwbbAJl3UmQfxIqIkOkTZsMvjcQhCIjuVXCJywn2exhW8qq56+IUO4U/KauZqbVxrwghp+zvu9iYp7v2YLjP/k+tUN5TaFm66GDgAT0ir/o0CAWYjyoj5UdOr;20:eCA/9Zh3ZpYv4OFuDfoZME1ylUrD14frlfJGcpQgLe6ez5pPQaq/DxYrhSd72fE6eUGmgCeZ1xn3aI1Z3MvuQ3TQ7U7di69A5O8tugIQAq+8xoz+/aC6UAolLnyFARh3oKtmiWOad35X+Tb7QN9de1S5sNh/q5iKl0bhrMCIv1s= x-ms-office365-filtering-ht: Tenant X-MS-Office365-Filtering-Correlation-Id: 6861b55f-a983-4d98-514b-08d59daf8bfd x-microsoft-antispam: UriScan:;BCL:0;PCL:0;RULEID:(7020095)(4652020)(48565401081)(5600026)(4604075)(3008032)(4534165)(4627221)(201703031133081)(201702281549075)(2017052603328)(7193020);SRVR:DM5PR2101MB1063; x-ms-traffictypediagnostic: DM5PR2101MB1063: authentication-results: spf=none (sender IP is ) smtp.mailfrom=Alexander.Levin@microsoft.com; x-microsoft-antispam-prvs: x-exchange-antispam-report-test: UriScan:(28532068793085)(89211679590171); x-exchange-antispam-report-cfa-test: BCL:0;PCL:0;RULEID:(8211001083)(61425038)(6040522)(2401047)(5005006)(8121501046)(93006095)(93001095)(3231221)(944501327)(52105095)(3002001)(10201501046)(6055026)(61426038)(61427038)(6041310)(20161123558120)(20161123562045)(20161123560045)(201703131423095)(201702281528075)(20161123555045)(201703061421075)(201703061406153)(20161123564045)(6072148)(201708071742011);SRVR:DM5PR2101MB1063;BCL:0;PCL:0;RULEID:;SRVR:DM5PR2101MB1063; x-forefront-prvs: 0637FCE711 x-forefront-antispam-report: SFV:NSPM;SFS:(10019020)(346002)(39380400002)(39860400002)(376002)(396003)(366004)(189003)(199004)(2900100001)(6436002)(7736002)(10090500001)(102836004)(3660700001)(6506007)(76176011)(305945005)(4326008)(5250100002)(97736004)(26005)(25786009)(6512007)(2906002)(81166006)(106356001)(107886003)(68736007)(14454004)(86612001)(66066001)(10290500003)(6666003)(5660300001)(81156014)(478600001)(476003)(486006)(6486002)(72206003)(3280700002)(99286004)(105586002)(36756003)(1076002)(2616005)(11346002)(53936002)(446003)(8676002)(186003)(3846002)(54906003)(6116002)(2501003)(8936002)(316002)(110136005)(575784001)(86362001)(22452003)(22906009)(217873001);DIR:OUT;SFP:1102;SCL:1;SRVR:DM5PR2101MB1063;H:DM5PR2101MB1032.namprd21.prod.outlook.com;FPR:;SPF:None;LANG:en;PTR:InfoNoRecords;MX:1;A:1; received-spf: None (protection.outlook.com: microsoft.com does not designate permitted sender hosts) x-microsoft-antispam-message-info: EtLrxx3QekQK7qgr1L0lSadtHPHPsyYAnbA2QH985/SeoU+DgU/+Nr5TdkO69484562OU6kat/83I1OBEj/SWi8KnjAw2wjnF+ibtypMjB6Jsh5AWNSNPvuMXRnMUc30zk4ng+NySI7RU1nH0PdRea7F7BzfynM/9AA6lrhmYMzXhG/57dH4G28vG4O1WLqG/42kSUloWP96vEujpM2WMjIfo2SSGa4AuBMIjGpuNEPC39jO2tE2wFGEgcNPcIVObGSIY+CCet9pWSOVLLpf3E5kXr1YTSO3y2gxoXXYIacZcSit0fTbD/1CxrreC8F4vHhaFOsysiK6rNGpzpclR2Z6lSJAL1wVrwwc2Mo1nGFMba9IyWvVzdev7frHtoO9qN2YczrtDYEeTa/S5DqQCzcHwl7DczCycj/OaeWaEvM= spamdiagnosticoutput: 1:99 spamdiagnosticmetadata: NSPM Content-Type: text/plain; charset="iso-8859-1" Content-Transfer-Encoding: quoted-printable MIME-Version: 1.0 X-OriginatorOrg: microsoft.com X-MS-Exchange-CrossTenant-Network-Message-Id: 6861b55f-a983-4d98-514b-08d59daf8bfd X-MS-Exchange-CrossTenant-originalarrivaltime: 09 Apr 2018 00:18:10.3812 (UTC) X-MS-Exchange-CrossTenant-fromentityheader: Hosted X-MS-Exchange-CrossTenant-id: 72f988bf-86f1-41af-91ab-2d7cd011db47 X-MS-Exchange-Transport-CrossTenantHeadersStamped: DM5PR2101MB1063 Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org From: Andy Spencer [ Upstream commit 202a0a70e445caee1d0ec7aae814e64b1189fa4d ] When the frame check sequence (FCS) is split across the last two frames of a fragmented packet, part of the FCS gets counted twice, once when subtracting the FCS, and again when subtracting the previously received data. For example, if 1602 bytes are received, and the first fragment contains the first 1600 bytes (including the first two bytes of the FCS), and the second fragment contains the last two bytes of the FCS: 'skb->len =3D=3D 1600' from the first fragment size =3D lstatus & BD_LENGTH_MASK; # 1602 size -=3D ETH_FCS_LEN; # 1598 size -=3D skb->len; # -2 Since the size is unsigned, it wraps around and causes a BUG later in the packet handling, as shown below: kernel BUG at ./include/linux/skbuff.h:2068! Oops: Exception in kernel mode, sig: 5 [#1] ... NIP [c021ec60] skb_pull+0x24/0x44 LR [c01e2fbc] gfar_clean_rx_ring+0x498/0x690 Call Trace: [df7edeb0] [c01e2c1c] gfar_clean_rx_ring+0xf8/0x690 (unreliable) [df7edf20] [c01e33a8] gfar_poll_rx_sq+0x3c/0x9c [df7edf40] [c023352c] net_rx_action+0x21c/0x274 [df7edf90] [c0329000] __do_softirq+0xd8/0x240 [df7edff0] [c000c108] call_do_irq+0x24/0x3c [c0597e90] [c00041dc] do_IRQ+0x64/0xc4 [c0597eb0] [c000d920] ret_from_except+0x0/0x18 --- interrupt: 501 at arch_cpu_idle+0x24/0x5c Change the size to a signed integer and then trim off any part of the FCS that was received prior to the last fragment. Fixes: 6c389fc931bc ("gianfar: fix size of scatter-gathered frames") Signed-off-by: Andy Spencer Signed-off-by: David S. Miller Signed-off-by: Sasha Levin --- drivers/net/ethernet/freescale/gianfar.c | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/drivers/net/ethernet/freescale/gianfar.c b/drivers/net/etherne= t/freescale/gianfar.c index 7f837006bb6a..3bdeb295514b 100644 --- a/drivers/net/ethernet/freescale/gianfar.c +++ b/drivers/net/ethernet/freescale/gianfar.c @@ -2932,7 +2932,7 @@ static irqreturn_t gfar_transmit(int irq, void *grp_i= d) static bool gfar_add_rx_frag(struct gfar_rx_buff *rxb, u32 lstatus, struct sk_buff *skb, bool first) { - unsigned int size =3D lstatus & BD_LENGTH_MASK; + int size =3D lstatus & BD_LENGTH_MASK; struct page *page =3D rxb->page; bool last =3D !!(lstatus & BD_LFLAG(RXBD_LAST)); =20 @@ -2947,11 +2947,16 @@ static bool gfar_add_rx_frag(struct gfar_rx_buff *r= xb, u32 lstatus, if (last) size -=3D skb->len; =20 - /* in case the last fragment consisted only of the FCS */ + /* Add the last fragment if it contains something other than + * the FCS, otherwise drop it and trim off any part of the FCS + * that was already received. + */ if (size > 0) skb_add_rx_frag(skb, skb_shinfo(skb)->nr_frags, page, rxb->page_offset + RXBUF_ALIGNMENT, size, GFAR_RXB_TRUESIZE); + else if (size < 0) + pskb_trim(skb, skb->len + size); } =20 /* try reuse page */ --=20 2.15.1