Received: by 2002:ac0:a581:0:0:0:0:0 with SMTP id m1-v6csp3003325imm; Sun, 1 Jul 2018 10:05:42 -0700 (PDT) X-Google-Smtp-Source: ADUXVKJXNeK4S9Z9UH37+pIGdWiLXV0cHBdb+yexPE7YMwnScFgQ6gZS+jYSn0cUnwClLCeuFpfr X-Received: by 2002:a65:6657:: with SMTP id z23-v6mr19467506pgv.257.1530464742580; Sun, 01 Jul 2018 10:05:42 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1530464742; cv=none; d=google.com; s=arc-20160816; b=iiXQ+w0lXDWWgKp8H3AkJIlU1Q7CJmUBwjMMfBR+eetCUQ4m2WXMFnuA6PxxwWkIjd w8d6SmVT8AgnQ/yBhL5KjVW/drSkanmgYxiEsyXbWtg9UMotxY5Tb3jHdVdMXt0mtBKA XNiDv57BF+/LVQzoFJGxtfsaHU7DANBBfZEXxtrDQBrTeKZtYKY2gjJUP0stoa3tyP7M jUIoxJ3UdE9gLfFB4uVBtgIpBTOpr363/eJDoqfvciYMPsHe7Q7cLItIxdRKqFOVnLQ+ prSZFoLa8rkz11VeVE2bvmj9L6SEr6fJ5G6OFPt2mICg7HffgVLfbCa+dl7KPC5lIbez y/aQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:mime-version:user-agent:references :in-reply-to:message-id:date:subject:cc:to:from :arc-authentication-results; bh=UpxhvFT9oIsszTO+GcTL3WMvvaQ61OS121pQF2CLm6w=; b=g9c4rnuZCOohipmCUu3tcxPAoEgxnf00sLFR5OKK8PCybVLzaXoB94ZKIoiekkYrNA CsIrUX05Zwoyr4s9OGNJ8HizYcS6PjKfhYgRtVXC0uKX6NFPyBkCLOegPsi31XweMvKn jzkQXcP0AVrZGW0qC303cV9Fz7QwYK3sTuOu4kCF36PWaUo6+kZCkM0N1fkb3Kxm19r5 z78Hgk3eataGq/DUcIVsCvCoiHvHHh4SkS+tTt8Pdbsdb37cRMOhYdentaCZrxPJH07C 2fgNSuuGFaqyYesiU4SXv4HhYh16YhcmndlibGjDTnUNE2ApOjqgG99V4ts5gR0uCgTi El7A== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id z18-v6si11661047pfl.209.2018.07.01.10.05.28; Sun, 01 Jul 2018 10:05:42 -0700 (PDT) Received-SPF: pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1753618AbeGAREk (ORCPT + 99 others); Sun, 1 Jul 2018 13:04:40 -0400 Received: from mail.linuxfoundation.org ([140.211.169.12]:37660 "EHLO mail.linuxfoundation.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1032211AbeGAQmh (ORCPT ); Sun, 1 Jul 2018 12:42:37 -0400 Received: from localhost (LFbn-1-12247-202.w90-92.abo.wanadoo.fr [90.92.61.202]) by mail.linuxfoundation.org (Postfix) with ESMTPSA id 2E106AA6; Sun, 1 Jul 2018 16:42:37 +0000 (UTC) From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , stable@vger.kernel.org, Luis Henriques , Douglas Gilbert , "Martin K. Petersen" Subject: [PATCH 4.17 132/220] scsi: scsi_debug: Fix memory leak on module unload Date: Sun, 1 Jul 2018 18:22:36 +0200 Message-Id: <20180701160913.836770119@linuxfoundation.org> X-Mailer: git-send-email 2.18.0 In-Reply-To: <20180701160908.272447118@linuxfoundation.org> References: <20180701160908.272447118@linuxfoundation.org> User-Agent: quilt/0.65 X-stable: review MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org 4.17-stable review patch. If anyone has any objections, please let me know. ------------------ From: Luis Henriques commit 52ab9768f723823a71dc659f0fad803a90f80236 upstream. Since commit 80c49563e250 ("scsi: scsi_debug: implement IMMED bit") there are long delays in F_SYNC_DELAY and F_SSU_DELAY. This can cause a memory leak in schedule_resp(), which can be invoked while unloading the scsi_debug module: free_all_queued() had already freed all sd_dp and schedule_resp will alloc a new one, which will never get freed. Here's the kmemleak report while running xfstests generic/350: unreferenced object 0xffff88007d752b00 (size 128): comm "rmmod", pid 26940, jiffies 4295816945 (age 7.588s) hex dump (first 32 bytes): 00 2b 75 7d 00 88 ff ff 00 00 00 00 00 00 00 00 .+u}............ 00 00 00 00 00 00 00 00 8e 31 a2 34 5f 03 00 00 .........1.4_... backtrace: [<000000002abd83d0>] 0xffffffffa000705e [<000000004c063fda>] scsi_dispatch_cmd+0xc7/0x1a0 [<000000000c119a00>] scsi_request_fn+0x251/0x550 [<000000009de0c736>] __blk_run_queue+0x3f/0x60 [<000000001c4453c8>] blk_execute_rq_nowait+0x98/0xd0 [<00000000d17ec79f>] blk_execute_rq+0x3a/0x50 [<00000000a7654b6e>] scsi_execute+0x113/0x250 [<00000000fd78f7cd>] sd_sync_cache+0x95/0x160 [<0000000024dacb14>] sd_shutdown+0x9b/0xd0 [<00000000e9101710>] sd_remove+0x5f/0xb0 [<00000000c43f0d63>] device_release_driver_internal+0x13c/0x1f0 [<00000000e8ad57b6>] bus_remove_device+0xe9/0x160 [<00000000713a7b8a>] device_del+0x120/0x320 [<00000000e5db670c>] __scsi_remove_device+0x115/0x150 [<00000000eccbef30>] scsi_forget_host+0x20/0x60 [<00000000cd5a0738>] scsi_remove_host+0x6d/0x120 Cc: stable@vger.kernel.org # v4.17+ Signed-off-by: Luis Henriques Acked-by: Douglas Gilbert Signed-off-by: Martin K. Petersen Signed-off-by: Greg Kroah-Hartman --- drivers/scsi/scsi_debug.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) --- a/drivers/scsi/scsi_debug.c +++ b/drivers/scsi/scsi_debug.c @@ -5506,9 +5506,9 @@ static void __exit scsi_debug_exit(void) int k = sdebug_add_host; stop_all_queued(); - free_all_queued(); for (; k; k--) sdebug_remove_adapter(); + free_all_queued(); driver_unregister(&sdebug_driverfs_driver); bus_unregister(&pseudo_lld_bus); root_device_unregister(pseudo_primary);