From patchwork Thu May 3 18:38:53 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Amit Pundir X-Patchwork-Id: 10378899 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 8ED74603B4 for ; Thu, 3 May 2018 18:40:16 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 7B29329244 for ; Thu, 3 May 2018 18:40:16 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 6F93A29251; Thu, 3 May 2018 18:40:16 +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 E5CBD29243 for ; Thu, 3 May 2018 18:40:15 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1751095AbeECSjE (ORCPT ); Thu, 3 May 2018 14:39:04 -0400 Received: from mail-pf0-f193.google.com ([209.85.192.193]:43671 "EHLO mail-pf0-f193.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1750969AbeECSjC (ORCPT ); Thu, 3 May 2018 14:39:02 -0400 Received: by mail-pf0-f193.google.com with SMTP id j20so1096344pff.10 for ; Thu, 03 May 2018 11:39:02 -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; bh=aZuHMnS8HoYQvymWT9toB6eMu7hXaR3HCblMyZn8Yd8=; b=AFrJSQ3g/0LEig40pCkgJBvQ97ub/yxdTMQMssKjZx4DN79hEkvqrCPpcVw2T3eq3Q Ef2wkiYwai7EzotwNhm+0x5YUoU3IfrQBWITitILNDFgEkKQc3sXu50p6NO98ohP//gS D/is42CRiBelk8q9v9w7SDdvZ2ML+xbPlT/Fo= 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; bh=aZuHMnS8HoYQvymWT9toB6eMu7hXaR3HCblMyZn8Yd8=; b=CV0jO+pUvMTV9zGi4nrFDiIouGO4eKbkLhUVStWC2Dq8EE/aNSPmxHmjdfx5he1Cfp PUWkoXOC0c5g+9vIfvksJNxnxzr9l07MHcR7w/FO1qnRDy94X/8e573gw/VFAgguufI3 JPKTGL85CSuJJiZzt6MPr4pnQacLp+zOSL94YaJqzo/tVHI/NJVo75H8OOd2Azvr5fF5 DKVdbQdKeIOhVR9NmNiFvgcbaF9L1YQ3Kye+y71/1l4Qjl//zKJHL6rmV37x8yi1O1Dq EMY/HuuI99ZMqyeFVC6n3Y9G/2Q8e7jzTlwDFZPj1fmILgkXj8ygHC7ETDeE34FcpLHP vq0g== X-Gm-Message-State: ALQs6tC2GoTmAWoCKnxLVrYS7RkHmW4Ha9/vq2x0yqdcAs9kD5aI0Z9t 5hfbMBR750IVol3z47Ohlu9q3A== X-Google-Smtp-Source: AB8JxZrcgQ5eOVoX6zWGPEsSZb60ZBV6e4tQHDR7GhJQ596RpyjIx9O6uIZ+P8iyzFMApGpMiWcY/w== X-Received: by 2002:a63:5ec5:: with SMTP id s188-v6mr20021730pgb.21.1525372742210; Thu, 03 May 2018 11:39:02 -0700 (PDT) Received: from localhost.localdomain ([106.51.17.226]) by smtp.gmail.com with ESMTPSA id o5-v6sm4130786pgv.47.2018.05.03.11.38.58 (version=TLS1_2 cipher=ECDHE-RSA-AES128-SHA bits=128/128); Thu, 03 May 2018 11:39:01 -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 , Stable Subject: [PATCH v3 1/4] NFC: st21nfca: Fix out of bounds kernel access when handling ATR_REQ Date: Fri, 4 May 2018 00:08:53 +0530 Message-Id: <1525372736-25094-1-git-send-email-amit.pundir@linaro.org> X-Mailer: git-send-email 2.7.4 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. cc: Stable Signed-off-by: Suren Baghdasaryan Signed-off-by: Amit Pundir Reviewed-by: Andy Shevchenko --- v3..v1: 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 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; }