From patchwork Wed Dec 20 19:51:22 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Amit Pundir X-Patchwork-Id: 122491 Delivered-To: patch@linaro.org Received: by 10.140.22.227 with SMTP id 90csp6023499qgn; Wed, 20 Dec 2017 11:51:46 -0800 (PST) X-Google-Smtp-Source: ACJfBosIjmkmKUr/0ZQyUz9xAnbsc2Pw0cyy1P2MMUcyB/xjjfK4p6NxcxJL3tYQSCNrDpXPvzTg X-Received: by 10.84.224.206 with SMTP id k14mr8077945pln.403.1513799506563; Wed, 20 Dec 2017 11:51:46 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1513799506; cv=none; d=google.com; s=arc-20160816; b=LgzSvFMQ3OUjkpWwPO2KaqiCLkt3ETfBTdWnM44sP+YVl1715P/V9pGVJD6W29sSZb oL2oqt/enssU4mOd4onemuxozUEXTlfAboNpAu6zfBs1+0Z79+WMqrZhyQos0a6XCdDA mMOrfLsriTaR5ArXWT7/L6/9nANV8piHjf/GKheQBK6GevJOP3WtD0RQlRQrI4EA2i5a /1NxJ01+j/Aw/mP0yaQ4QqiMEBk9XhBBV8ZkBkQ4lu0g9aDrrtJyqoKYoXNV6HOIkmYL tDTIaJGY/Fg21K9QjHl/5NzgUUWucSxCKdsl7VIUQym9Sna9eHeOrwERVs9/jHig/VMG CNnA== 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=HcXK5QhJLsNnIdafcboJFIL1D+9+ZVKtG6zA+N2XozI09m1G8KGzKsEIBLAckJGU8Z ujK0OtTDARmevTtbsFZiCTPol4fCF84/EMdNUUBwKDWDZ0PFP1XydxEHQF9T31BeUJsm nDvmtaOFGaSscgwXRKtgL+7UEoItGYOLzGIBiTdKKyWY2um9hJSpS8q06TDusjbZOlDF 3j/j+bVN5B5xmKJ2FEsIW1xtK8QbHRq+G/fFOKLIDMr7AzHVJ41tBi6sbPygTtoBxODq HqeGCRn/P2EO3b2Rwme7RGYyYAGW0R9fe2TN9IZxNG25GhqArKdWdGMOrwq3kx49Zu5k 9epw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=g6Kqpflg; 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 d13si5902212pgn.383.2017.12.20.11.51.46; Wed, 20 Dec 2017 11:51:46 -0800 (PST) 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=g6Kqpflg; 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 S1756745AbdLTTvp (ORCPT + 2 others); Wed, 20 Dec 2017 14:51:45 -0500 Received: from mail-pl0-f68.google.com ([209.85.160.68]:37412 "EHLO mail-pl0-f68.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1756615AbdLTTvj (ORCPT ); Wed, 20 Dec 2017 14:51:39 -0500 Received: by mail-pl0-f68.google.com with SMTP id s3so9608559plp.4 for ; Wed, 20 Dec 2017 11:51:39 -0800 (PST) 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=g6KqpflgqnaQOgO+ea8Nn5HIDUfPH3KJTwVwO9kkhOEZQWKSDVE9/t1r0snEnbCtMg IdgbfV+NpenUdianA3yD2IddS7rStV/PC8LbQx6v4wTFfpZJP7DAWT6YdRizFvgnDdIX Hy1QGRVOFlfUxdh2e9MzS44MhSB3GusLd5yKk= 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=FJDys1QTpiSZrVqGh59jlZ3AoS7Ypdt69/wvQFnSzaoSn2OZETUTGMWN0Oe+WkpMmy GdBZiJM1LfPoKf9/GFfLTpyXa4nwGmdDB5xHT6TStFhsJlc0leAd2LYgKiGcwBbhPbB+ sFlsoclh+mwrnlUtYftWR+qSy2JO2CGhhF+FEvZfJuGx2cfUrPSvJPH1jn4gKSXrb0dD QbNm/cOy7JyARZ3/YWW7gcPV+37DKkoISVTQ6XJZj1OQlO7Ty7G0QKkvWEDbSzgRkW+L iXhgUejKeXsuFo+zK8yCkRaBA/hjljC096LKM9ul8uRzWHxa9hDO97jEnbbcyZmcJ8Kh o2LA== X-Gm-Message-State: AKGB3mIntZiHbNbsp3VjF0JASayg74toVeygxrevHd6uziQGqgr7fXWp 08dgBD7YsmDaOl8XIvW+URkzIw== X-Received: by 10.84.242.134 with SMTP id d6mr7934028pll.98.1513799499067; Wed, 20 Dec 2017 11:51:39 -0800 (PST) Received: from localhost.localdomain ([106.51.17.191]) by smtp.gmail.com with ESMTPSA id g2sm36715867pfc.130.2017.12.20.11.51.35 (version=TLS1_2 cipher=ECDHE-RSA-AES128-SHA bits=128/128); Wed, 20 Dec 2017 11:51:37 -0800 (PST) From: Amit Pundir To: lkml , linux-wireless@vger.kernel.org Cc: Suren Baghdasaryan , Samuel Ortiz , Christophe Ricard , Andy Shevchenko , John Stultz , Dmitry Shmidt , Todd Kjos , Android Kernel Team Subject: [RFC][PATCH 2/4] NFC: st21nfca: Fix memory OOB and leak issues in connectivity events handler Date: Thu, 21 Dec 2017 01:21:22 +0530 Message-Id: <1513799484-12505-3-git-send-email-amit.pundir@linaro.org> X-Mailer: git-send-email 2.7.4 In-Reply-To: <1513799484-12505-1-git-send-email-amit.pundir@linaro.org> References: <1513799484-12505-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 Dec 20 19:51:23 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Amit Pundir X-Patchwork-Id: 122492 Delivered-To: patch@linaro.org Received: by 10.140.22.227 with SMTP id 90csp6023561qgn; Wed, 20 Dec 2017 11:51:50 -0800 (PST) X-Google-Smtp-Source: ACJfBouVQnt6vDCmLY4AJAWTaSpFxcbG7L6sG0j4lPMg9fkqXw4rK//vNOVcZnKQJanZDnOYYN2p X-Received: by 10.99.101.66 with SMTP id z63mr7424755pgb.426.1513799510042; Wed, 20 Dec 2017 11:51:50 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1513799510; cv=none; d=google.com; s=arc-20160816; b=MhNwi0O9BorlKuY2AVaj1PYnI9qoHx+A+Yb4oNnPbMtQcQrXuxWjb7n+JbjOwxN+kE yyAFmpQ8oAHY9Jhlmb9q3q+Mc/dy4Xza3gQNhtMyJHBqbhoUsg17hOOE5WSrL88RFLbq aKbfrrFs67fO1EFjPdK8iiEEtbO/jdUbMrfztpI33Xpy50erDaMzpOASqyn+JrfAe6IY 4mmgeu8WRsOsm7tYXYA8PWJUat8lorWFCXtIf1QbTN6lRzVzlGB0MV3EwCfHmFNY3NaR /r0VF3C9QoPoU+0XMV4Ug/d83GT0OJYfosza1349gJVYTD45e6cldaKHj4J6HmDxikzJ uUFQ== 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=KpKW3aPjV82SBufNPUgvSXs6uQzi+sN1usCFrEYrpYBLc1fzeYgx+fvzGNWo1wVg4t lMrFQ4PVVvRQ+5UJU1APPMLNQz0tQOs3mxrcdXi/L6POSmqmvuboVxZfCulPw1DMZsUO TFNTt6dFyX6NYolC8hFDROLR5Xql4THxjXfN//1TzKNRoet+1Wh6G0wF5wmvNmHfksDg 7SrpuXGcO+UHnDZD+XurQSpKJPD4FfzR8vCCuhcMgsUrgdV2MeOu5ElNSB4EHgKgUSps ++tZy1xlN8qDSOjpN1CsTBvPvsYJIo4bSkac987WWjkRfIAVSBWsfIgeU3qIGhbngBJb y17g== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=ictfZkm/; 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 i9si12288544pgs.523.2017.12.20.11.51.49; Wed, 20 Dec 2017 11:51:50 -0800 (PST) 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=ictfZkm/; 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 S1756782AbdLTTvr (ORCPT + 2 others); Wed, 20 Dec 2017 14:51:47 -0500 Received: from mail-pg0-f66.google.com ([74.125.83.66]:42671 "EHLO mail-pg0-f66.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1756746AbdLTTvn (ORCPT ); Wed, 20 Dec 2017 14:51:43 -0500 Received: by mail-pg0-f66.google.com with SMTP id q67so3092573pga.9 for ; Wed, 20 Dec 2017 11:51:43 -0800 (PST) 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=ictfZkm/czEh5F5dX0Q+WEfhCfrkDSDHdL09pN4GGlqU+HfXSdt4sH/FK5qmHKglUg 8vyEkcXVywZmq6cFj4NYZppAD9XIq5eZhMZNGBrIVmlwi/3yAZ+lqGIyBx3A36Njod3O 2Fo7U6hgUDbiyVKh6T8BEwpmU0ErAaoQtxra8= 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=pCrxMEMWigXTGEJdaWLSuQsMafC+6qSXtRDnTNX4gOQ3XaJavU1y7pa1VDpeGYbO8Q nc3ptbvPujnRcQaziP+RuRVW4BaXA/e7OfjnPQyQmkzFSocrIdpT6+D9JEjl/1wQWE3V LngynDQdTbaJSjpYO0VtnO52Cf6dDx5Iobfgmr7oMiAMf24LDg64haVd6meeH6VyXOrp BvYGYUo8bqvUuP9xeTiGKDuanExYlhOkUSrgo0SD/un3LDiAMEPMFmdAIqnlf4el2n67 CINZcStfmOvTpt27/STzZp0zIz3JYFjWyoeCKvqfiDNWsHzEmxBUsQqMwyO3gZcN2BlN jiJg== X-Gm-Message-State: AKGB3mJqoAry173oTOXlbs/wdZQM8TH/en4zA6NUsNQnU4axrvzlDNch 81Srd4pv+ysRWFrqI3q2AcqsiA== X-Received: by 10.99.113.20 with SMTP id m20mr7196139pgc.67.1513799502880; Wed, 20 Dec 2017 11:51:42 -0800 (PST) Received: from localhost.localdomain ([106.51.17.191]) by smtp.gmail.com with ESMTPSA id g2sm36715867pfc.130.2017.12.20.11.51.39 (version=TLS1_2 cipher=ECDHE-RSA-AES128-SHA bits=128/128); Wed, 20 Dec 2017 11:51:41 -0800 (PST) From: Amit Pundir To: lkml , linux-wireless@vger.kernel.org Cc: Suren Baghdasaryan , Samuel Ortiz , Christophe Ricard , Andy Shevchenko , John Stultz , Dmitry Shmidt , Todd Kjos , Android Kernel Team Subject: [RFC][PATCH 3/4] NFC: Fix possible memory corruption when handling SHDLC I-Frame commands Date: Thu, 21 Dec 2017 01:21:23 +0530 Message-Id: <1513799484-12505-4-git-send-email-amit.pundir@linaro.org> X-Mailer: git-send-email 2.7.4 In-Reply-To: <1513799484-12505-1-git-send-email-amit.pundir@linaro.org> References: <1513799484-12505-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 Dec 20 19:51:24 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Amit Pundir X-Patchwork-Id: 122493 Delivered-To: patch@linaro.org Received: by 10.140.22.227 with SMTP id 90csp6023611qgn; Wed, 20 Dec 2017 11:51:53 -0800 (PST) X-Google-Smtp-Source: ACJfBov8GuzVF32u2BadcJKQUkKkqi4l92WprfaKiClU/vVjBEZiZjnr8uMFXueMICegiAiSkBbT X-Received: by 10.84.215.2 with SMTP id k2mr7972227pli.60.1513799513700; Wed, 20 Dec 2017 11:51:53 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1513799513; cv=none; d=google.com; s=arc-20160816; b=NRWfyxF+Fm835qZ5NE+exV2rvR4fU2xxX70z4HN/eomybrI32koVR7S4jXwnBebgqZ BwRoGsSp5937VPqISIdMvBkIviBLftbfOI0SAYO/1LS/bcGiG7EVWIjjSgl3fQzLP2nt NpYSybKnPpK/1Xcw1XPRIk+I6WwhuEGbKoK2y/45HU/kV/O0LtPqhc7YNn1HpYvCoQZ1 cKZUUdLArlOBlN06KNH91QM+Da/z2Nu/tViuhGHhGsL95TaUgwN2SD45ik/8DJD71pH7 ZPwBwrY6m/maAh55EhQsUGju7+FTLXS/n1rjAmAimJil8PTmB8y00m0Gs2dVYbMu7e0B GjRg== 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=oLcN9knIuQElfy1GoYsG/KTm3UNiYzPtLDOolHMuPhZOFd9KTJqiddEFyvVp4N0NMZ 2BKlLtanraxz6XFS5LWL/QO1URbZLCPN//DXUGhL5pjmYsRArsNLm0q0dEl+gsNbOAbR QhAnk+cgZ3nA3qaFFrtA/qG6foVsuYtzxQnvRBkhqG3I+0dSRgSYq/YT8GicQynfzmQg DCBYNnhMYaIUGZCDKjIfysRYtxYEhWwnw0dd64Fosl4j73bwmkHCecmOO2T1/TDYpY/Z P1NosrutumBws7kEKN+RfB0cb0rhQaORCVy2TmKcOEl+4Ea3SNIog/FV5h2Z/sgxEKBD OtLg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=Q3SGWrIP; 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 i9si12288544pgs.523.2017.12.20.11.51.53; Wed, 20 Dec 2017 11:51:53 -0800 (PST) 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=Q3SGWrIP; 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 S1756552AbdLTTvv (ORCPT + 2 others); Wed, 20 Dec 2017 14:51:51 -0500 Received: from mail-pf0-f193.google.com ([209.85.192.193]:35644 "EHLO mail-pf0-f193.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1756774AbdLTTvr (ORCPT ); Wed, 20 Dec 2017 14:51:47 -0500 Received: by mail-pf0-f193.google.com with SMTP id j124so12995487pfc.2 for ; Wed, 20 Dec 2017 11:51:47 -0800 (PST) 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=Q3SGWrIP5PNIWoVuBNRAsp8M9VTBLhmgqVRe9Dcqt96Nxw2YjJJgqc2Gx56VTsRRlW uo7uJ2GkbBuBn7VvHb7oSiGQGZLKV5+tBk3S5S06acutcx/00ipwPI/BZI08ndoh1ob4 5zTd6mR9hqdTahXjuRCYc25nZ95k23+Oxajoc= 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=rvA82/I2eH3kGUb1AkUZliueKuGzYZrV1XB6LJwPW3I1UYYUJRles7zniWcBpx/VgW Wk7lIQnDhlcdwxYio6y0OUGQf94JQ4XI6AYjhsft38J20MueGgM5wmcKvj3c26tnkdJc z9jNO/Dz9h71NSrViUlLIftNeQoIVXtsrCyFEm1CKBbtw+c1ldHPPCu+J+wbWl5v1qbO 8HSug0DuQV4ijRAxG+1uV2U0SpRpTIKSqHX8FO9j7Fh0ZUrOQ+l/nzL3jptMhfRMf6cF C5ppPbFe9FyyedYhELX+PL8W21pQMmRKmJZkW8P51u4BRakOATh3EFmRa2JmB1nBwkBU 4oXw== X-Gm-Message-State: AKGB3mIGpANSTH+YdQlMhvw3uipvjN2tIF6+PPLWuLikXyGyuixiSjy2 g0TWCWIu45koHyl/ele0tjHgJg== X-Received: by 10.99.117.12 with SMTP id q12mr7407819pgc.412.1513799506827; Wed, 20 Dec 2017 11:51:46 -0800 (PST) Received: from localhost.localdomain ([106.51.17.191]) by smtp.gmail.com with ESMTPSA id g2sm36715867pfc.130.2017.12.20.11.51.43 (version=TLS1_2 cipher=ECDHE-RSA-AES128-SHA bits=128/128); Wed, 20 Dec 2017 11:51:45 -0800 (PST) From: Amit Pundir To: lkml , linux-wireless@vger.kernel.org Cc: Suren Baghdasaryan , Samuel Ortiz , Christophe Ricard , Andy Shevchenko , John Stultz , Dmitry Shmidt , Todd Kjos , Android Kernel Team Subject: [RFC][PATCH 4/4] NFC: fdp: Fix possible buffer overflow in WCS4000 NFC driver Date: Thu, 21 Dec 2017 01:21:24 +0530 Message-Id: <1513799484-12505-5-git-send-email-amit.pundir@linaro.org> X-Mailer: git-send-email 2.7.4 In-Reply-To: <1513799484-12505-1-git-send-email-amit.pundir@linaro.org> References: <1513799484-12505-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;