From patchwork Wed Dec 20 19:51:21 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Amit Pundir X-Patchwork-Id: 122494 Delivered-To: patch@linaro.org Received: by 10.140.22.227 with SMTP id 90csp6024225qgn; Wed, 20 Dec 2017 11:52:39 -0800 (PST) X-Google-Smtp-Source: ACJfBovWLapomJWK0SNjwX+z4kNKWj1kYrLh0qFbOPLr7tnvpA+aC0bbCo5jaSuz/8mXv0dtHCxz X-Received: by 10.99.190.72 with SMTP id g8mr7234085pgo.170.1513799559268; Wed, 20 Dec 2017 11:52:39 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1513799559; cv=none; d=google.com; s=arc-20160816; b=hjBuDxXvh3nSxUkL8wQxevqb0I44TIBzAUlfjLAct/yPBvD5aNhNFvKfdGsPtRy7ML oxEzzu8Yu+hqSo6LQcNV3+HPni4hSWPpo648wtUTBqCuHdIBNdm3GvuwszYsSZAlRiVj KW3cn+1/7B66cwvlLeFKQ0JaSl25ppiTKGpmewBxcPEt3naY3nom8ORCdbBqgO7O6aOu qh7FO0WmrmnouzJ1xaIWhVEF33xCxw4tXprBzoYIs2/MQ9R62VUwSKhXX02MkT7CcbQL E1e0uY3XUOkWgdjmO0zqbZhuQ/lgdABiZWEjHMP73j24ZWjnSqwIyR039+pSpBaiwUaV aPBQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:references:in-reply-to:message-id:date :subject:cc:to:from:dkim-signature:arc-authentication-results; bh=BSvaSnSaUmVJ7Li8G5jPfvmWzxU8loCxeYaDdT0Atkw=; b=dM0r9vvqgpERjKzESDN21GVnmNukU9LnLkkHd6x/2YwpXG73nUuSr/Od+8VMXopANf njO/LwAQxXgyvtwPJrgtyIsRa7geKqcvjSeair9x2mqC/zjuJmTspMjG7i2yMK10Qpod DVOpBUlBJD+HkAVlnoyRJikD6zwNmUD4y/kULZE23HaRJ9HvSt6GzRzIEpPwzHWtUB+H 7Hvh8mnyPnZLrJ84jCYjxjMKu2NcKcbR6jRJ11E4HAaZlL/Eo1IixCp9aAoXFE5EryNr cB1Fof6OaclUQ3nI5A8RpBR30cAmFIcKWAottxZOnnmSBJaa7+mZUpI8VVb2EbTMnZQt aKiw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=itw0Dtii; 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=NONE sp=NONE dis=NONE) header.from=linaro.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id i6si12229962pgq.343.2017.12.20.11.52.38; Wed, 20 Dec 2017 11:52:39 -0800 (PST) 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=@linaro.org header.s=google header.b=itw0Dtii; 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=NONE sp=NONE dis=NONE) header.from=linaro.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1756863AbdLTTwf (ORCPT + 28 others); Wed, 20 Dec 2017 14:52:35 -0500 Received: from mail-pf0-f193.google.com ([209.85.192.193]:41138 "EHLO mail-pf0-f193.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1756697AbdLTTvg (ORCPT ); Wed, 20 Dec 2017 14:51:36 -0500 Received: by mail-pf0-f193.google.com with SMTP id j28so12982310pfk.8 for ; Wed, 20 Dec 2017 11:51:36 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; h=from:to:cc:subject:date:message-id:in-reply-to:references; bh=BSvaSnSaUmVJ7Li8G5jPfvmWzxU8loCxeYaDdT0Atkw=; b=itw0DtiiAKKmK/MVZ+/FsvO5cVdilp0X89f54teCSZ8Ec5vJPsF3Xnv9sJHkZruK7P 6fYCkPG5MA64oue0l9wik1hZ4MQxaQhxBRNZxqNDv8BWxS7isnDjjcAtiV/b7uNzjNqE 7ij21vD9H/YWILrbRo2EZuFXTosFLv7qHhR3o= 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=BSvaSnSaUmVJ7Li8G5jPfvmWzxU8loCxeYaDdT0Atkw=; b=ZoEcol1YzOVZYTwpOi69SG0b24UN9NPpD10e0YPsziA7rA/NPLTbXhlwzw59dsTZAi o49MTfyHri3Q654/7+FCnkwx1S8iEVWT1xoiLOoBTYk8AeXvBNN7zh+NsMYQiQCdpld6 TwbSFE6ik+na4+INvIinrs9US47yhE+cdDiTtVDDZpBiHuNUDZN26WIgdaZhhNYtGwkm l019+2qBD1tjcSuB6rYfhcOKVIgUPsuJVWWojEx2mvTdLGKkITcba0MRDGKiKDSPXgn8 4ylSr4aDWv8yFD2CbeMPsZyaJIiyJzF1FQrRXo+PR7diG4/B32h/ZAafSZrsHYTcHbTd YFcg== X-Gm-Message-State: AKGB3mIwiPVm4z1YX3Qs9Ia3+v8W/PSNbBoqKvKH0uD6B2qEBYO17Ppd AEXSz+RKSdSAIS4+4LSts3Na3Gcl/co= X-Received: by 10.101.98.136 with SMTP id f8mr7204857pgv.366.1513799495117; Wed, 20 Dec 2017 11:51:35 -0800 (PST) Received: from localhost.localdomain ([106.51.17.191]) by smtp.gmail.com with ESMTPSA id g2sm36715867pfc.130.2017.12.20.11.51.31 (version=TLS1_2 cipher=ECDHE-RSA-AES128-SHA bits=128/128); Wed, 20 Dec 2017 11:51:33 -0800 (PST) From: Amit Pundir To: lkml , linux-wireless@vger.kernel.org Cc: Suren Baghdasaryan , Samuel Ortiz , Christophe Ricard , Andy Shevchenko , John Stultz , Dmitry Shmidt , Todd Kjos , Android Kernel Team Subject: [RFC][PATCH 1/4] NFC: st21nfca: Fix out of bounds kernel access when handling ATR_REQ Date: Thu, 21 Dec 2017 01:21:21 +0530 Message-Id: <1513799484-12505-2-git-send-email-amit.pundir@linaro.org> X-Mailer: git-send-email 2.7.4 In-Reply-To: <1513799484-12505-1-git-send-email-amit.pundir@linaro.org> References: <1513799484-12505-1-git-send-email-amit.pundir@linaro.org> Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org From: Suren Baghdasaryan Out of bounds kernel accesses in st21nfca's NFC HCI layer might happen when handling ATR_REQ events if user-specified atr_req->length is bigger than the buffer size. In that case memcpy() inside st21nfca_tm_send_atr_res() will read extra bytes resulting in OOB read from the kernel heap. Signed-off-by: Suren Baghdasaryan Signed-off-by: Amit Pundir --- drivers/nfc/st21nfca/dep.c | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) -- 2.7.4 diff --git a/drivers/nfc/st21nfca/dep.c b/drivers/nfc/st21nfca/dep.c index fd08be2917e6..3420c5104c94 100644 --- a/drivers/nfc/st21nfca/dep.c +++ b/drivers/nfc/st21nfca/dep.c @@ -217,7 +217,8 @@ static int st21nfca_tm_recv_atr_req(struct nfc_hci_dev *hdev, atr_req = (struct st21nfca_atr_req *)skb->data; - if (atr_req->length < sizeof(struct st21nfca_atr_req)) { + if (atr_req->length < sizeof(struct st21nfca_atr_req) || + atr_req->length > skb->len) { r = -EPROTO; goto exit; }