From patchwork Wed May 2 17:48:06 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Amit Pundir X-Patchwork-Id: 10376187 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 350DC6037D for ; Wed, 2 May 2018 17:49:24 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 274DC289E2 for ; Wed, 2 May 2018 17:49:24 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 1BE6628A3E; Wed, 2 May 2018 17:49:24 +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 CB8AF289E2 for ; Wed, 2 May 2018 17:49:23 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1751245AbeEBRtU (ORCPT ); Wed, 2 May 2018 13:49:20 -0400 Received: from mail-pg0-f67.google.com ([74.125.83.67]:36800 "EHLO mail-pg0-f67.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1751763AbeEBRsT (ORCPT ); Wed, 2 May 2018 13:48:19 -0400 Received: by mail-pg0-f67.google.com with SMTP id z129-v6so6985464pgz.3 for ; Wed, 02 May 2018 10:48:19 -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=4fymCIn5kQ1t0qy2gJd1+DqIl18DKdeO5ToUU0ZKRTg=; b=adzPT/Fwc5/7pVxPJqHIEdllSIyuIC1pyl610qvDmFOOODn+pRi9FsRYVsAgfvGloM 2rtgKc2cI5E4AR5YeXzG+P8T5J22BP3HOCJaQu8BEQxdhdK+DVlCIBK83Lw1e93MB8nq qxD7Tz6RclMqnpfJLWaKDyrp+becuZvETQYHQ= 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=4fymCIn5kQ1t0qy2gJd1+DqIl18DKdeO5ToUU0ZKRTg=; b=KN3MwyTdP3IGSl7L6rlt+gQnV2BgnfeZqs2xVgO2N7zW8zH+yMLipFCG8HTcsJhqxj GQz6nvVfdMWkt9wRoZLOuce9tc2+0nSq6wZB9rm5YwLMwMEteN0Vt7OLodq7CF1iObMR AzLcLCLcq6rc7+CSe5muTLK/rbv/kJFyF3rtW6nVp8i0/ARqKaaJnsoAh9ftZctbHK5n Tg54T8nL1PhBa7OiYL7PAHvsMcg83DygHW8UHFXXuIRt9Rzs0kVV64ysyyocwDinunFI AnPOXQhsOS0TaKlcOTSs7eLt9EICPYmg9e1JNNBW86dkK3xVO+eAiaEJKDbvE1VnPOFV yKwg== X-Gm-Message-State: ALQs6tBE2wvCPOKN6evOy8t5bag3XCcz+huOp6+BUo30Rs1zdiEOLaKk tI2Tz3rBA5PqCF9vJeiFw4FuOg== X-Google-Smtp-Source: AB8JxZqECjJoxkgfcz+tLfYSPTkFwC28TJUJiXW/dCJELcoo9aMyHXsJ6xuxKpZA+zbTEXKhPaeGLA== X-Received: by 2002:a17:902:8c83:: with SMTP id t3-v6mr17166196plo.357.1525283299065; Wed, 02 May 2018 10:48:19 -0700 (PDT) Received: from localhost.localdomain ([106.51.17.226]) by smtp.gmail.com with ESMTPSA id l19-v6sm19179875pgn.44.2018.05.02.10.48.14 (version=TLS1_2 cipher=ECDHE-RSA-AES128-SHA bits=128/128); Wed, 02 May 2018 10:48:17 -0700 (PDT) From: Amit Pundir To: lkml , linux-wireless@vger.kernel.org Cc: Suren Baghdasaryan , Samuel Ortiz , Christophe Ricard , Andy Shevchenko , Greg KH , John Stultz , Dmitry Shmidt , Todd Kjos , Android Kernel Team Subject: [PATCH v2 1/3] NFC: st21nfca: Fix out of bounds kernel access when handling ATR_REQ Date: Wed, 2 May 2018 23:18:06 +0530 Message-Id: <1525283288-7027-2-git-send-email-amit.pundir@linaro.org> X-Mailer: git-send-email 2.7.4 In-Reply-To: <1525283288-7027-1-git-send-email-amit.pundir@linaro.org> References: <1525283288-7027-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 --- v2: Resend. No changes. 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 fd08be2..3420c51 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; }