From patchwork Mon Dec 21 01:15:33 2015 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Brad Campbell X-Patchwork-Id: 7892911 Return-Path: X-Original-To: patchwork-linux-wpan@patchwork.kernel.org Delivered-To: patchwork-parsemail@patchwork2.web.kernel.org Received: from mail.kernel.org (mail.kernel.org [198.145.29.136]) by patchwork2.web.kernel.org (Postfix) with ESMTP id 744C0BEEE5 for ; Mon, 21 Dec 2015 01:16:10 +0000 (UTC) Received: from mail.kernel.org (localhost [127.0.0.1]) by mail.kernel.org (Postfix) with ESMTP id 9A38A203AB for ; Mon, 21 Dec 2015 01:16:09 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id BD5C4203AA for ; Mon, 21 Dec 2015 01:16:08 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1751195AbbLUBQI (ORCPT ); Sun, 20 Dec 2015 20:16:08 -0500 Received: from mail-ig0-f178.google.com ([209.85.213.178]:38197 "EHLO mail-ig0-f178.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1750863AbbLUBQH (ORCPT ); Sun, 20 Dec 2015 20:16:07 -0500 Received: by mail-ig0-f178.google.com with SMTP id jw2so26399600igc.1 for ; Sun, 20 Dec 2015 17:16:07 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113; h=from:to:cc:subject:date:message-id:in-reply-to:references; bh=j6E8HJS0OBzRbbY6ePbptzWksBXy3grztiRiAS5LJEA=; b=KDIE+/fUJ9fzC8WDK6guNOG0iPwEKr7Db5qakaUH4Kj4Aj+epwUHEl77z9R58pZFf7 M7iTm5U3qqQLLn2qzhGjkJXXxsSGjLviRZ99UShQd+IuUR2u8h/xTyMoLC7b9fSasDem 5nbCJg1NAav1mYeZmxqmzgOSZ/8+CIIlOWbJfZ33F1iqUTl4YFrnO1WIhRkXT/6/AqC1 bW0jD0vq2pECLg3DOgTpW+/BGbvbMBkNN3pHmkeBa/SdGV44Uib+3AMYBE6ug7P4uO38 uysPNKMNiUltYpnIjNJ5F3OJhVbaknraJBLL4/hjKqp83ED2LxDOTbTGNO0zZy6Ar9PW JQIA== X-Received: by 10.50.43.199 with SMTP id y7mr15514203igl.47.1450660567112; Sun, 20 Dec 2015 17:16:07 -0800 (PST) Received: from localhost.localdomain ([141.212.11.53]) by smtp.gmail.com with ESMTPSA id e5sm11080473ioj.40.2015.12.20.17.16.06 (version=TLS1_2 cipher=ECDHE-RSA-AES128-SHA bits=128/128); Sun, 20 Dec 2015 17:16:06 -0800 (PST) From: Brad Campbell To: Varka Bhadram , Alexander Aring , linux-wpan@vger.kernel.org Cc: Brad Campbell Subject: [PATCH 1/1] ieee802154-cc2520: Check CRC Date: Sun, 20 Dec 2015 20:15:33 -0500 Message-Id: <1450660533-38184-2-git-send-email-bradjc5@gmail.com> X-Mailer: git-send-email 2.6.3 In-Reply-To: <1450660533-38184-1-git-send-email-bradjc5@gmail.com> References: <1450660533-38184-1-git-send-email-bradjc5@gmail.com> Sender: linux-wpan-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-wpan@vger.kernel.org X-Spam-Status: No, score=-6.8 required=5.0 tests=BAYES_00, DKIM_ADSP_CUSTOM_MED, DKIM_SIGNED, FREEMAIL_FROM, RCVD_IN_DNSWL_HI, RP_MATCHES_RCVD, T_DKIM_INVALID, UNPARSEABLE_RELAY autolearn=ham version=3.3.1 X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on mail.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP Add checking the "CRC_OK" bit at the end of incoming packets to make sure the cc2520 driver only passes up valid packets. Because the AUTOCRC bit in the FRMCTRL0 register is set to 1 after init, the CC2520 handles checking the CRC of incoming packets and sets the most significant bit of the last byte of the incoming packet to 1 if the check passed. This patch simply checks that bit. Signed-off-by: Brad Campbell --- drivers/net/ieee802154/cc2520.c | 11 +++++++++++ 1 file changed, 11 insertions(+) diff --git a/drivers/net/ieee802154/cc2520.c b/drivers/net/ieee802154/cc2520.c index e65b605..b54edbf 100644 --- a/drivers/net/ieee802154/cc2520.c +++ b/drivers/net/ieee802154/cc2520.c @@ -450,6 +450,17 @@ cc2520_read_rxfifo(struct cc2520_private *priv, u8 *data, u8 len, u8 *lqi) mutex_unlock(&priv->buffer_mutex); + /* If we are reading the actual packet and not just the length byte, + * check that the CRC is valid. + */ + if (len > 1) { + /* Most significant bit of the last byte of the data buffer + * is a 1 bit CRC indicator. See section 20.3.4. + */ + if (data[len - 1] >> 7 == 0) + return -EINVAL; + } + return status; }