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: 134856 Delivered-To: patch@linaro.org Received: by 10.46.151.6 with SMTP id r6csp961540lji; Wed, 2 May 2018 10:49:20 -0700 (PDT) X-Google-Smtp-Source: AB8JxZpOYMA0vOacgnTdTtDtIl2xqOZGvbXIftbFenUW/52HOlqV1INvGHOGIEfXnegsYfHe9qU1 X-Received: by 2002:a17:902:758d:: with SMTP id j13-v6mr21117749pll.188.1525283360606; Wed, 02 May 2018 10:49:20 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1525283360; cv=none; d=google.com; s=arc-20160816; b=fvkce7fKbjTpDRVPxp5IpMET3l3YA8b0Q+j2ufnp7vaOukAjRskL+rLqWVu5HLK1Jz bqlt6B1IBtqiX+zc8JyOzLu2u0zVR5tg/I9gugQBVu2i7atGZxUVA63CqCWPf1uGk1bw 7ujetTURboZnNQeFIxWWWPWqq887v0Yw15riu28sizfUTXPBrhRdwuFBSC19GXRsugdl DHOgk1LmT5Xy7IMMY4qAAMmvDsdLzO0pD7SMCpCscucMwQ3IyEk1WkiIacBwtyO3vlbu N11WLACWdsrXDEH9Wxiquz3UgAaDeysYAWY/czhaASqoltjfqCwQCxE9z1lXO+GvV+pj NogQ== 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=4fymCIn5kQ1t0qy2gJd1+DqIl18DKdeO5ToUU0ZKRTg=; b=O6SQStdzPdD2QXRdXTJF3ltoEylxf5XSJbZWvG6UoKdUNQKGw/m+qgw1ixIobPzDxg z/2vb9KMGE9HRpzu5UCzt78sJmWXxqIGPWfu+/CIJbQNixjJTR1urq73U1y3Qjc6Llji kOz2lMYLGl4VkNr5p4F/d9evXF/ZtcZdamP8foF+WsfZsHYQD3qKS+MBkbVxFX8uJnwg fw2bzJkvL0jd5ZSFQtQ/pUPrYUFq9RCUQMpPCaOiMoxDGudqNDHpxgqagtIZvYH88DMR LbeO13UbxUZzwUWXm9Hmw09tj77BTFADBT3QWzZlHRxK5iC8YWqOfCnUubrmA9FbK6Va FruA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=adzPT/Fw; 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 x8-v6si7947487plv.71.2018.05.02.10.49.20; Wed, 02 May 2018 10:49:20 -0700 (PDT) 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=adzPT/Fw; 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 S1751855AbeEBRtS (ORCPT + 29 others); Wed, 2 May 2018 13:49:18 -0400 Received: from mail-pg0-f67.google.com ([74.125.83.67]:33138 "EHLO mail-pg0-f67.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1751803AbeEBRsU (ORCPT ); Wed, 2 May 2018 13:48:20 -0400 Received: by mail-pg0-f67.google.com with SMTP id i194-v6so11162959pgd.0 for ; Wed, 02 May 2018 10:48:20 -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=fy/Dh8v34hpZIB9txXSyhL7u0mDXQKOb3pPxxqOEf1dW4nqYkQNsbTePDwaxg2qHw2 JMHTHKcMgCiuzmFoERmDyEbLyxgzVqiWjkXAhp9I7jnMimUX0k6l3C0AkABUvFo/zJMK trmq0FWX542UUQE7mgp/OuJdE0k2kLem51gMlMITj8jRQJFrnxrFz+wqMmRPjNBczs+P bWZjWkbpTRVELWQXKY9T5ud7H2clrBPJt/A5JkM+BP2WAHYENRQggpaJcX/UCL34u0qy DvpPyL/P+1dCmceh9/HTFtSt4PlFgJzsnmlZzd0UXwVOxF3XKeS3c+5N0D4BOy7OM8Ex 7VMA== X-Gm-Message-State: ALQs6tAUv5+1StKhK2ju44lyaLGbp+rV1Hwn4YnT8+AUh8ccRvYlUxVE TV9u1Gn5ClrIYe0JbwhKsr23bvbKnNM= 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-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 --- v2: Resend. No changes. 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 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; } From patchwork Wed May 2 17:48:07 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Amit Pundir X-Patchwork-Id: 134853 Delivered-To: patch@linaro.org Received: by 10.46.151.6 with SMTP id r6csp960798lji; Wed, 2 May 2018 10:48:31 -0700 (PDT) X-Google-Smtp-Source: AB8JxZorlPzJISzhif+gL+GfeFHeuU4VEOMLWfZlzftvMY2rh64d2WoEfNJkV3KpB1XtBodabhSx X-Received: by 2002:a63:b746:: with SMTP id w6-v6mr12138197pgt.215.1525283311711; Wed, 02 May 2018 10:48:31 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1525283311; cv=none; d=google.com; s=arc-20160816; b=vDhMiKq1tu9QiG9TI78rcmpD5jwgVjlCHsI46NwrR4ufwOHLwkdp9hS0t043/BTD8M VrEVZnVE/YLIdSrXysftLl2pmBAyEK+05RCMYI1pGwxh5WXg27yUSOUPCSQRFv3jKJyV MVoqWaPVDVVQTXaKUH+0QvIDSCAohi6lhgggu31IJHuZWSig/iyoMlTqNSpQSw+hpWK/ oPGZXMNLDFkt9S97h6Mbj0e27z2g/mh13JloVLIyYgP7J4RmljWQ9DzcflmjOXT5IdVJ xKG4CrqsX3pb3XGOuhNoHurk5Fioq+Le1zJEBmrSWBQMFPMCzhxwcSht2714iiZbx2dz DM/Q== 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=z47AkYrZrCYwdJHLcba161nVjfCLWE0I/WK1pjwAC5w=; b=IQ8+z262xFstmMYdcSq5KPQoaMDS+f/l1pUhLQAfssB/q3ejZOzVqUShkXkJyuqLo4 pkMPLKGJD6SgONCj2F549Sd1sfSrQktcfQvPOm1VMnUPzdN5Bew/L/lX+v9sgfMGuSCl HevSsejRBVEMxgvaph+9OsvbvwgtG2Z/1nY1pt7D0mPEFXoBQ0gb8wpFrM6lAdr1Dajn qq9kF7bEbunQCCbOHm7VvouEoi0q5cDbouR/H0zlcBLkfFNCbwSy5LNS+uOnvSKGaiRS H4lphs+iOKu673OWAxrviEFNDbasGrwuBxWgXP0c0rgXAn06VXbN1k4S8JDE7UeJKvbd oXsA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=djnVsbdS; 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 u184-v6si9757258pgc.223.2018.05.02.10.48.31; Wed, 02 May 2018 10:48:31 -0700 (PDT) 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=djnVsbdS; 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 S1751846AbeEBRs3 (ORCPT + 29 others); Wed, 2 May 2018 13:48:29 -0400 Received: from mail-pf0-f195.google.com ([209.85.192.195]:37087 "EHLO mail-pf0-f195.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1751790AbeEBRsY (ORCPT ); Wed, 2 May 2018 13:48:24 -0400 Received: by mail-pf0-f195.google.com with SMTP id e9so8414267pfi.4 for ; Wed, 02 May 2018 10:48:24 -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=z47AkYrZrCYwdJHLcba161nVjfCLWE0I/WK1pjwAC5w=; b=djnVsbdSHiXGUI3L7k1vTen67hc4ydsopoxbcg5aQKFjpdYkrA6wF/G7pDJv88/jiA Jd/fSkRFJkDMfOL3UfvlcdDTg1QbVWKrk2qQpvvymDRSCiezYRUhQga+zD6lsJTMPn/J 8+0KzoKrC8aX632RAIikX1mXP2/vNtogb59YE= 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=z47AkYrZrCYwdJHLcba161nVjfCLWE0I/WK1pjwAC5w=; b=R11s5xNAeajtnpua/OgDOYCjrykwOvyIYY8KSiEBtS5nYdLkE6B6U+OzHpoorRhA6m vfTmjXwXw8fAlMZq1p1APBytT0mV+V0FC335OZRWhOfbmIVdEAnq9I7LIS5Q++0VBtN3 KYkxOmrvPi62TB3UqkqRYKMn2E0E9mpzOrJIZLQVbYkrcbkngLwinPBTiY7Y4+O3n1va BSMKC5p34aZpkb1YstHRWvHfUQyGFsHLOHzkRbJu0dg1pjHuxIFFVYmU+YQC1Tbj01aq FZvXzbn5pfhIrH9BbL4BvVwhBp/+kn7cc+JlJnbApZzbwp+UXq5KT+UDE2zB8sZPFBgb 4ukw== X-Gm-Message-State: ALQs6tBBWOAyxrJtdM7Y7MTS1//fTk3pShTAneIjug0wKqEtEbsNN7aa ++vmuoiKpfGV98bfeuXJcvw88bwBMlQ= X-Received: by 2002:a17:902:2826:: with SMTP id e35-v6mr20947133plb.348.1525283303179; Wed, 02 May 2018 10:48:23 -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.19 (version=TLS1_2 cipher=ECDHE-RSA-AES128-SHA bits=128/128); Wed, 02 May 2018 10:48:22 -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 2/3] NFC: Fix possible memory corruption when handling SHDLC I-Frame commands Date: Wed, 2 May 2018 23:18:07 +0530 Message-Id: <1525283288-7027-3-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-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org From: Suren Baghdasaryan When handling SHDLC I-Frame commands "pipe" field used for indexing into an array should be checked before usage. If left unchecked it might access memory outside of the array of size NFC_HCI_MAX_PIPES(127). Signed-off-by: Suren Baghdasaryan Signed-off-by: Amit Pundir --- v2: Resend. No changes. net/nfc/hci/core.c | 10 ++++++++++ 1 file changed, 10 insertions(+) -- 2.7.4 diff --git a/net/nfc/hci/core.c b/net/nfc/hci/core.c index ac8030c4..19cb2e4 100644 --- a/net/nfc/hci/core.c +++ b/net/nfc/hci/core.c @@ -209,6 +209,11 @@ void nfc_hci_cmd_received(struct nfc_hci_dev *hdev, u8 pipe, u8 cmd, } create_info = (struct hci_create_pipe_resp *)skb->data; + if (create_info->pipe >= NFC_HCI_MAX_PIPES) { + status = NFC_HCI_ANY_E_NOK; + goto exit; + } + /* Save the new created pipe and bind with local gate, * the description for skb->data[3] is destination gate id * but since we received this cmd from host controller, we @@ -232,6 +237,11 @@ void nfc_hci_cmd_received(struct nfc_hci_dev *hdev, u8 pipe, u8 cmd, } delete_info = (struct hci_delete_pipe_noti *)skb->data; + if (delete_info->pipe >= NFC_HCI_MAX_PIPES) { + status = NFC_HCI_ANY_E_NOK; + goto exit; + } + hdev->pipes[delete_info->pipe].gate = NFC_HCI_INVALID_GATE; hdev->pipes[delete_info->pipe].dest_host = NFC_HCI_INVALID_HOST; break; From patchwork Wed May 2 17:48:08 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Amit Pundir X-Patchwork-Id: 134854 Delivered-To: patch@linaro.org Received: by 10.46.151.6 with SMTP id r6csp960973lji; Wed, 2 May 2018 10:48:42 -0700 (PDT) X-Google-Smtp-Source: AB8JxZpB7iZNinK+v9Zcz20F6hqfFUljAy0r7yIQLQ9BCZ/6TOVFrz6hWOQwoyF8fr7pWbbdgNqG X-Received: by 2002:a17:902:ac96:: with SMTP id h22-v6mr21046075plr.338.1525283322508; Wed, 02 May 2018 10:48:42 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1525283322; cv=none; d=google.com; s=arc-20160816; b=d/hQgVynUc5Itbxr7lMsjg2VjYjCqW/+ADcjPOS4uggdfmniwWKDNCk6uiET8c7aO/ fpc+7vTUW+bNI/jTE74DI1P8A361vTcrh9RiQn7jkMKXDgjjfB1Z01NyGHnRpdfnAcpj QueNwEfVHx6m6J+r2t7lrBPmI7Usy6TsH4YlEFCMvQRPwThrtf4kpWGzJtgJUJ7a1OtD vcr4T35cPP/b5UwCqi7UzBbGYMtG1rCjxRfqpI5Bj09W1wcDDlnlp7Qv15Dw19+ximwP l2dGIIQgYevPz4j49Hei0E7oMVnRVBhEMKCJeixs1dSiGnnENcn1xGbiqerImyCbobdG RWjQ== 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=vIbutGlUGmHHi1W8Vh0uYh/n/wIktrMraEjzwoOh+Cs=; b=0EJ8vMkgdwuJBR+qxlLLD6m1gmmvwXgt3ClaOE5UVgfvaq7CxOHKJTiaipEwuTIMky csEHZOYn0Hdmw8BjTTarCGjfwnNyOHAm+PVj34uS3pvzYtrt70U4I6I+RfjSTbICm9eM Lf3om6bJaBAOqSRKalSh29yPvdukgIUiKyZLVtoTN+gRJSjQEr4WlVRGf/LrPuyWF9r1 Kb/7F7GsXcomZryuls6wObf3GaFOrJwOhXWB7AAL0d0X1D9dHABM1fPHKl2r1o7M5crY WhDjuTcWQDTP/AY2fi6Ea+6RqQDxPy5KYQa8QbjZ1Y4lQrpMi3gBS9t/ApSPDnQh6dZL E0OQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=fJKe5FX7; 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 h62si11818453pfg.308.2018.05.02.10.48.42; Wed, 02 May 2018 10:48:42 -0700 (PDT) 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=fJKe5FX7; 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 S1751852AbeEBRsk (ORCPT + 29 others); Wed, 2 May 2018 13:48:40 -0400 Received: from mail-pf0-f195.google.com ([209.85.192.195]:39340 "EHLO mail-pf0-f195.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1751837AbeEBRs2 (ORCPT ); Wed, 2 May 2018 13:48:28 -0400 Received: by mail-pf0-f195.google.com with SMTP id z9so12400328pfe.6 for ; Wed, 02 May 2018 10:48:28 -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=vIbutGlUGmHHi1W8Vh0uYh/n/wIktrMraEjzwoOh+Cs=; b=fJKe5FX7XaJ/Kmp+Ss+DUfT8WypJ9cUdcNIgDhMDcd4vmTac4mMwTxvu27HDLrrzvQ 8iq4oiuYd8HWt5f5B6cMWKhEOhVEQoIZqbxnuSsSaudJug8WvI5ZXKzy95jPQu+WYp55 5YwuNiga6gX11RGVE3+4vxgUZiU8ug+tixfjU= 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=vIbutGlUGmHHi1W8Vh0uYh/n/wIktrMraEjzwoOh+Cs=; b=lX6FWIn8hjzqTKMv8Ow3zBWjvKq2dzVioYiHLXy1F701QUdiDIwx7VUBAuFuuDKFOj 5dYEQZJxY6hGqFwOTFWLVMxtYSBDZNR8tbWP92KHudiQDk8SkvspDkTj2JnI3ZUkYWKl +2qQKtr6iV3YxrWdU2kZqkufYwrq+xuvsTp8d85DSf/yFpmgc8B9Leyd2OEQPcCnWo7d v+Hb1DmEGaZM8SIOwYV561l56S8h2JNq59Xtrb6qdpG3225YPTIKoiH94uAkzHLuJl05 Hy8QpmzjbxC0lvPBZUVnJFqQQQO4Fo7DbAsiKLOTpJO68GkliWIwyvkeAm7xTsLMR22e 9RHA== X-Gm-Message-State: ALQs6tD24hMqc9YHW05lOyLcBWCv6ReyOh2rJzgICT4h0/1VOv1u1dEa Id0xh1Oq9AHLeyPga7fZM0KJcV14ZMY= X-Received: by 2002:a17:902:6b0c:: with SMTP id o12-v6mr20673823plk.159.1525283307320; Wed, 02 May 2018 10:48:27 -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.23 (version=TLS1_2 cipher=ECDHE-RSA-AES128-SHA bits=128/128); Wed, 02 May 2018 10:48:26 -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 3/3] NFC: fdp: Fix possible buffer overflow in WCS4000 NFC driver Date: Wed, 2 May 2018 23:18:08 +0530 Message-Id: <1525283288-7027-4-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-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org From: Suren Baghdasaryan Possible buffer overflow when reading next_read_size bytes into tmp buffer after next_read_size was extracted from a previous packet. Signed-off-by: Suren Baghdasaryan Signed-off-by: Amit Pundir --- v2: Remove redundant __func__ from dev_dgb(). drivers/nfc/fdp/i2c.c | 9 +++++++++ 1 file changed, 9 insertions(+) -- 2.7.4 diff --git a/drivers/nfc/fdp/i2c.c b/drivers/nfc/fdp/i2c.c index c4da50e..b80d1ad 100644 --- a/drivers/nfc/fdp/i2c.c +++ b/drivers/nfc/fdp/i2c.c @@ -176,6 +176,15 @@ static int fdp_nci_i2c_read(struct fdp_i2c_phy *phy, struct sk_buff **skb) /* Packet that contains a length */ if (tmp[0] == 0 && tmp[1] == 0) { phy->next_read_size = (tmp[2] << 8) + tmp[3] + 3; + /* + * Ensure next_read_size does not exceed sizeof(tmp) + * for reading that many bytes during next iteration + */ + if (phy->next_read_size > FDP_NCI_I2C_MAX_PAYLOAD) { + dev_dbg(&client->dev, "corrupted packet\n"); + phy->next_read_size = 5; + goto flush; + } } else { phy->next_read_size = FDP_NCI_I2C_MIN_PAYLOAD;