Received: by 2002:a6b:fb09:0:0:0:0:0 with SMTP id h9csp445565iog; Mon, 13 Jun 2022 06:08:18 -0700 (PDT) X-Google-Smtp-Source: ABdhPJywUH0bjSldMzXHL+Za1pcBfZvohiqRmaWGF9opqpGY3DsC/ZtsXKK0+p6kNel0HtuqVzbE X-Received: by 2002:a17:906:a105:b0:6fe:9a27:85c7 with SMTP id t5-20020a170906a10500b006fe9a2785c7mr50603844ejy.315.1655125698502; Mon, 13 Jun 2022 06:08:18 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1655125698; cv=none; d=google.com; s=arc-20160816; b=NvmqpZn4bUonhoonJJB3U4Wg0Dpe1cOZWutTHPfqWuPllPgOFH4OmfQFcgeO5T6IU+ oVVGlPhyxIUv92ll26dZnFR4NkFzv1HW1HpgH+kUPpo8fPpG5hOcjoMzIGKivVHbg2Ec ApY5zFP/WK0jSCyngExWAxIjFAykNjYbkIAiJ8m4Fn4nzrF3D/tMdtvo0+40IkT0XBwp cXSUqMzMdOWaz8uz8OFTqObGJz+8jLVbXrQVSGe8zrJSkF2QrZooV2yelVx44YsEcOdc zipgu+SLVUdqqVzEKVHYTFjXWJenJBxWhDNZbd3KD42IZHdsRp9veLq9oZaT36UIBmGA UoWg== 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=YA2CTwAJB5vqNaCB2y04d9Yqp22jOQdv/xMqOErPN+bdDiBI8FvZqqCNgVzgtORhWh q375TwbAzcfXRiPLoQjLwkz5Yu7NWxN4YI5+Rxsy3BhnkRdczBZYlAdTEL34oT8Cj2eo whAbDwJt0dNz6SBUYYyKkyXVRsu3/y9wo/qIOqnAc/Nr0pd51F+ojIX9CAEDMkQJFqmq dpAmwjlVYko3Y5xKptVPd6Nwwxaln9hmQR52Nzprts58kNusSKELg6R7vLo76/vA22/y +E9vCihgEQq7ki5s9fKYwDifif5PYxpnJCrtiJqe6MiizPn5AA1dzogOJbanaxL//4Cr VaEg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b=0KFJ4D+U; 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 dp17-20020a170906c15100b006fea036b38esi8219144ejc.310.2022.06.13.06.07.51; Mon, 13 Jun 2022 06:08:18 -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=0KFJ4D+U; 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 S1343930AbiFMKdf (ORCPT + 99 others); Mon, 13 Jun 2022 06:33:35 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:42486 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1346594AbiFMKbA (ORCPT ); Mon, 13 Jun 2022 06:31:00 -0400 Received: from ams.source.kernel.org (ams.source.kernel.org [IPv6:2604:1380:4601:e00::1]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 75FC526AED; Mon, 13 Jun 2022 03:21:30 -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 ams.source.kernel.org (Postfix) with ESMTPS id F2353B80E95; Mon, 13 Jun 2022 10:21:28 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 631ECC36B00; Mon, 13 Jun 2022 10:21:27 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linuxfoundation.org; s=korg; t=1655115687; bh=VLAUu/pBbU0WbMGamu1ApVdJKC+8dNefuYHs3rDbbgo=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=0KFJ4D+UXMGCndIqa0FgsjqCv9mAfVkBOUUSHuP0R5fUtT5R+j95IohCSQFciN515 k5X8UaIDTOnok1IMNrijxuRYzngSXbDuSyYaMu6Qh/+L8xeorCY2Hmhj8B3NTrzPj/ Jf6uQaGt5hNgXkZ08lEGtXnc48fckZompKsrP2ew= 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.9 162/167] nfc: st21nfca: fix memory leaks in EVT_TRANSACTION handling Date: Mon, 13 Jun 2022 12:10:36 +0200 Message-Id: <20220613094918.973482189@linuxfoundation.org> X-Mailer: git-send-email 2.36.1 In-Reply-To: <20220613094840.720778945@linuxfoundation.org> References: <20220613094840.720778945@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);