From patchwork Wed Apr 18 10:05:01 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Amit Pundir X-Patchwork-Id: 10347759 X-Patchwork-Delegate: sameo@linux.intel.com 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 DA6926053F for ; Wed, 18 Apr 2018 10:06:43 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id CA45A28599 for ; Wed, 18 Apr 2018 10:06:43 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id BEF94285DA; Wed, 18 Apr 2018 10:06:43 +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=-8.0 required=2.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,MAILING_LIST_MULTI,RCVD_IN_DNSWL_HI autolearn=unavailable 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 769C028599 for ; Wed, 18 Apr 2018 10:06:43 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1752776AbeDRKFS (ORCPT ); Wed, 18 Apr 2018 06:05:18 -0400 Received: from mail-pf0-f194.google.com ([209.85.192.194]:35964 "EHLO mail-pf0-f194.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1752727AbeDRKFP (ORCPT ); Wed, 18 Apr 2018 06:05:15 -0400 Received: by mail-pf0-f194.google.com with SMTP id g14so668654pfh.3 for ; Wed, 18 Apr 2018 03:05:15 -0700 (PDT) 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=A2Yb2+dsBznNACeCzktKB04NeyHXS/rtf8TNYmHdR6p18lbyTuw01g3vbym58csWOX w/2ZOp6BsbdU7jQZG9itdEnq/m8Ia9UTg87qn9YHV05Pa5iCB5cn1f1/XIXgn6pWSSie 0IVZBj+0vCR5l55epgmOIA9EQFAx/1d7kvrvQ= 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=tsm1LR5iEi4JJPCGGxNx9wdy5YAEYsTw+/7UoFxUVvewfNjs0rfVPvFlFsNq+CbAlR 5wY8VmY280XJr0OP9p7gIDexbP+9Kh2khHIbmxJTAwnogP6ZwAXopm3SP9zX6GyF20Dl xwtA+igV9WMtEh17m9B0frBZfbCuHwHc5kveYvKgrSp2bJ5s+PInJA/dQkW1O7EabLyR ZgDdN6iK1LHdJ9joMaMN8+Z9n9ioLG4InwBlQGzYyulygJcmw9ebqQ0zh5aUCcbsQG+z FXaor/7PZKYF5oWKLF9Z8c+RlebGZ1pZswb/JsfUwb1EazDKaugaQu7FkraMBoIz4W26 ctAg== X-Gm-Message-State: ALQs6tDo6vRvEYo3BPNS1HYie2RrWa0xjqym5GGVY6raK26T+ykj/BHs fxE/gQHkGl8OxpRimlSqbGxVCA== X-Google-Smtp-Source: AIpwx4/SjcYk6SeG8ttnObSIsLzWpl0p5htSA+W5LYt+eoBRdHRJ0rRncjMY+fsjd832tK4Cmnmetg== X-Received: by 10.101.93.7 with SMTP id e7mr1264772pgr.119.1524045915213; Wed, 18 Apr 2018 03:05:15 -0700 (PDT) Received: from localhost.localdomain ([106.51.17.69]) by smtp.gmail.com with ESMTPSA id z16sm1970298pfn.101.2018.04.18.03.05.11 (version=TLS1_2 cipher=ECDHE-RSA-AES128-SHA bits=128/128); Wed, 18 Apr 2018 03:05:14 -0700 (PDT) From: Amit Pundir To: lkml , linux-wireless@vger.kernel.org Cc: Samuel Ortiz , Christophe Ricard , Andy Shevchenko , Greg KH , John Stultz , Dmitry Shmidt , Todd Kjos , Android Kernel Team , Suren Baghdasaryan Subject: [RESEND][PATCH 1/4] NFC: st21nfca: Fix out of bounds kernel access when handling ATR_REQ Date: Wed, 18 Apr 2018 15:35:01 +0530 Message-Id: <1524045904-7005-2-git-send-email-amit.pundir@linaro.org> X-Mailer: git-send-email 2.7.4 In-Reply-To: <1524045904-7005-1-git-send-email-amit.pundir@linaro.org> References: <1524045904-7005-1-git-send-email-amit.pundir@linaro.org> Sender: linux-wireless-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-wireless@vger.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP 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(-) 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; }