Received: by 2002:ac0:a5b6:0:0:0:0:0 with SMTP id m51-v6csp4100963imm; Mon, 18 Jun 2018 09:09:02 -0700 (PDT) X-Google-Smtp-Source: ADUXVKIhj/b5+lHuu0xB0d3jZnZxnDMvQFHZCe1d1w4YSRsbX7TjuFGliZ4iiMSyO4ON1KorFRgy X-Received: by 2002:a17:902:8f82:: with SMTP id z2-v6mr14758740plo.203.1529338142310; Mon, 18 Jun 2018 09:09:02 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1529338142; cv=none; d=google.com; s=arc-20160816; b=fVwpKwr43WUij8lO95SCVqOlUnunhAf0f5JfH2Vj/5i9eC2ki84ZkK0Y/Bi0IGcRaP TfVzBKXLJDIIL/8TwoKnNw+UzzPZ1d1XDMOsRBzSmZ+z57hJa59B2Oq//Zpy0xJ/JYmG 1CHTiKCy5i1oTM1LrylV4XSKh5VQgxDrFGJ+mINFsKQb5/D2itQ6k3wHt00CZbfJpU1c xoiaiPId1DTYavEeSAN6IxY2MscwjHRvmRH9Phm/fSORT/D62EeHYGg3aHgK3S5utsXT R8jKr4irDRM0r2JCuLOtxiv7FcluL598dit+/kuO8P3HhJZ4xYycH9sNmVe5dKZNchox Z8bQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:message-id:date:subject:cc:to:from :arc-authentication-results; bh=wau+XfYsb68wnT8aqKYKnPxQ7GwpMqW41d/xRpK42qM=; b=cXoGAec0GRe5bzSjPp5aYKco/CcRfSpfY9/FnfgnN1Y3SrTAiPPTt8owwfUNUoK5M8 vywiYFoabgh5cZDyU0O6rZkngoJHs8UwC/z1YE/JXQM7chuJliQTzuMqVzRXsazu7IXe ek1qXWg/uWc7BH4gXeNS3eo3MHaIQTjs8ZsP5vDrb0L6K6Lr5NElPu52jDqJdmPzJxF4 UVOgBeV0H3yKTakn2z8uL7mMWYJtXTrtwHu8MtC/ZOPLRH2JqH3jicM9htZZ7pMk1W4q Uv16frCntwZHKNoOQ/M3SA8yzpgEyzOdRvMDq5aXj7J3bcaY0P/kM6BDEOfgCkf7hFZO f1/Q== 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 1-v6si15610850plt.342.2018.06.18.09.08.48; Mon, 18 Jun 2018 09:09:02 -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 S1755186AbeFRQHT (ORCPT + 99 others); Mon, 18 Jun 2018 12:07:19 -0400 Received: from mx2.suse.de ([195.135.220.15]:54138 "EHLO mx2.suse.de" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1754091AbeFRQHR (ORCPT ); Mon, 18 Jun 2018 12:07:17 -0400 X-Virus-Scanned: by amavisd-new at test-mx.suse.de Received: from relay1.suse.de (charybdis-ext-too.suse.de [195.135.220.254]) by mx2.suse.de (Postfix) with ESMTP id 6A73DADCA; Mon, 18 Jun 2018 16:07:16 +0000 (UTC) From: Luis Henriques To: "James E . J . Bottomley" , "Martin K . Petersen" Cc: Douglas Gilbert , linux-scsi@vger.kernel.org, linux-kernel@vger.kernel.org, Luis Henriques , stable@vger.kernel.org Subject: [PATCH] scsi: scsi_debug: Fix memory leak on module unload Date: Mon, 18 Jun 2018 17:08:03 +0100 Message-Id: <20180618160803.11674-1-lhenriques@suse.com> Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org 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 Signed-off-by: Luis Henriques --- drivers/scsi/scsi_debug.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/drivers/scsi/scsi_debug.c b/drivers/scsi/scsi_debug.c index 24d7496cd9e2..364e71861bfd 100644 --- a/drivers/scsi/scsi_debug.c +++ b/drivers/scsi/scsi_debug.c @@ -5507,9 +5507,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);