From patchwork Fri May 8 12:32:54 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: 226115 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 9C843C47254 for ; Fri, 8 May 2020 13:17:40 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 7098B218AC for ; Fri, 8 May 2020 13:17:40 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1588943860; bh=1dRfvo3y1eTNxKbDkM0vF8Peuzsi+lmgYxwyqGR7jto=; h=From:To:Cc:Subject:Date:In-Reply-To:References:List-ID:From; b=iIH03texu1uqWk8sLMat4LsoAOkuasmluo2wkGu7HUr/ABp2f80+K7jzWsO6hOvsg ldNyGT2e8djjMwa9uXXp8kbfIw3Ryp0brFGR+Y5lBVC+GmI65ldOeFweecEu+USmG/ 7e3MF7oHfvSOdAqK4SRbeHeraoUJk2zJ9z7Azfoc= Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1728483AbgEHMnq (ORCPT ); Fri, 8 May 2020 08:43:46 -0400 Received: from mail.kernel.org ([198.145.29.99]:41588 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1728156AbgEHMnk (ORCPT ); Fri, 8 May 2020 08:43:40 -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 AA7D121974; Fri, 8 May 2020 12:43:39 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1588941820; bh=1dRfvo3y1eTNxKbDkM0vF8Peuzsi+lmgYxwyqGR7jto=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=2uwjnrwgBBKe3j285/EgyD9uBSXyUJxDSDGGLMv5wTE/5uIkX+kQUFrf6MVpmV9KD CSxvBO6tYjcmBH4C7axUk5Si+2s/5wYIL9n+uGnGowweSb4ZnDXnMbztAYwe49fXXq KCGoo1IeOw6Fowd512MyU6jQLZlCsXidilh1NOs8= From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , stable@vger.kernel.org, Bart Van Assche , Hannes Reinecke , Christoph Hellwig , Andy Grover , Sagi Grimberg , Nicholas Bellinger Subject: [PATCH 4.4 183/312] target: Fix a memory leak in target_dev_lba_map_store() Date: Fri, 8 May 2020 14:32:54 +0200 Message-Id: <20200508123137.353779595@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: Bart Van Assche commit f0a8afecb29ad0005e7e946228a0ef5422058b85 upstream. strsep() modifies its first argument. Make the pointer passed to kfree() match the return value of kmalloc(). Fixes: 229d4f112fd6 (commit "target_core_alua: Referrals configfs integration") Signed-off-by: Bart Van Assche Cc: Hannes Reinecke Cc: Christoph Hellwig Cc: Andy Grover Cc: Sagi Grimberg Signed-off-by: Nicholas Bellinger Signed-off-by: Greg Kroah-Hartman --- drivers/target/target_core_configfs.c | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) --- a/drivers/target/target_core_configfs.c +++ b/drivers/target/target_core_configfs.c @@ -1980,14 +1980,14 @@ static ssize_t target_dev_lba_map_store( struct se_device *dev = to_device(item); struct t10_alua_lba_map *lba_map = NULL; struct list_head lba_list; - char *map_entries, *ptr; + char *map_entries, *orig, *ptr; char state; int pg_num = -1, pg; int ret = 0, num = 0, pg_id, alua_state; unsigned long start_lba = -1, end_lba = -1; unsigned long segment_size = -1, segment_mult = -1; - map_entries = kstrdup(page, GFP_KERNEL); + orig = map_entries = kstrdup(page, GFP_KERNEL); if (!map_entries) return -ENOMEM; @@ -2085,7 +2085,7 @@ out: } else core_alua_set_lba_map(dev, &lba_list, segment_size, segment_mult); - kfree(map_entries); + kfree(orig); return count; }