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; }