From patchwork Wed Feb 21 11:35:40 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Rafael Vuijk X-Patchwork-Id: 10232013 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork.web.codeaurora.org (Postfix) with ESMTP id 4653860392 for ; Wed, 21 Feb 2018 11:36:01 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 3B76728AE2 for ; Wed, 21 Feb 2018 11:36:01 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 3018E28AE9; Wed, 21 Feb 2018 11:36:01 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-6.8 required=2.0 tests=BAYES_00,DKIM_SIGNED, RCVD_IN_DNSWL_HI,T_DKIM_INVALID autolearn=ham version=3.3.1 Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id E42AF28AE2 for ; Wed, 21 Feb 2018 11:35:59 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S932123AbeBULf5 (ORCPT ); Wed, 21 Feb 2018 06:35:57 -0500 Received: from mail-db5eur01on0077.outbound.protection.outlook.com ([104.47.2.77]:35072 "EHLO EUR01-DB5-obe.outbound.protection.outlook.com" rhost-flags-OK-OK-OK-FAIL) by vger.kernel.org with ESMTP id S1753391AbeBULfy (ORCPT ); Wed, 21 Feb 2018 06:35:54 -0500 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=sownet.onmicrosoft.com; s=selector1-sownet-nl; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version; bh=pjAkoZt/Lf6PNS4x1RKtvqzczlH5QU9sxRXbMrjz+Ng=; b=2gpaUjIocgW81kfUQnM3uW6JpgVHlliViS0JaxLFYn9YSv2pD5Ow25sbuH0mgEzS6/4U0Mane8FRfRfh1IfrmQqM5vIuXIFSNar4Fkff2lftbyKPTcVwZ5QRnQpXxBTvwzqq+90mJ1N2yVUDmRGFvt1NoOFAJ93K3Wq5QK3LNGU= Received: from Rafael-Mac.intra.sownet.nl (2001:982:c549:1:a06a:c4a2:131d:aa6f) by AM4PR10MB0161.EURPRD10.PROD.OUTLOOK.COM (2603:10a6:200:2a::17) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_CBC_SHA384_P256) id 15.20.506.18; Wed, 21 Feb 2018 11:35:51 +0000 Date: Wed, 21 Feb 2018 12:35:40 +0100 From: Rafael Vuijk To: Alexander Aring , Jukka Rissanen Cc: linux-wpan@vger.kernel.org, linux-bluetooth@vger.kernel.org Subject: [PATCH] ieee802154: assembly of 6LoWPAN fragments improvement Message-ID: <20180221113540.GA54319@Rafael-Mac.intra.sownet.nl> MIME-Version: 1.0 Content-Disposition: inline User-Agent: Mutt/1.9.3 (2018-01-21) X-Originating-IP: [2001:982:c549:1:a06a:c4a2:131d:aa6f] X-ClientProxiedBy: HE1PR08CA0077.eurprd08.prod.outlook.com (2603:10a6:7:2a::48) To AM4PR10MB0161.EURPRD10.PROD.OUTLOOK.COM (2603:10a6:200:2a::17) X-MS-PublicTrafficType: Email X-MS-Office365-Filtering-Correlation-Id: 236da97b-745f-4729-3877-08d5791f4303 X-Microsoft-Antispam: UriScan:; BCL:0; PCL:0; RULEID:(7020095)(4652020)(7021125)(4534165)(7022125)(4603075)(4627221)(201702281549075)(7048125)(7024125)(7027125)(7028125)(7023125)(5600026)(4604075)(2017052603307)(7153060)(7193020); SRVR:AM4PR10MB0161; X-Microsoft-Exchange-Diagnostics: 1; AM4PR10MB0161; 3:SQdDphHKE3TWvcS5VKewrVT/iZzxYvfxYeT1N8hTt3RwQEdJN8bvAYeuQnxqRUbStMrSOtIEH5A3++9TaeYWKwOiPfuGSN/COja+jWk2SIp4CbTIrPN77axxBcUnDBC7Lc+51WoiGQ/P+TyCj6NyuOFqLFT/b1VbKipWnmKrtdGfJ2+fhTGsyi9Wblr0macFS3u/lRUhSHl5N3+NznrLWWKhb/IzoPLm9Otocbfu/6zWWinIlHM7bJ7mNu8fPzOK; 25:QAdMwT2C8eMTHjJnNHEDcV1BsQ/5khfUc1E6rfYBCY5DdixNFKNqX4w8PDMJ6jhx3uFFagw+B4vlE4I0Kh1moK8pxtI6wAfxjunzfSvQV/3w1hMh9dkz5vjUwcHI7g/pBr4oLk4+WHoDZTwauKzxI1se2sq/8dlG7FDJNV8IPeyvXEuVJZrcUW2aWh5GbotpGay3ZipS5Hgt+fCT3js9ZFf+ZC9eGIdrwsC37uQPWNg338GWqP67h41J9nutogMQMglNrD64uLLFrHnuoCiqmwJpk2UwbJDv5Hed0lMlIzBf+y4flvTDrIxcJoiHsN6dYlXwm1Fu6PpVNqnyrPKAyg==; 31:eDK1OcqvD1sZqNoCjfgDwc9MlQrGQUGMCkZcaeawIHXtH8zcMszhekpTGDXD/X4bkXB3EyyyuaFpOV+ExSRaQ2gHnLO4IA+YEsaHD8t2cgZdYZocOa2YkHTTOLn9RQ0HRkVBbxRa0GIefEjthvAMHTGtmM1R9rzmYJx59bYDnaNnGubjyjsk4szYUgMKaThqMcs4y06fHZnN5Gp84Bv4cso/Pd+x8GVmw+/7kI1qWhA= X-MS-TrafficTypeDiagnostic: AM4PR10MB0161: Authentication-Results: spf=none (sender IP is ) smtp.mailfrom=r.vuijk@sownet.nl; X-Microsoft-Antispam-PRVS: X-Exchange-Antispam-Report-Test: UriScan:; X-Exchange-Antispam-Report-CFA-Test: BCL:0; PCL:0; RULEID:(6040501)(2401047)(5005006)(8121501046)(3231101)(944501161)(93006095)(93001095)(10201501046)(3002001)(6041288)(2016111802025)(20161123562045)(20161123558120)(20161123560045)(20161123564045)(6043046)(6072148)(201708071742011); SRVR:AM4PR10MB0161; BCL:0; PCL:0; RULEID:; SRVR:AM4PR10MB0161; X-Microsoft-Exchange-Diagnostics: 1; AM4PR10MB0161; 4:IhhCnPzbHaJqP69KEZyNfAHlhg0hKYHZxWTFR2hg16j7Q0Ut58prr6Nbur8rj5g2s0BADBb+zfbDSimftnSgqhczWdDJv0n5gxucZnlxIWX3CFddriFBdCgqAcZ8lES5eZPav1vZbL+ntoUxM50qjAMHBmLOwwBIUyrCNdEpVZF39AOWmV9DNVGa8k1nkMdJSWecT4GHlHcHoc8djFJ0OitnwtnJ2rqey+JhKLqGM/dAwGhSzu0rgsYY6v5xVgwsTnNJ2ury6VLfMT8aWcfKqQ== X-Forefront-PRVS: 0590BBCCBC X-Forefront-Antispam-Report: SFV:NSPM; SFS:(10009020)(396003)(39380400002)(346002)(39830400003)(366004)(376002)(377424004)(199004)(189003)(316002)(52396003)(305945005)(97736004)(74482002)(105586002)(50466002)(110136005)(16526019)(6116002)(2906002)(186003)(23726003)(55016002)(1076002)(106356001)(86362001)(68736007)(1857600001)(58126008)(386003)(53936002)(8676002)(52116002)(7696005)(39060400002)(6666003)(16586007)(25786009)(5660300001)(47776003)(81166006)(81156014)(8936002)(7736002)(33656002)(478600001)(4326008)(18370500001); DIR:OUT; SFP:1101; SCL:1; SRVR:AM4PR10MB0161; H:Rafael-Mac.intra.sownet.nl; FPR:; SPF:None; PTR:InfoNoRecords; A:1; MX:1; LANG:en; Received-SPF: None (protection.outlook.com: sownet.nl does not designate permitted sender hosts) X-Microsoft-Exchange-Diagnostics: =?us-ascii?Q?1; AM4PR10MB0161; 23:ZnV/qyEenpfTqJ19yiMDbgbHtydLxsAUNJ2QRBK4Y?= =?us-ascii?Q?rKHMIB66kpKZHi2nmsiQHhUJG9tt+4mbHcUv6F9B0ImNPSTuGOB0UL+rgsAE?= =?us-ascii?Q?96pMiBWs7Ogo+3Jt3BlxbWwlO0BqSeQM192bQ07Rvsa5UgXfXRDLrNKMql7N?= =?us-ascii?Q?2vmBE/Mo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iagnosticMetadata: NSPM X-OriginatorOrg: sownet.nl X-MS-Exchange-CrossTenant-OriginalArrivalTime: 21 Feb 2018 11:35:51.3962 (UTC) X-MS-Exchange-CrossTenant-Network-Message-Id: 236da97b-745f-4729-3877-08d5791f4303 X-MS-Exchange-CrossTenant-FromEntityHeader: Hosted X-MS-Exchange-CrossTenant-Id: b942e044-b452-4fc3-a156-54104fe5c4b6 X-MS-Exchange-Transport-CrossTenantHeadersStamped: AM4PR10MB0161 Sender: linux-wpan-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-wpan@vger.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP Hi, We have tested the 6LoWPAN modules in the Linux kernel and came to some issue regarding fragmentation. We have seen aborted SCP transfers ("message authentication code incorrect") and tested TCP transfers as well and saw corruption on fragment-sized intervals. The current fragment assembling functions do not check enough for corrupted L2 packets that might slip through L2 CRC check. (in our case IEEE802.15.4 which has only 16-bit CRC). As a result, overlapping fragments due to offset corruption are not detected and assembled incorrectly. Part of packets may have old data. At TCP-level, there is only a simple TCP-checksum which is not enough in this case as the corruption occurs frequently (once every few minutes). After quickly analysing the code we saw some potential issues and created a patch that adds additional overlap checks and simplifies some conditional statements. After running tests again, TCP corruption was not seen again. The test was performed with SCP and keeps transferring large files now without error. Rafael Vuijk Signed-off-by: Rafael Vuijk --- -- To unsubscribe from this list: send the line "unsubscribe linux-wpan" in the body of a message to majordomo@vger.kernel.org More majordomo info at http://vger.kernel.org/majordomo-info.html --- ./net/ieee802154/6lowpan/reassembly.c 2018-02-20 11:10:06.000000000 +0100 +++ ./net/ieee802154/6lowpan/reassembly.c 2018-02-21 09:13:29.000000000 +0100 @@ -140,23 +140,14 @@ static int lowpan_frag_queue(struct lowp offset = lowpan_802154_cb(skb)->d_offset << 3; end = lowpan_802154_cb(skb)->d_size; + if (fq->q.len == 0) + fq->q.len = end; + if (fq->q.len != end) + goto err; + /* Is this the final fragment? */ if (offset + skb->len == end) { - /* If we already have some bits beyond end - * or have different end, the segment is corrupted. - */ - if (end < fq->q.len || - ((fq->q.flags & INET_FRAG_LAST_IN) && end != fq->q.len)) - goto err; fq->q.flags |= INET_FRAG_LAST_IN; - fq->q.len = end; - } else { - if (end > fq->q.len) { - /* Some bits beyond end -> corruption. */ - if (fq->q.flags & INET_FRAG_LAST_IN) - goto err; - fq->q.len = end; - } } /* Find out which fragments are in front and at the back of us @@ -179,6 +170,13 @@ static int lowpan_frag_queue(struct lowp } found: + /* Current fragment overlaps with previous fragment? */ + if (prev && (lowpan_802154_cb(prev)->d_offset << 3) + prev->len > offset) + goto err; + /* Current fragment overlaps with next fragment? */ + if (next && offset + skb->len > lowpan_802154_cb(next)->d_offset << 3) + goto err; + /* Insert this fragment in the chain of fragments. */ skb->next = next; if (!next)