From patchwork Wed Mar 28 10:54:27 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: harrymorris12@gmail.com X-Patchwork-Id: 10312753 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 A1A7460325 for ; Wed, 28 Mar 2018 10:54:41 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 9932829664 for ; Wed, 28 Mar 2018 10:54:41 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 8DA0729675; Wed, 28 Mar 2018 10:54:41 +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_ADSP_CUSTOM_MED, DKIM_SIGNED, FREEMAIL_FROM, 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 A8ED729669 for ; Wed, 28 Mar 2018 10:54:39 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1752237AbeC1Kyj (ORCPT ); Wed, 28 Mar 2018 06:54:39 -0400 Received: from mail-wm0-f67.google.com ([74.125.82.67]:55461 "EHLO mail-wm0-f67.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1752216AbeC1Kyi (ORCPT ); Wed, 28 Mar 2018 06:54:38 -0400 Received: by mail-wm0-f67.google.com with SMTP id b127so3238234wmf.5 for ; Wed, 28 Mar 2018 03:54:38 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:to:cc:subject:date:message-id:in-reply-to:references; bh=nVar/xbHO9eC8Eqlf0bkckfB1NXqoVhAQ2oZjY5CHHw=; b=XyCCTLtnTn73Oil+wA8BOL/HNP6dWC/VGzJgz3b4Bw26JEhbyT12HeBS5lyU+M8PRC /ZlYpYiCjZqjw5dvDQ12DqJ52GLOc3hVDrgxDPv7ZIkSJIYd1UdLK5LNpBFD8u7k/qiC 8gctm5XlAE7+AMOZbnDniytBgqjW0MAD5sW2aBpy7o1GHxhZu8MTwPo/mXd/pKjNzKb3 htCoFRvthKBrCrwmUXCM7Rgb2/FITY8G3kgY8zYUy1cacT1WIu/yRN0oz1XHE/XGz4KL DdoHlXbFeHzFC5VRkDSVXA5TQz6Bxksy8DsJUUsIuuiAR/GDocemrzc3l1juVqtgAWBu hJ9Q== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references; bh=nVar/xbHO9eC8Eqlf0bkckfB1NXqoVhAQ2oZjY5CHHw=; b=MyAC6ZBEIclfiljZLpQbLE89cbbGjKuJU23QTl5n2wPA2GMYGw0YPX63okyNhdkQ6S Qr4hHUCNrKYg90h05Q8HM0c/9aeFIJvKyi4pDIPt4uQSfwxb9FAICuiXZqnH/d2tSMto h+csceTyALDwxWzxonjuybbRwixPnfVHSH2bAr0/q6ArbgTPZr2XZsb+jgulnslJBRwj UXnw4oKBkrV+5Ur8Jubm0k6PDWOvmun5NdFJDYhlDdMMCgBtzoGKTsuHIJaUMvGs3Cc+ g26wWw37A4P/jH8CKteYUeFTUekuk82gG6Sx1glON6sJ+9TSK1/h6ciQ5F/7yuH11Z2w +4AQ== X-Gm-Message-State: AElRT7HZe0Yb2Wu2QqzIM5q0tUpve2sS4FhM2pQMS8pUx+TfPXwj0GP+ NEDzSJbkIauOZ8bW7ze/KVcEXvwo X-Google-Smtp-Source: AIpwx49fNp4RtFkUr25gYi5Xx6Zt9omX1vu7CAypP1R/0RIBcywdIrfu1J4ZIxGQvPIOceg+DqDlbg== X-Received: by 10.28.114.20 with SMTP id n20mr2198266wmc.56.1522234477189; Wed, 28 Mar 2018 03:54:37 -0700 (PDT) Received: from CASCODA211.internal.cascoda ([89.21.229.165]) by smtp.gmail.com with ESMTPSA id q9sm3147579wrf.11.2018.03.28.03.54.36 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Wed, 28 Mar 2018 03:54:36 -0700 (PDT) From: harrymorris12@gmail.com X-Google-Original-From: h.morris@cascoda.com To: linux-wpan@vger.kernel.org Cc: stefan@osg.samsung.com, aring@mojatatu.com, domen.puncer@samsung.com, Harry Morris Subject: [PATCH v2 1/1] ieee802154: ca8210: fix uninitialised data read Date: Wed, 28 Mar 2018 11:54:27 +0100 Message-Id: <20180328105427.34812-2-h.morris@cascoda.com> X-Mailer: git-send-email 2.11.0 In-Reply-To: <20180328105427.34812-1-h.morris@cascoda.com> References: <20180328105427.34812-1-h.morris@cascoda.com> 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 From: Harry Morris In ca8210_test_int_user_write() a user can request the transfer of a frame with a length field (command.length) that is longer than the actual buffer provided (len). In this scenario the driver will copy the buffer contents into the uninitialised command[] buffer, then transfer bytes over the SPI even though only bytes had been populated, potentially leaking sensitive kernel memory. Also the first 6 bytes of the command buffer must be initialised in case a malformed, short packet is written and the uninitialised bytes are read in ca8210_test_check_upstream. Reported-by: Domen Puncer Kugler Signed-off-by: Harry Morris Tested-by: Harry Morris --- drivers/net/ieee802154/ca8210.c | 14 +++++++++++--- 1 file changed, 11 insertions(+), 3 deletions(-) diff --git a/drivers/net/ieee802154/ca8210.c b/drivers/net/ieee802154/ca8210.c index 377af43b8..58299fb66 100644 --- a/drivers/net/ieee802154/ca8210.c +++ b/drivers/net/ieee802154/ca8210.c @@ -2493,13 +2493,14 @@ static ssize_t ca8210_test_int_user_write( struct ca8210_priv *priv = filp->private_data; u8 command[CA8210_SPI_BUF_SIZE]; - if (len > CA8210_SPI_BUF_SIZE) { + memset(command, SPI_IDLE, 6); + if (len > CA8210_SPI_BUF_SIZE || len < 2) { dev_warn( &priv->spi->dev, - "userspace requested erroneously long write (%zu)\n", + "userspace requested erroneous write length (%zu)\n", len ); - return -EMSGSIZE; + return -EBADE; } ret = copy_from_user(command, in_buf, len); @@ -2511,6 +2512,13 @@ static ssize_t ca8210_test_int_user_write( ); return -EIO; } + if (len != command[1] + 2) { + dev_err( + &priv->spi->dev, + "write len does not match packet length field\n" + ); + return -EBADE; + } ret = ca8210_test_check_upstream(command, priv->spi); if (ret == 0) {