Received: by 2002:a6b:fb09:0:0:0:0:0 with SMTP id h9csp579850iog; Mon, 13 Jun 2022 08:31:00 -0700 (PDT) X-Google-Smtp-Source: AGRyM1vgbitdBXKMkkKeFz0jhLOkPiUPXBZ+wGHE4WK6qhnO0wsO0lGn+WqvLjNbxdGV+S6BTB8p X-Received: by 2002:a17:90a:f2cb:b0:1e8:8ac2:bcdd with SMTP id gt11-20020a17090af2cb00b001e88ac2bcddmr325776pjb.219.1655134260327; Mon, 13 Jun 2022 08:31:00 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1655134260; cv=none; d=google.com; s=arc-20160816; b=t+QZMmI4plUXI/ArIUgCocOLIjcOjSrU1zsN/2AwV3x0oWHdYh0xHKB6cySETwjGre 808NFOPtYKORHcdwwp4DmnJff/2RFHBiKHJDT4kILz6LxQO0+nd4UKYAdfPv7M9vYAK/ nUXufgBFQItNhmmp2mEi1EfccYgk8nTnrQoZUDHXsw8RwI8Y4p5SiS9mPVtiWYS8Rcgp CKIBPtnzOulNozXS/Neynf7yJ3WhWb6zkrXyjUASzCKEROVhNlH6Fq5g99whcArwSsj3 +q9oJAHSvexbYA4kWgIS3plUvY9SApWy46AnikOie0VpFSIx1IRyv0mm8M8bmDJCF3ok 9Pcg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :user-agent:references:in-reply-to:message-id:date:subject:cc:to :from:dkim-signature; bh=sGAwCXqBQiwcLEYfmYLZ1jKPv+VpcvI0UDhGPmL4STQ=; b=DiYW0tDoCTPauCkAGz2JIeRmY+Z3mEnn1MQPfwILQqTtAee2civJ3RXNwOOh/RDuUN QS9l4McvoXHTMM+FghR85QmYtwLdxTFZVrb4kh2jhcUqLpU6ZxqL8Us2v+el/uAakvHe 3wB5AW41MVxfcrO8ckpSfJiBZ6MoBE5xdeEb9r/Fg8VUUgQE5lk8kbuuVKvUePHt/us0 lUVYKRIMb4gjH3svLaPTLmJFbLAovj2RrkST73MTfpYj9Yv3b4DFhu+w0GqCY/gh9qGe /peJWCjEMEuMYf+kV4F6ehD7nTNX2Xav+hVrEjUC50cSsEsn2CO2oxQ/Q4z5snTXXHJI DELg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b=jU4nROSl; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linuxfoundation.org Return-Path: Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id w14-20020a170902e88e00b00167863f828dsi12168863plg.119.2022.06.13.08.30.46; Mon, 13 Jun 2022 08:31:00 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) client-ip=2620:137:e000::1:20; Authentication-Results: mx.google.com; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b=jU4nROSl; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linuxfoundation.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1352413AbiFMLRo (ORCPT + 99 others); Mon, 13 Jun 2022 07:17:44 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:43240 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1352664AbiFMLOK (ORCPT ); Mon, 13 Jun 2022 07:14:10 -0400 Received: from dfw.source.kernel.org (dfw.source.kernel.org [IPv6:2604:1380:4641:c500::1]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id D605B366B0; Mon, 13 Jun 2022 03:36:40 -0700 (PDT) Received: from smtp.kernel.org (relay.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by dfw.source.kernel.org (Postfix) with ESMTPS id D0FA6610AB; Mon, 13 Jun 2022 10:36:39 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id B78F0C385A5; Mon, 13 Jun 2022 10:36:38 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linuxfoundation.org; s=korg; t=1655116599; bh=VLAUu/pBbU0WbMGamu1ApVdJKC+8dNefuYHs3rDbbgo=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=jU4nROSlNmV04WICNuK1p73iwjCy7fTLwpVDXkbo7jiyF9Pe9/F8EpFWc76cb0Mte vXUzvCG/HPZNKhYlq4658UUvVz2L/Zyf0El/qkdtKdBzJ3UAoK0BaNkhnAPYBm2kVr V5lzQKZPo+SUQt/hC9TzxBUHVsd/hDyFJwfpbANE= From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , stable@vger.kernel.org, Martin Faltesek , Guenter Roeck , Krzysztof Kozlowski , Jakub Kicinski Subject: [PATCH 4.14 210/218] nfc: st21nfca: fix memory leaks in EVT_TRANSACTION handling Date: Mon, 13 Jun 2022 12:11:08 +0200 Message-Id: <20220613094926.993839081@linuxfoundation.org> X-Mailer: git-send-email 2.36.1 In-Reply-To: <20220613094908.257446132@linuxfoundation.org> References: <20220613094908.257446132@linuxfoundation.org> User-Agent: quilt/0.66 MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit X-Spam-Status: No, score=-8.3 required=5.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,RCVD_IN_DNSWL_HI, SPF_HELO_NONE,SPF_PASS,T_SCC_BODY_TEXT_LINE autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org From: Martin Faltesek commit 996419e0594abb311fb958553809f24f38e7abbe upstream. Error paths do not free previously allocated memory. Add devm_kfree() to those failure paths. Fixes: 26fc6c7f02cb ("NFC: st21nfca: Add HCI transaction event support") Fixes: 4fbcc1a4cb20 ("nfc: st21nfca: Fix potential buffer overflows in EVT_TRANSACTION") Cc: stable@vger.kernel.org Signed-off-by: Martin Faltesek Reviewed-by: Guenter Roeck Reviewed-by: Krzysztof Kozlowski Signed-off-by: Jakub Kicinski Signed-off-by: Greg Kroah-Hartman --- drivers/nfc/st21nfca/se.c | 13 ++++++++++--- 1 file changed, 10 insertions(+), 3 deletions(-) --- a/drivers/nfc/st21nfca/se.c +++ b/drivers/nfc/st21nfca/se.c @@ -332,22 +332,29 @@ int st21nfca_connectivity_event_received transaction->aid_len = skb->data[1]; /* Checking if the length of the AID is valid */ - if (transaction->aid_len > sizeof(transaction->aid)) + if (transaction->aid_len > sizeof(transaction->aid)) { + devm_kfree(dev, transaction); return -EINVAL; + } memcpy(transaction->aid, &skb->data[2], transaction->aid_len); /* Check next byte is PARAMETERS tag (82) */ if (skb->data[transaction->aid_len + 2] != - NFC_EVT_TRANSACTION_PARAMS_TAG) + NFC_EVT_TRANSACTION_PARAMS_TAG) { + devm_kfree(dev, transaction); return -EPROTO; + } transaction->params_len = skb->data[transaction->aid_len + 3]; /* Total size is allocated (skb->len - 2) minus fixed array members */ - if (transaction->params_len > ((skb->len - 2) - sizeof(struct nfc_evt_transaction))) + if (transaction->params_len > ((skb->len - 2) - + sizeof(struct nfc_evt_transaction))) { + devm_kfree(dev, transaction); return -EINVAL; + } memcpy(transaction->params, skb->data + transaction->aid_len + 4, transaction->params_len);