Received: by 2002:a6b:fb09:0:0:0:0:0 with SMTP id h9csp443573iog; Mon, 13 Jun 2022 06:06:51 -0700 (PDT) X-Google-Smtp-Source: ABdhPJytSZK0oWTfVL7J/2UHjy3RgyA8EOIk2UsX8FQUdhxVMiXFTZg0TSFPuW3TjjFHsJ8DN9jz X-Received: by 2002:a17:906:6492:b0:712:1f5c:a2d6 with SMTP id e18-20020a170906649200b007121f5ca2d6mr15478614ejm.404.1655125611622; Mon, 13 Jun 2022 06:06:51 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1655125611; cv=none; d=google.com; s=arc-20160816; b=T0mpgDvtPLrFknJ1o12+6RxGVWFu52eBjavmRg8/xKvOVIFAJEpW9DiO6VPX8hY7Hf WLZ26ukYyMv0lyLLA8q2PXovTEILeqrVVVmuNw2T5i3NQAfxZ9Y8stvlzc1sscg8cbaN B3P0vctpIyKSPTUO+hhqyL9GCvNGBS6OS0bXeK/BMdJzMfpacy0Kr/iCkUFwWufyLjVh bBEO90mxyZNWAfEeou2vJhH82qqMKYzGHLApr4bLLyDD/UPeDb1CtD6mqdKBsmUzJepO 6aGI0hPLfyCRaXWk8Rc8sI77/YZibMuyPdSnAU4cgg4L+dDj0mz4x7kJOHi1RmHLiD0A 40fg== 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=poelnGo9B2eHdwrFou18mTCoKf8Z1ht9oFW6yXNNdlA=; b=0/XnkQmJlTKGxlIs83VfMuHM0zgw2KLP+SeoBlC2Ma6WMrLpSYyOLWW70CBVZrvi5c LRD8edxbvse6iniZlyMzcpHzHJFbP5jQ3D14pdZR79Ag5bLnimw+zm6N+jht0xkLsgCZ g9Q/YWd2OKVRNy4wCOMGxVlG0UYDzLKXlWeHxtvj7AEY1i9vzkRCGm1EbqKSh1rtQ3Q7 QBSKb3QnLsai9JJr8yvYiVuH4VYN57CHluzoeRE3iYpSNiC5epClyzm3GTg4dmuoJzC3 3uAfPquW0mCsW6tvS5P62LfEzWOBtPzU+Tp6/edWkYSPi/jW3dSFbMpC71izfCrW/895 8TDQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b="ZG/l2uUt"; 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 i27-20020a170906265b00b006e88cc5c374si6413978ejc.179.2022.06.13.06.06.16; Mon, 13 Jun 2022 06:06:51 -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="ZG/l2uUt"; 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 S1357307AbiFMLxv (ORCPT + 99 others); Mon, 13 Jun 2022 07:53:51 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:56610 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1356694AbiFMLt1 (ORCPT ); Mon, 13 Jun 2022 07:49:27 -0400 Received: from dfw.source.kernel.org (dfw.source.kernel.org [139.178.84.217]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id BD9384D26A; Mon, 13 Jun 2022 03:53:14 -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 45E3B6135F; Mon, 13 Jun 2022 10:53:14 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 275DBC3411C; Mon, 13 Jun 2022 10:53:12 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linuxfoundation.org; s=korg; t=1655117593; bh=2HQSmBnichybBCDp3mrh9Rp8FHzNIOjhmd7G3VIkAU0=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=ZG/l2uUt1vcGo3MOK5Lxk/e2owBmpp81TvGaEcYmlhPQs6hjT+W+BBaY8UYVVXeMn svabYLyC1YLMD9Ok9jsDZ/AytYuLuPRDMi7QHYuliz1Pf722tzoTUFxMchGVvUgQ/r Ttz4QgER+YdvpvXa92Elj6qZKqqOgaz0dp/wbnEg= 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 5.4 405/411] nfc: st21nfca: fix memory leaks in EVT_TRANSACTION handling Date: Mon, 13 Jun 2022 12:11:18 +0200 Message-Id: <20220613094940.966488160@linuxfoundation.org> X-Mailer: git-send-email 2.36.1 In-Reply-To: <20220613094928.482772422@linuxfoundation.org> References: <20220613094928.482772422@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 @@ -331,22 +331,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);