From patchwork Fri May 8 12:32:22 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Greg Kroah-Hartman X-Patchwork-Id: 226116 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-6.8 required=3.0 tests=DKIMWL_WL_HIGH, DKIM_SIGNED, DKIM_VALID, HEADER_FROM_DIFFERENT_DOMAINS, MAILING_LIST_MULTI, SIGNED_OFF_BY, SPF_HELO_NONE,SPF_PASS,USER_AGENT_GIT autolearn=unavailable autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id F13C6C47254 for ; Fri, 8 May 2020 13:17:34 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id C564920870 for ; Fri, 8 May 2020 13:17:34 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1588943854; bh=yGfNa+n5Nyg6FPVOOg9qf7jiROMVkZog5tzowtrAA5Q=; h=From:To:Cc:Subject:Date:In-Reply-To:References:List-ID:From; b=I3+hQUe0KnSjpOABZyHSe57YQ0Eu8xEJqb1V0bm6x5ASA3CIrXmeJ4tjBYcqWsZ/p o64kWtWPwEiq50BqkF98QTSZ+8licF8fnXEsQ0rU9pAiz31IMG3ZUVen9o5B1SRZw1 MFXBChV7jpDAP8TBtosHqQ0g6r8anUL522ZV3Dz8= Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1727803AbgEHMn5 (ORCPT ); Fri, 8 May 2020 08:43:57 -0400 Received: from mail.kernel.org ([198.145.29.99]:42022 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1729116AbgEHMnz (ORCPT ); Fri, 8 May 2020 08:43:55 -0400 Received: from localhost (83-86-89-107.cable.dynamic.v4.ziggo.nl [83.86.89.107]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPSA id B00CF20720; Fri, 8 May 2020 12:43:54 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1588941835; bh=yGfNa+n5Nyg6FPVOOg9qf7jiROMVkZog5tzowtrAA5Q=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=0fVqGiaCDbdAeHADlfS1YqVmqy8MjhY3qvmxrYGHGGIon9gtEC9Qs3dfKugwBIKf4 lDM+HODyFf4xCfjDkkBhCRwO3O3ULZhQrS5KH9Gs3vTMp/XBa8LbiB8g7hkuLpPoOS yxgW72hidAK3bYzGIkErAFJ+PMas4H4qPOUGOKCw= From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , stable@vger.kernel.org, Christophe Ricard , Dan Carpenter , Samuel Ortiz Subject: [PATCH 4.4 151/312] NFC: nci: memory leak in nci_core_conn_create() Date: Fri, 8 May 2020 14:32:22 +0200 Message-Id: <20200508123135.083649102@linuxfoundation.org> X-Mailer: git-send-email 2.26.2 In-Reply-To: <20200508123124.574959822@linuxfoundation.org> References: <20200508123124.574959822@linuxfoundation.org> User-Agent: quilt/0.66 MIME-Version: 1.0 Sender: stable-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: stable@vger.kernel.org From: Dan Carpenter commit c6dc65d885b98898bf287aaf44e020077b41769f upstream. I've moved the check for "number_destination_params" forward a few lines to avoid leaking "cmd". Fixes: caa575a86ec1 ('NFC: nci: fix possible crash in nci_core_conn_create') Acked-by: Christophe Ricard Signed-off-by: Dan Carpenter Signed-off-by: Samuel Ortiz Signed-off-by: Greg Kroah-Hartman --- net/nfc/nci/core.c | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) --- a/net/nfc/nci/core.c +++ b/net/nfc/nci/core.c @@ -610,14 +610,14 @@ int nci_core_conn_create(struct nci_dev struct nci_core_conn_create_cmd *cmd; struct core_conn_create_data data; + if (!number_destination_params) + return -EINVAL; + data.length = params_len + sizeof(struct nci_core_conn_create_cmd); cmd = kzalloc(data.length, GFP_KERNEL); if (!cmd) return -ENOMEM; - if (!number_destination_params) - return -EINVAL; - cmd->destination_type = destination_type; cmd->number_destination_params = number_destination_params; memcpy(cmd->params, params, params_len);