From patchwork Wed Apr 18 10:05:02 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Amit Pundir X-Patchwork-Id: 133609 Delivered-To: patch@linaro.org Received: by 10.46.84.18 with SMTP id i18csp5694414ljb; Wed, 18 Apr 2018 03:05:22 -0700 (PDT) X-Google-Smtp-Source: AIpwx4+qhGGXgMm2MXY1gO4lNF7G4b9FL3ztLfrOe31tC4oorfi5a5ezDnvPgzEXD7/Apd/uRuA3 X-Received: by 2002:a17:902:51ce:: with SMTP id y72-v6mr1459535plh.157.1524045922589; Wed, 18 Apr 2018 03:05:22 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1524045922; cv=none; d=google.com; s=arc-20160816; b=KD5/SJmpN5bOHcgCjBDN6fgSS2ia0VnNrZcRpu/mMMpuF74zs92EaYRG8L56831bls RhRg4+GPEwUEwaQaSNpMTRaBHWvWzRYny6Fh9li2uFGVTaGLOc1wwKei57vhBdqPtrV+ siJZn/ONI9ogcKU3xA0bUFAmLKSUxwyxgBi+h127ZCgd2gKxpLW57vsVqHJ2FxdcnW4R Na4aBNQ6Zk0ATam2UBmqjtqZOMrSVYk7lz3gmLqJA4veB0VSQSuzPOQ7ETzRftE2wksL gaBBL+xkqnPqAoDVRG2R36ejrilZKlfArJNtiorH46Vu7Id5kgLmUQEA/ey4YpIaL97s 0QVw== 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=Q7b33P81Dqi1buU+SZECfMgqa7so/MUyD350h11szic=; b=yXon37vOTqXpZueXkEMJI+4jpJ7iQGGmb4b2BnFk4NSyl1vO9dihBzsWgGZEfHZDaz iBZzoe/e7Mz5G1geskJ5kQyNP5YO7mWsPpbxh7JV/uW0CcIcBHY4gdkuFeINeMkviEWb +YtqaI3br48jU4m1mftiySsqrAlSopwiLjrHueITqlNgbIybGp5yr80MU97xLI+aw3Im 0g4XVtFPV20qVaL344pVZr1Uv2B+Cb1OPtdmhpo9xRx8ZSja7jk4LAUUZn3/HE8bslGr eg6oXP3s99+V9hre58cDx3sORLDj7VTS1iaQDdQbOCNyVX5ZeekuQts+DgvGVJszf9vH pecQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=i0/i+u1T; spf=pass (google.com: best guess record for domain of linux-wireless-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-wireless-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 g12-v6si941274pla.133.2018.04.18.03.05.22; Wed, 18 Apr 2018 03:05:22 -0700 (PDT) Received-SPF: pass (google.com: best guess record for domain of linux-wireless-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=i0/i+u1T; spf=pass (google.com: best guess record for domain of linux-wireless-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-wireless-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 S1753073AbeDRKFV (ORCPT + 3 others); Wed, 18 Apr 2018 06:05:21 -0400 Received: from mail-pf0-f195.google.com ([209.85.192.195]:46864 "EHLO mail-pf0-f195.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1752747AbeDRKFT (ORCPT ); Wed, 18 Apr 2018 06:05:19 -0400 Received: by mail-pf0-f195.google.com with SMTP id h69so660170pfe.13 for ; Wed, 18 Apr 2018 03:05: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=Q7b33P81Dqi1buU+SZECfMgqa7so/MUyD350h11szic=; b=i0/i+u1TA8GYiSnZWDkrWz9ukDrSUiebEH0RE5mvRS5xjMI2Nn3Ed8tNdbtuEdC1ay h4e1Na5NOHm9y0WbKUiseirF60zoMV+YB5nGmaBM0eka7yZ1+qTinkDHPIFiduBWkdEg 7Raf0sxc6a2DNpMZr61Hn2czYJRJ1IPZUHRiE= 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=Q7b33P81Dqi1buU+SZECfMgqa7so/MUyD350h11szic=; b=hvjehw1imTugbjYt7ra0KQRp/EZnO921b+ITQDwoiNbTcHC4yM4B/MUwFEuQ3BtlWq KbY3GpHHwPU27nPvZK3O/ahajC2t1j43ccf9+ApBX71A5DTCm3t8J35fBJQga9Et2VRa jr9/QtG66Uf7hQuFbOAuGFAQfHAx95lVVc8wX0gRXLtjweYnodJcuP0hOkB/eSTgjDbF 7v7x85bAlEDNa7u3quepuEPdd2VAF9bwaOL/c+lRsSoArp3+OtVBck3S5LWdzFHMr7IV Up3sjnmrzeb+1AtD8vJAVuM0Y9QGmL06tlm8RgsRlW90XLoCryFgUcqtLsMOCA5oKvNk eGrw== X-Gm-Message-State: ALQs6tBoWaS+ID28BUGaaWsCXN4lYIIkU30YtCYEbh1COJ1VzXG7hdIJ xOG7Al4YVL1feiaQG2CaLYUl4Q== X-Received: by 10.101.78.134 with SMTP id b6mr1204815pgs.392.1524045919286; Wed, 18 Apr 2018 03:05:19 -0700 (PDT) Received: from localhost.localdomain ([106.51.17.69]) by smtp.gmail.com with ESMTPSA id z16sm1970298pfn.101.2018.04.18.03.05.15 (version=TLS1_2 cipher=ECDHE-RSA-AES128-SHA bits=128/128); Wed, 18 Apr 2018 03:05:18 -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 2/4] NFC: st21nfca: Fix memory OOB and leak issues in connectivity events handler Date: Wed, 18 Apr 2018 15:35:02 +0530 Message-Id: <1524045904-7005-3-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 From: Suren Baghdasaryan Overflow on memcpy is possible in kernel driver for st21nfca's NFC HCI layer when handling connectivity events if aid_len or params_len are bigger than the buffer size. Memory leak is possible when parameter tag is invalid. Signed-off-by: Suren Baghdasaryan Signed-off-by: Amit Pundir --- drivers/nfc/st21nfca/se.c | 18 ++++++++++++++---- 1 file changed, 14 insertions(+), 4 deletions(-) -- 2.7.4 diff --git a/drivers/nfc/st21nfca/se.c b/drivers/nfc/st21nfca/se.c index 4bed9e842db3..acdce231e227 100644 --- a/drivers/nfc/st21nfca/se.c +++ b/drivers/nfc/st21nfca/se.c @@ -322,23 +322,33 @@ int st21nfca_connectivity_event_received(struct nfc_hci_dev *hdev, u8 host, * AID 81 5 to 16 * PARAMETERS 82 0 to 255 */ - if (skb->len < NFC_MIN_AID_LENGTH + 2 && + if (skb->len < NFC_MIN_AID_LENGTH + 2 || skb->data[0] != NFC_EVT_TRANSACTION_AID_TAG) return -EPROTO; + /* + * Buffer should have enough space for at least + * two tag fields + two length fields + aid_len (skb->data[1]) + */ + if (skb->len < skb->data[1] + 4) + return -EPROTO; + transaction = (struct nfc_evt_transaction *)devm_kzalloc(dev, skb->len - 2, GFP_KERNEL); transaction->aid_len = skb->data[1]; memcpy(transaction->aid, &skb->data[2], transaction->aid_len); + transaction->params_len = skb->data[transaction->aid_len + 3]; - /* Check next byte is PARAMETERS tag (82) */ + /* Check next byte is PARAMETERS tag (82) and the length field */ if (skb->data[transaction->aid_len + 2] != - NFC_EVT_TRANSACTION_PARAMS_TAG) + NFC_EVT_TRANSACTION_PARAMS_TAG || + skb->len < transaction->aid_len + transaction->params_len + 4) { + devm_kfree(dev, transaction); return -EPROTO; + } - transaction->params_len = skb->data[transaction->aid_len + 3]; memcpy(transaction->params, skb->data + transaction->aid_len + 4, transaction->params_len); From patchwork Wed Apr 18 10:05:03 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Amit Pundir X-Patchwork-Id: 133610 Delivered-To: patch@linaro.org Received: by 10.46.84.18 with SMTP id i18csp5694505ljb; Wed, 18 Apr 2018 03:05:29 -0700 (PDT) X-Google-Smtp-Source: AIpwx488tkhk7kE0bv31zBUO5ZQkwsLUXW1trJBLkxZFTYprVMZCL7T+KkXTqhJvumcucHlUrZGF X-Received: by 2002:a17:902:9042:: with SMTP id w2-v6mr1488767plz.34.1524045929523; Wed, 18 Apr 2018 03:05:29 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1524045929; cv=none; d=google.com; s=arc-20160816; b=g84g8KsH95+6WT1xbHRDNaZimRgzIDNUXCmzoSc/KxRSb0jQZuXpi1DUr9+pcbw3ao qdmzurHi3ia1eoSpNfmeOvAKY+rEPvgdtJl4pfouXZrk24xVrAgAxGwTZanbIr5DOT3r Q1GOs8dbdvdylqfBLud9lGKRfEDNUTS3lzoi5Q1WKoXdlwEcI29s+spAfvRHVsK4/Eko UNnXvjPzKO+kcQrGOB2DOyzD3Mfzoqg/JQKFqzdd+K6uNQeUUIJMvyRqbnwSJSbyvjkK HaNE3VlC9x5tKbLaRDDVUOFMdCaZzMH8+c4xab0WpBuLLp8AT9y7F+keqYZAybHDg+2u li6w== 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=12mwkxYQZ7M7BIfATqchCZe1U9P8e+8jonsb/6NZX8k=; b=nw3CukL03REDLvgiZ7T+CVEV0s01xjA3eSxqq0B+22RwT68OXXmRz8kyJw8GWBZ+SY Q84jLjCiLQWlJuMxMJ7GGY2R3HQB4Jd7u4FiVTOEvK6zlZljyyEFv5CiCm4b1WTLhQW5 VRgvnRt0B+0W0t+/orreSwXzo45qjGQtT74/gIoLNorjGky/lBRDSmJvC2JIOLZwT886 TIHiMYnANsEn9GBWXgikqnRkA0zuF3nbhZvTPkun5hk8i6zeN4E6Iiu1vNVISfLqMwt1 8ds2kC0vIFmJIs2RzvXrmfWrDfB9uq4b2WGAbsqiVqufsh7ssilt1nq1madI1qn8QBrb ZRCw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=dgoKY9QP; spf=pass (google.com: best guess record for domain of linux-wireless-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-wireless-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 m10-v6si1034543pln.257.2018.04.18.03.05.29; Wed, 18 Apr 2018 03:05:29 -0700 (PDT) Received-SPF: pass (google.com: best guess record for domain of linux-wireless-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=dgoKY9QP; spf=pass (google.com: best guess record for domain of linux-wireless-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-wireless-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 S1753211AbeDRKFZ (ORCPT + 3 others); Wed, 18 Apr 2018 06:05:25 -0400 Received: from mail-pl0-f67.google.com ([209.85.160.67]:37453 "EHLO mail-pl0-f67.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1752983AbeDRKFX (ORCPT ); Wed, 18 Apr 2018 06:05:23 -0400 Received: by mail-pl0-f67.google.com with SMTP id f7-v6so828221plr.4 for ; Wed, 18 Apr 2018 03:05:23 -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=12mwkxYQZ7M7BIfATqchCZe1U9P8e+8jonsb/6NZX8k=; b=dgoKY9QPAfnZ6d8CarORSyA0bspt8j2khoUsx2GlxY0f5Ex8/4AAUrz4qmnZEw9Bi9 alWKLWv6Y/rSh0wz8ivjDlrV+r/iMq3TN2A5pehooMZ4z7bqxTwWJiPlN70P+eeqj8Oa L6+X9wRrY9NOpIsWT38TsX/TEPaTbJ8sQ3N1Q= 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=12mwkxYQZ7M7BIfATqchCZe1U9P8e+8jonsb/6NZX8k=; b=XMUdg7pml2DlEjdmqT4MYwp4T+zvqAvp2+P42biNy5y741NqILg2ZWdaiZFs5qn6nU pOSVEtfhWilFTpVh0srhM9SEZ1ksvgIwcn70w6kVXpKCKk+1OPL0KAFrfUsFvMfGWCDc lkeGizIQA6jrHDycQ9Snuck0EQ7hxjYXJ04ykiwlzpO4HewCdJpTapE11SDQyyjnAPJ7 iZWNxQmso7ZI7GDGmHIk6R17zcUdu5j/FkwzwyUSXnf+vJmFHIDY9qqYEXaAM9OxVnkO t0taqpmUDRYHF1lV7dxltDPa6lAQ54CfKHd7eytOlpTa/GnrnWf3XQ5UHvUeG03pIWNg YhWQ== X-Gm-Message-State: ALQs6tCg7/+ITFktGRlEoqxOej0MOpBbgibKbN2eT5aIdvUBJ7zG8jc1 p6BrK9Iu86JHggjk0Kr1BR+FFQ== X-Received: by 2002:a17:902:41:: with SMTP id 59-v6mr1487334pla.345.1524045923344; Wed, 18 Apr 2018 03:05:23 -0700 (PDT) Received: from localhost.localdomain ([106.51.17.69]) by smtp.gmail.com with ESMTPSA id z16sm1970298pfn.101.2018.04.18.03.05.19 (version=TLS1_2 cipher=ECDHE-RSA-AES128-SHA bits=128/128); Wed, 18 Apr 2018 03:05:22 -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 3/4] NFC: Fix possible memory corruption when handling SHDLC I-Frame commands Date: Wed, 18 Apr 2018 15:35:03 +0530 Message-Id: <1524045904-7005-4-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 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 --- 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 ac8030c4bcf8..19cb2e473ea6 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 Apr 18 10:05:04 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Amit Pundir X-Patchwork-Id: 133611 Delivered-To: patch@linaro.org Received: by 10.46.84.18 with SMTP id i18csp5694911ljb; Wed, 18 Apr 2018 03:05:56 -0700 (PDT) X-Google-Smtp-Source: AIpwx4/b7KWx7l4SX9NjBKxGthk5TQoY+oWJ9ARKPL2wr/QTBGyeZPCUnTFsZMNvY4CY+VZydzMQ X-Received: by 10.98.130.140 with SMTP id w134mr1407602pfd.127.1524045956346; Wed, 18 Apr 2018 03:05:56 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1524045956; cv=none; d=google.com; s=arc-20160816; b=ExzlutLgE44q84Qip0tzPZloD/Wwe9F0sKU+ON9d+YXHSyNDFAUXrINIwryz/y/BOx 1Qu9u7T155dHknB75iXzWm7eRklwjR4bxq2p8AC/u+KlNNynJWm8iyGN0Pq78MkKtMAm yoy38/7T2GEYIEVAMEKUdBiFJl0BTzQM8MWb/t4FLYPpcNmlimAdwPY3TmBUW6bh8La0 hWhNscPUXgbAd0PD0jeSv9gx4FoZAYDfddUxaJ8B28n7nJ2UoM+NEXW17kSVtsqkxcjI RNMSakSKujqQzIzzf28Gg9V3sTc1cXUiYflZJNSXqQvpsaGw/r4nEyHVvKvcTE9sbBMF 7gng== 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=TZBj15vhcZkL16Ta0GEOKA6YFvs3QXuieY8qcfuQ2Dg=; b=Q+TFDEJmLomyYytBzrCxW60L6mgfHh9keS8yt6IQCLfWSCeR/i10qNECg39IfvADo1 RZpI1wsXSi9rz3wgmnm+Ok9+u6bBIfPriWabqgkdELfZj4Rw19JKapRxKrsOClp+vv3y Z7ddxpz3Wrz8ms8GNk2+wFh+sweIiSg3OmuY6sGezl7SnGSkNwMVRd4A0oRUN6QvwdLe eDo0tNq6zdYLrGQXaCASj2a4nm8j2zlJTNQBAWg5xiKYBhEVPVz6PVK7Z2hlfh0hN7Uc Vujm5XI4NHiZlvyYZ2ElWS8ycgIVawhj5pktc9rDfVE/nJkBkYgHsHoJjQmu6iJ1cFSy +l+w== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=f4ScOL+k; spf=pass (google.com: best guess record for domain of linux-wireless-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-wireless-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 e15si793285pga.573.2018.04.18.03.05.56; Wed, 18 Apr 2018 03:05:56 -0700 (PDT) Received-SPF: pass (google.com: best guess record for domain of linux-wireless-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=f4ScOL+k; spf=pass (google.com: best guess record for domain of linux-wireless-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-wireless-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 S1753426AbeDRKFn (ORCPT + 3 others); Wed, 18 Apr 2018 06:05:43 -0400 Received: from mail-pg0-f66.google.com ([74.125.83.66]:45112 "EHLO mail-pg0-f66.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1752983AbeDRKF2 (ORCPT ); Wed, 18 Apr 2018 06:05:28 -0400 Received: by mail-pg0-f66.google.com with SMTP id z21so626447pgv.12 for ; Wed, 18 Apr 2018 03:05:27 -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=TZBj15vhcZkL16Ta0GEOKA6YFvs3QXuieY8qcfuQ2Dg=; b=f4ScOL+kvsB1n2oHrfxVv7siv3wGHJzKQlab2ujoKM5bBCjc+vd79n3HDdSDM+P6Hp gPVgUYJtiRATXiFEv4omAat3hkGhHbwHoHKFXG2cnHVzU1SISvSR5YZLHvltIrk3Kv93 /xJqnQjFCQklk5b/HUG2RXJNccwlozf68YxsE= 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=TZBj15vhcZkL16Ta0GEOKA6YFvs3QXuieY8qcfuQ2Dg=; b=quvwO8QZ3j4FscdqsdsVHCz9RQrqjvSxsrGhw5utb7UkgV4Gahd278mAKDRsNPIjt3 MUQ6L6HnJ+qWGKxDuvHCGMpp82vwr9GlU2muoy6ObZw3qsxJmzrD1KZD0alQGnQz7qSL aXpp4GNT5qj53H6Sxzk4wBN4wBqWhyCexfzYBLmU3TsY1pK5yClWxnxBxcAaKyRkabUD OLv7nVf/JOpTXlnBdiPfinbEPKnwQqMdmvFkTY3K3Dm2Iq3+q9UKF/uilIquiulu3CBc 4vZ8IpcILMA+T20mjXVIzfDkwVgSUCtVNnlGuor9Y+HEdziO+BywKoyEJTtFKGAsLxEy ln+A== X-Gm-Message-State: ALQs6tD7ZZAG4Dm9/HsDbe8ynd6IU9siou20VQmNtTIOzG37voc7aswp VFo7yN3Xx9IGdtsTfOpK9gLuIg== X-Received: by 10.99.125.78 with SMTP id m14mr1231947pgn.190.1524045927437; Wed, 18 Apr 2018 03:05:27 -0700 (PDT) Received: from localhost.localdomain ([106.51.17.69]) by smtp.gmail.com with ESMTPSA id z16sm1970298pfn.101.2018.04.18.03.05.23 (version=TLS1_2 cipher=ECDHE-RSA-AES128-SHA bits=128/128); Wed, 18 Apr 2018 03:05:26 -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 4/4] NFC: fdp: Fix possible buffer overflow in WCS4000 NFC driver Date: Wed, 18 Apr 2018 15:35:04 +0530 Message-Id: <1524045904-7005-5-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 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 --- drivers/nfc/fdp/i2c.c | 10 ++++++++++ 1 file changed, 10 insertions(+) -- 2.7.4 diff --git a/drivers/nfc/fdp/i2c.c b/drivers/nfc/fdp/i2c.c index c4da50e07bbc..08a4f82a2965 100644 --- a/drivers/nfc/fdp/i2c.c +++ b/drivers/nfc/fdp/i2c.c @@ -176,6 +176,16 @@ 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, "%s: corrupted packet\n", + __func__); + phy->next_read_size = 5; + goto flush; + } } else { phy->next_read_size = FDP_NCI_I2C_MIN_PAYLOAD;