From patchwork Fri Jan 8 14:36:30 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jinpu Wang X-Patchwork-Id: 12006723 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=-18.8 required=3.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,HEADER_FROM_DIFFERENT_DOMAINS,INCLUDES_CR_TRAILER, INCLUDES_PATCH,MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS,URIBL_BLOCKED, USER_AGENT_GIT autolearn=ham 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 C05A2C43381 for ; Fri, 8 Jan 2021 14:37:24 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 8F9B623884 for ; Fri, 8 Jan 2021 14:37:24 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1727228AbhAHOhY (ORCPT ); Fri, 8 Jan 2021 09:37:24 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:55984 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726205AbhAHOhS (ORCPT ); Fri, 8 Jan 2021 09:37:18 -0500 Received: from mail-ej1-x632.google.com (mail-ej1-x632.google.com [IPv6:2a00:1450:4864:20::632]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 1A965C061381 for ; Fri, 8 Jan 2021 06:36:38 -0800 (PST) Received: by mail-ej1-x632.google.com with SMTP id lt17so14842977ejb.3 for ; Fri, 08 Jan 2021 06:36:38 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=cloud.ionos.com; s=google; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=EiNKIQB4SZxip9loF5DwUxC/dWXpbt01EaFO3eOT2KU=; b=Tgt1MfuWl+vRPjQXNZ4+snCEsntO+/55gXY752tM30tkjXNW2vppg1YyARuL0Z/UF9 1kju9SjwHXTJ/MVYn6NgfTZYUAMzgCvwTfatafaBfSIQ2unCZuQ0yqVoXR5rRczD18kT wbjVMPvEXILPKo6FosMir35NQDOLvzB2GmQhMrOsN5vmXUvGKLrj4/9+HNfv6D3afeOE YajoJ78U+v+lhVs1my+gH/uvRfAC00E2m/PTYaRX/zyD0QuMH5uQDC8NfsvmvUFlDYcT 651ypY1nhuZBwHz5aod/Iz6vaasEftykGwo8wAKRA3gnG5Fe2XVl9e+uWu+rnr3Jj9OI jRhA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=EiNKIQB4SZxip9loF5DwUxC/dWXpbt01EaFO3eOT2KU=; b=ZeSyI4uy9iOIrmdDzuZYoP/YluckS7UHzNpw/CV39zc6kQ9mt//FIbtze51XDvOc9s VHsDdBCX6dKyjsbwPDHl/9bwgFOh4qCavk3rVjVnpuwTfqB0KkzrULSupffvtqdBpb2F JplruQ+FprfVvOhLFlJ9tWzSsODj4OJNldUGXW/9XzDViswK3RYfjDRELBBRoUW/plQt tUKoO9Q7O9QvfsoZm2yOeWTO4eyHBpuQOMUqNipY+ov5a4eq0SK52FM/xndaFhmxZG5h l4WCYGv5/GlMXg5BtgQ6RdCtwg1tUCysAID28MUoOG8BkhKSJtB7VighW/emoOVLc3ev CU5w== X-Gm-Message-State: AOAM531Mom0DQEueo/1EKPQSzwbWhsBBXqi1xeA1M/yvhS+ar5M2Qq8M 6CVY36xjWL2vrwz0YWFdccv5o60zlZZ9ZQ== X-Google-Smtp-Source: ABdhPJxO8NtKkA1WDM4pPA5b3EkOPgvOOTOBLcznjWn/MI+h/we4DFbBePeVS/b4wJDzJxUiA8S/CQ== X-Received: by 2002:a17:907:2506:: with SMTP id y6mr2830044ejl.53.1610116596459; Fri, 08 Jan 2021 06:36:36 -0800 (PST) Received: from jwang-Latitude-5491.fkb.profitbricks.net ([2001:16b8:4906:c200:31ac:50df:cd1f:f7fc]) by smtp.gmail.com with ESMTPSA id e25sm3858698edq.24.2021.01.08.06.36.35 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 08 Jan 2021 06:36:36 -0800 (PST) From: Jack Wang To: linux-block@vger.kernel.org Cc: axboe@kernel.dk, hch@infradead.org, sagi@grimberg.me, bvanassche@acm.org, danil.kipnis@cloud.ionos.com, kernel test robot Subject: [PATCH for-rc 1/5] block/rnbd: Select SG_POOL for RNBD_CLIENT Date: Fri, 8 Jan 2021 15:36:30 +0100 Message-Id: <20210108143634.175394-2-jinpu.wang@cloud.ionos.com> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20210108143634.175394-1-jinpu.wang@cloud.ionos.com> References: <20210108143634.175394-1-jinpu.wang@cloud.ionos.com> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: linux-block@vger.kernel.org lkp reboot following build error: drivers/block/rnbd/rnbd-clt.c: In function 'rnbd_softirq_done_fn': >> drivers/block/rnbd/rnbd-clt.c:387:2: error: implicit declaration of function 'sg_free_table_chained' [-Werror=implicit-function-declaration] 387 | sg_free_table_chained(&iu->sgt, RNBD_INLINE_SG_CNT); | ^~~~~~~~~~~~~~~~~~~~~ The reason is CONFIG_SG_POOL is not enabled in the config, to avoid such failure, select SG_POOL in Kconfig for RNBD_CLIENT. Fixes: 5a1328d0c3a7 ("block/rnbd-clt: Dynamically allocate sglist for rnbd_iu") Reported-by: kernel test robot Signed-off-by: Jack Wang --- drivers/block/rnbd/Kconfig | 1 + 1 file changed, 1 insertion(+) diff --git a/drivers/block/rnbd/Kconfig b/drivers/block/rnbd/Kconfig index 4b6d3d816d1f..2ff05a0d2646 100644 --- a/drivers/block/rnbd/Kconfig +++ b/drivers/block/rnbd/Kconfig @@ -7,6 +7,7 @@ config BLK_DEV_RNBD_CLIENT tristate "RDMA Network Block Device driver client" depends on INFINIBAND_RTRS_CLIENT select BLK_DEV_RNBD + select SG_POOL help RNBD client is a network block device driver using rdma transport. From patchwork Fri Jan 8 14:36:31 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jinpu Wang X-Patchwork-Id: 12006725 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=-18.8 required=3.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,HEADER_FROM_DIFFERENT_DOMAINS,INCLUDES_CR_TRAILER, INCLUDES_PATCH,MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS,URIBL_BLOCKED, USER_AGENT_GIT autolearn=ham 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 8F365C433E9 for ; Fri, 8 Jan 2021 14:37:24 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 69849238A1 for ; Fri, 8 Jan 2021 14:37:24 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1727213AbhAHOhY (ORCPT ); Fri, 8 Jan 2021 09:37:24 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:55986 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726919AbhAHOhT (ORCPT ); Fri, 8 Jan 2021 09:37:19 -0500 Received: from mail-ed1-x532.google.com (mail-ed1-x532.google.com [IPv6:2a00:1450:4864:20::532]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id CAA1EC0612EA for ; Fri, 8 Jan 2021 06:36:38 -0800 (PST) Received: by mail-ed1-x532.google.com with SMTP id h16so11382302edt.7 for ; Fri, 08 Jan 2021 06:36:38 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=cloud.ionos.com; s=google; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=u25adq35DuqO+Mk8+/7OS6CK54gsT8vmqBWNkLqnsMk=; b=EXCTRJZ2MLDyMo2NSQ7ft9JCYTUJO0OTkQjNFCPTF6q80JZS+IZv13LGAOWQPKRlGw X5hSK+JiLzo1yn1JVBBgEWDtpzBhS6nvAw2swvxUnX9tLXZOoYmmYkLgEIzf6ZCV59Ap BVHh+pW6rGbPL4BJ32Ym2U5VSBKTPLYmLzpm0cV7W5MB6F2q9oRjk3LWT/yV1P3rOMwa sivUOAD2pNTnn14mYZSJfK53bNLDI8d0Vj/saSDiTExQhLLm4PZ46vzwrQvIaHxPT71M 5Spj13pUACMu46JnttsIYXN6R12KlRiVBcbk89Q0Gf7yA/mkIm7AdhQKjYg7iiSjKulz jxrg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=u25adq35DuqO+Mk8+/7OS6CK54gsT8vmqBWNkLqnsMk=; b=WMe/p76t1+1i3yXJTfgWwWLgZbjcM0ra11S4v8FagAU04/PTJYoOU4p78uUBd/II8M pY9qTN2RrCSgNM2uo6x1daF/gVx+nrFB6iYLogiixjWP+DvFOBBffdZo8q8tVwJdFZc1 UmUFQVcaBRKKHndTS7AOe7FcUyKlyIjB4/T/RlJ/in5J/qKtFPUVPvMvdWlm5vgedI6a n1PpAJuxW9kBgkRiHm02vQvmquLsYq94SQ6ANmoDIqJC8yjoUnH/G5DkESU3b3LEnqvu T71ToqUIBHuTDlctTZ3NiNZqZkaQdFK99Sl3wOEsyQPfA/tGYphMcbN9t2R/A7KhSQYB pYXg== X-Gm-Message-State: AOAM532o7NiVIaQsFnDhM2eZeK9mIc3rjuOt748CjDdbmkdaW798vVGY kw2CZgpycYxyBtcCw0zEdcAiLHcOrD8bNg== X-Google-Smtp-Source: ABdhPJwg783FMSI3NPXY9btnzSd6k+BHnUgUuhw3mrQ40KowzRlM/JoUzTFr2jWNPuJFRkEY8Mgckg== X-Received: by 2002:a50:8741:: with SMTP id 1mr5544045edv.349.1610116597300; Fri, 08 Jan 2021 06:36:37 -0800 (PST) Received: from jwang-Latitude-5491.fkb.profitbricks.net ([2001:16b8:4906:c200:31ac:50df:cd1f:f7fc]) by smtp.gmail.com with ESMTPSA id e25sm3858698edq.24.2021.01.08.06.36.36 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 08 Jan 2021 06:36:36 -0800 (PST) From: Jack Wang To: linux-block@vger.kernel.org Cc: axboe@kernel.dk, hch@infradead.org, sagi@grimberg.me, bvanassche@acm.org, danil.kipnis@cloud.ionos.com, Guoqing Jiang Subject: [PATCH for-rc 2/5] block/rnbd-srv: Fix use after free in rnbd_srv_sess_dev_force_close Date: Fri, 8 Jan 2021 15:36:31 +0100 Message-Id: <20210108143634.175394-3-jinpu.wang@cloud.ionos.com> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20210108143634.175394-1-jinpu.wang@cloud.ionos.com> References: <20210108143634.175394-1-jinpu.wang@cloud.ionos.com> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: linux-block@vger.kernel.org KASAN detect following BUG: [ 778.215311] ================================================================== [ 778.216696] BUG: KASAN: use-after-free in rnbd_srv_sess_dev_force_close+0x38/0x60 [rnbd_server] [ 778.219037] Read of size 8 at addr ffff88b1d6516c28 by task tee/8842 [ 778.220500] CPU: 37 PID: 8842 Comm: tee Kdump: loaded Not tainted 5.10.0-pserver #5.10.0-1+feature+linux+next+20201214.1025+0910d71 [ 778.220529] Hardware name: Supermicro Super Server/X11DDW-L, BIOS 3.3 02/21/2020 [ 778.220555] Call Trace: [ 778.220609] dump_stack+0x99/0xcb [ 778.220667] ? rnbd_srv_sess_dev_force_close+0x38/0x60 [rnbd_server] [ 778.220715] print_address_description.constprop.7+0x1e/0x230 [ 778.220750] ? freeze_kernel_threads+0x73/0x73 [ 778.220896] ? rnbd_srv_sess_dev_force_close+0x38/0x60 [rnbd_server] [ 778.220932] ? rnbd_srv_sess_dev_force_close+0x38/0x60 [rnbd_server] [ 778.220994] kasan_report.cold.9+0x37/0x7c [ 778.221066] ? kobject_put+0x80/0x270 [ 778.221102] ? rnbd_srv_sess_dev_force_close+0x38/0x60 [rnbd_server] [ 778.221184] rnbd_srv_sess_dev_force_close+0x38/0x60 [rnbd_server] [ 778.221240] rnbd_srv_dev_session_force_close_store+0x6a/0xc0 [rnbd_server] [ 778.221304] ? sysfs_file_ops+0x90/0x90 [ 778.221353] kernfs_fop_write+0x141/0x240 [ 778.221451] vfs_write+0x142/0x4d0 [ 778.221553] ksys_write+0xc0/0x160 [ 778.221602] ? __ia32_sys_read+0x50/0x50 [ 778.221684] ? lockdep_hardirqs_on_prepare+0x13d/0x210 [ 778.221718] ? syscall_enter_from_user_mode+0x1c/0x50 [ 778.221821] do_syscall_64+0x33/0x40 [ 778.221862] entry_SYSCALL_64_after_hwframe+0x44/0xa9 [ 778.221896] RIP: 0033:0x7f4affdd9504 [ 778.221928] Code: 00 f7 d8 64 89 02 48 c7 c0 ff ff ff ff eb b3 0f 1f 80 00 00 00 00 48 8d 05 f9 61 0d 00 8b 00 85 c0 75 13 b8 01 00 00 00 0f 05 <48> 3d 00 f0 ff ff 77 54 c3 0f 1f 00 41 54 49 89 d4 55 48 89 f5 53 [ 778.221956] RSP: 002b:00007fffebb36b28 EFLAGS: 00000246 ORIG_RAX: 0000000000000001 [ 778.222011] RAX: ffffffffffffffda RBX: 0000000000000002 RCX: 00007f4affdd9504 [ 778.222038] RDX: 0000000000000002 RSI: 00007fffebb36c50 RDI: 0000000000000003 [ 778.222066] RBP: 00007fffebb36c50 R08: 0000556a151aa600 R09: 00007f4affeb1540 [ 778.222094] R10: fffffffffffffc19 R11: 0000000000000246 R12: 0000556a151aa520 [ 778.222121] R13: 0000000000000002 R14: 00007f4affea6760 R15: 0000000000000002 [ 778.222764] Allocated by task 3212: [ 778.223285] kasan_save_stack+0x19/0x40 [ 778.223316] __kasan_kmalloc.constprop.7+0xc1/0xd0 [ 778.223347] kmem_cache_alloc_trace+0x186/0x350 [ 778.223382] rnbd_srv_rdma_ev+0xf16/0x1690 [rnbd_server] [ 778.223422] process_io_req+0x4d1/0x670 [rtrs_server] [ 778.223573] __ib_process_cq+0x10a/0x350 [ib_core] [ 778.223709] ib_cq_poll_work+0x31/0xb0 [ib_core] [ 778.223743] process_one_work+0x521/0xa90 [ 778.223773] worker_thread+0x65/0x5b0 [ 778.223802] kthread+0x1f2/0x210 [ 778.223833] ret_from_fork+0x22/0x30 [ 778.224296] Freed by task 8842: [ 778.224800] kasan_save_stack+0x19/0x40 [ 778.224829] kasan_set_track+0x1c/0x30 [ 778.224860] kasan_set_free_info+0x1b/0x30 [ 778.224889] __kasan_slab_free+0x108/0x150 [ 778.224919] slab_free_freelist_hook+0x64/0x190 [ 778.224947] kfree+0xe2/0x650 [ 778.224982] rnbd_destroy_sess_dev+0x2fa/0x3b0 [rnbd_server] [ 778.225011] kobject_put+0xda/0x270 [ 778.225046] rnbd_srv_sess_dev_force_close+0x30/0x60 [rnbd_server] [ 778.225081] rnbd_srv_dev_session_force_close_store+0x6a/0xc0 [rnbd_server] [ 778.225111] kernfs_fop_write+0x141/0x240 [ 778.225140] vfs_write+0x142/0x4d0 [ 778.225169] ksys_write+0xc0/0x160 [ 778.225198] do_syscall_64+0x33/0x40 [ 778.225227] entry_SYSCALL_64_after_hwframe+0x44/0xa9 [ 778.226506] The buggy address belongs to the object at ffff88b1d6516c00 which belongs to the cache kmalloc-512 of size 512 [ 778.227464] The buggy address is located 40 bytes inside of 512-byte region [ffff88b1d6516c00, ffff88b1d6516e00) The problem is in the sess_dev release function we call rnbd_destroy_sess_dev, and could free the sess_dev already, but we still set the keep_id in rnbd_srv_sess_dev_force_close, which lead to use after free. To fix it, move the keep_id before the sysfs removal, and cache the rnbd_srv_session for lock accessing, Fixes: 786998050cbc ("block/rnbd-srv: close a mapped device from server side.") Signed-off-by: Jack Wang Reviewed-by: Guoqing Jiang --- drivers/block/rnbd/rnbd-srv.c | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/drivers/block/rnbd/rnbd-srv.c b/drivers/block/rnbd/rnbd-srv.c index b8e44331e494..a6a68d44f517 100644 --- a/drivers/block/rnbd/rnbd-srv.c +++ b/drivers/block/rnbd/rnbd-srv.c @@ -338,10 +338,12 @@ static int rnbd_srv_link_ev(struct rtrs_srv *rtrs, void rnbd_srv_sess_dev_force_close(struct rnbd_srv_sess_dev *sess_dev) { - mutex_lock(&sess_dev->sess->lock); - rnbd_srv_destroy_dev_session_sysfs(sess_dev); - mutex_unlock(&sess_dev->sess->lock); + struct rnbd_srv_session *sess = sess_dev->sess; + sess_dev->keep_id = true; + mutex_lock(&sess->lock); + rnbd_srv_destroy_dev_session_sysfs(sess_dev); + mutex_unlock(&sess->lock); } static int process_msg_close(struct rtrs_srv *rtrs, From patchwork Fri Jan 8 14:36:32 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jinpu Wang X-Patchwork-Id: 12006727 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=-18.8 required=3.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,HEADER_FROM_DIFFERENT_DOMAINS,INCLUDES_CR_TRAILER, INCLUDES_PATCH,MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS,URIBL_BLOCKED, USER_AGENT_GIT autolearn=ham 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 7FBA3C433E6 for ; Fri, 8 Jan 2021 14:37:24 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 3FCE523884 for ; Fri, 8 Jan 2021 14:37:24 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1727176AbhAHOhX (ORCPT ); Fri, 8 Jan 2021 09:37:23 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:55992 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726935AbhAHOhU (ORCPT ); Fri, 8 Jan 2021 09:37:20 -0500 Received: from mail-ej1-x632.google.com (mail-ej1-x632.google.com [IPv6:2a00:1450:4864:20::632]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id B69A8C0612FD for ; Fri, 8 Jan 2021 06:36:39 -0800 (PST) Received: by mail-ej1-x632.google.com with SMTP id ga15so14825292ejb.4 for ; Fri, 08 Jan 2021 06:36:39 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=cloud.ionos.com; s=google; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=xDFpQWrHMsuKz/nh26/noW6aHuNV8mbI1uQD9qPo1DM=; b=FDhELJkw7kpTs1Too27M1GbjuEU6VA8MqoDNV6jlYAL0RrNIYmqMlkHCdWJVzldtDO 3fTDAbyLUrs91J900Nk35cI2RZVbk/XcdrJ3lxPfQzWWk3sf4i65wfdvd+yDZgcI7QRn Laj1r4OH2T0Mo32K8RnzQrLN2u54L7MzNmCblvh7RT9hL6gcRSbe2S4qJQTmWWtNedKb 6m17NTcrnRNSn2j6QJPUFt3BUmmemDNrkOTj/KGYcJJd1McQu5NeSEvuOBKo+6ggmKtR C1Nkh6r9jMIqykWuyQfX+jI2jnpij6RcNJ0rIh/CJ0nEVYNmdSZrxOAWY9BUSqJVoRUB 2NBQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=xDFpQWrHMsuKz/nh26/noW6aHuNV8mbI1uQD9qPo1DM=; b=TH/ryDQSGh1VH8AsiOKx4Ld3a5m7bnnJDtTd2M4C5+WL5KSv435xYfQx5YHtuz0VRn 92FY6+WUekIpJQ6fuD92EmHO9KxcyxxOO13t3k18GNQ4Csp3OossUbm1n6H78Y32BDAh Zkt466tIg3rpn+lEYn7bDT9ut8bZeaBbrPTn3dM7iMK/0Jp3SM/KEzE3Rd4aqz7xvZPj y87fwAnvcHRG+SMM1UhBhU6CyQU7Kg45o6XsHFRYkumr5LWrEkoc26YP3siIdao49c2c MnbaQ55YTvNp/DajOgnKU9a5XNiIS93zdtzuPLTd07eI//psylDqlr6IFERscZxPxcHe oQ5g== X-Gm-Message-State: AOAM532BKD7wogClu6Wi1DvUHL6EXGSPbmj26LJvjW/pSZJXk48KruBr doBclXR/qJiqMTpmC41C/0poUJl/8IEHPQ== X-Google-Smtp-Source: ABdhPJxciLNzvQWim5KMMvqRtG2gwMHveOv/3jfMUXZyAYTJnF3QD6mFEhV5y48fOClONWl3o69ZZQ== X-Received: by 2002:a17:906:3a0d:: with SMTP id z13mr2806615eje.2.1610116598220; Fri, 08 Jan 2021 06:36:38 -0800 (PST) Received: from jwang-Latitude-5491.fkb.profitbricks.net ([2001:16b8:4906:c200:31ac:50df:cd1f:f7fc]) by smtp.gmail.com with ESMTPSA id e25sm3858698edq.24.2021.01.08.06.36.37 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 08 Jan 2021 06:36:37 -0800 (PST) From: Jack Wang To: linux-block@vger.kernel.org Cc: axboe@kernel.dk, hch@infradead.org, sagi@grimberg.me, bvanassche@acm.org, danil.kipnis@cloud.ionos.com, Guoqing Jiang Subject: [PATCH for-rc 3/5] block/rnbd-clt: Fix sg table use after free Date: Fri, 8 Jan 2021 15:36:32 +0100 Message-Id: <20210108143634.175394-4-jinpu.wang@cloud.ionos.com> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20210108143634.175394-1-jinpu.wang@cloud.ionos.com> References: <20210108143634.175394-1-jinpu.wang@cloud.ionos.com> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: linux-block@vger.kernel.org From: Guoqing Jiang Since dynamically allocate sglist is used for rnbd_iu, we can't free sg table after send_usr_msg since the callback function (cqe.done) could still access the sglist. Otherwise KASAN reports UAF issue: [ 4856.600257] BUG: KASAN: use-after-free in dma_direct_unmap_sg+0x53/0x290 [ 4856.600772] Read of size 4 at addr ffff888206af3a98 by task swapper/1/0 [ 4856.601729] CPU: 1 PID: 0 Comm: swapper/1 Kdump: loaded Tainted: G W 5.10.0-pserver #5.10.0-1+feature+linux+next+20201214.1025+0910d71 [ 4856.601748] Hardware name: Supermicro Super Server/X11DDW-L, BIOS 3.3 02/21/2020 [ 4856.601766] Call Trace: [ 4856.601785] [ 4856.601822] dump_stack+0x99/0xcb [ 4856.601856] ? dma_direct_unmap_sg+0x53/0x290 [ 4856.601888] print_address_description.constprop.7+0x1e/0x230 [ 4856.601913] ? freeze_kernel_threads+0x73/0x73 [ 4856.601965] ? mark_held_locks+0x29/0xa0 [ 4856.602019] ? dma_direct_unmap_sg+0x53/0x290 [ 4856.602039] ? dma_direct_unmap_sg+0x53/0x290 [ 4856.602079] kasan_report.cold.9+0x37/0x7c [ 4856.602188] ? mlx5_ib_post_recv+0x430/0x520 [mlx5_ib] [ 4856.602209] ? dma_direct_unmap_sg+0x53/0x290 [ 4856.602256] dma_direct_unmap_sg+0x53/0x290 [ 4856.602366] complete_rdma_req+0x188/0x4b0 [rtrs_client] [ 4856.602451] ? rtrs_clt_close+0x80/0x80 [rtrs_client] [ 4856.602535] ? mlx5_ib_poll_cq+0x48b/0x16e0 [mlx5_ib] [ 4856.602589] ? radix_tree_insert+0x3a0/0x3a0 [ 4856.602610] ? do_raw_spin_lock+0x119/0x1d0 [ 4856.602647] ? rwlock_bug.part.1+0x60/0x60 [ 4856.602740] rtrs_clt_rdma_done+0x3f7/0x670 [rtrs_client] [ 4856.602804] ? rtrs_clt_rdma_cm_handler+0xda0/0xda0 [rtrs_client] [ 4856.602857] ? check_flags.part.31+0x6c/0x1f0 [ 4856.602927] ? rcu_read_lock_sched_held+0xaf/0xe0 [ 4856.602963] ? rcu_read_lock_bh_held+0xc0/0xc0 [ 4856.603137] __ib_process_cq+0x10a/0x350 [ib_core] [ 4856.603309] ib_poll_handler+0x41/0x1c0 [ib_core] [ 4856.603358] irq_poll_softirq+0xe6/0x280 [ 4856.603392] ? lockdep_hardirqs_on_prepare+0x111/0x210 [ 4856.603446] __do_softirq+0x10d/0x646 [ 4856.603540] asm_call_irq_on_stack+0x12/0x20 [ 4856.603563] [ 4856.605096] Allocated by task 8914: [ 4856.605510] kasan_save_stack+0x19/0x40 [ 4856.605532] __kasan_kmalloc.constprop.7+0xc1/0xd0 [ 4856.605552] __kmalloc+0x155/0x320 [ 4856.605574] __sg_alloc_table+0x155/0x1c0 [ 4856.605594] sg_alloc_table+0x1f/0x50 [ 4856.605620] send_msg_sess_info+0x119/0x2e0 [rnbd_client] [ 4856.605646] remap_devs+0x71/0x210 [rnbd_client] [ 4856.605676] init_sess+0xad8/0xe10 [rtrs_client] [ 4856.605706] rtrs_clt_reconnect_work+0xd6/0x170 [rtrs_client] [ 4856.605728] process_one_work+0x521/0xa90 [ 4856.605748] worker_thread+0x65/0x5b0 [ 4856.605769] kthread+0x1f2/0x210 [ 4856.605789] ret_from_fork+0x22/0x30 [ 4856.606159] Freed by task 8914: [ 4856.606559] kasan_save_stack+0x19/0x40 [ 4856.606580] kasan_set_track+0x1c/0x30 [ 4856.606601] kasan_set_free_info+0x1b/0x30 [ 4856.606622] __kasan_slab_free+0x108/0x150 [ 4856.606642] slab_free_freelist_hook+0x64/0x190 [ 4856.606661] kfree+0xe2/0x650 [ 4856.606681] __sg_free_table+0xa4/0x100 [ 4856.606707] send_msg_sess_info+0x1d6/0x2e0 [rnbd_client] [ 4856.606733] remap_devs+0x71/0x210 [rnbd_client] [ 4856.606763] init_sess+0xad8/0xe10 [rtrs_client] [ 4856.606792] rtrs_clt_reconnect_work+0xd6/0x170 [rtrs_client] [ 4856.606813] process_one_work+0x521/0xa90 [ 4856.606833] worker_thread+0x65/0x5b0 [ 4856.606853] kthread+0x1f2/0x210 [ 4856.606872] ret_from_fork+0x22/0x30 The solution is to free iu's sgtable after the iu is not used anymore. And also move sg_alloc_table into rnbd_get_iu accordingly. Fixes: 5a1328d0c3a7 ("block/rnbd-clt: Dynamically allocate sglist for rnbd_iu") Signed-off-by: Guoqing Jiang Signed-off-by: Jack Wang --- drivers/block/rnbd/rnbd-clt.c | 15 +++++++-------- 1 file changed, 7 insertions(+), 8 deletions(-) diff --git a/drivers/block/rnbd/rnbd-clt.c b/drivers/block/rnbd/rnbd-clt.c index 9165e70bee0c..c696c3a937d7 100644 --- a/drivers/block/rnbd/rnbd-clt.c +++ b/drivers/block/rnbd/rnbd-clt.c @@ -375,12 +375,19 @@ static struct rnbd_iu *rnbd_get_iu(struct rnbd_clt_session *sess, init_waitqueue_head(&iu->comp.wait); iu->comp.errno = INT_MAX; + if (sg_alloc_table(&iu->sgt, 1, GFP_KERNEL)) { + rnbd_put_permit(sess, permit); + kfree(iu); + return NULL; + } + return iu; } static void rnbd_put_iu(struct rnbd_clt_session *sess, struct rnbd_iu *iu) { if (atomic_dec_and_test(&iu->refcount)) { + sg_free_table(&iu->sgt); rnbd_put_permit(sess, iu->permit); kfree(iu); } @@ -487,8 +494,6 @@ static int send_msg_close(struct rnbd_clt_dev *dev, u32 device_id, bool wait) iu->buf = NULL; iu->dev = dev; - sg_alloc_table(&iu->sgt, 1, GFP_KERNEL); - msg.hdr.type = cpu_to_le16(RNBD_MSG_CLOSE); msg.device_id = cpu_to_le32(device_id); @@ -502,7 +507,6 @@ static int send_msg_close(struct rnbd_clt_dev *dev, u32 device_id, bool wait) err = errno; } - sg_free_table(&iu->sgt); rnbd_put_iu(sess, iu); return err; } @@ -575,7 +579,6 @@ static int send_msg_open(struct rnbd_clt_dev *dev, bool wait) iu->buf = rsp; iu->dev = dev; - sg_alloc_table(&iu->sgt, 1, GFP_KERNEL); sg_init_one(iu->sgt.sgl, rsp, sizeof(*rsp)); msg.hdr.type = cpu_to_le16(RNBD_MSG_OPEN); @@ -594,7 +597,6 @@ static int send_msg_open(struct rnbd_clt_dev *dev, bool wait) err = errno; } - sg_free_table(&iu->sgt); rnbd_put_iu(sess, iu); return err; } @@ -622,8 +624,6 @@ static int send_msg_sess_info(struct rnbd_clt_session *sess, bool wait) iu->buf = rsp; iu->sess = sess; - - sg_alloc_table(&iu->sgt, 1, GFP_KERNEL); sg_init_one(iu->sgt.sgl, rsp, sizeof(*rsp)); msg.hdr.type = cpu_to_le16(RNBD_MSG_SESS_INFO); @@ -650,7 +650,6 @@ static int send_msg_sess_info(struct rnbd_clt_session *sess, bool wait) } else { err = errno; } - sg_free_table(&iu->sgt); rnbd_put_iu(sess, iu); return err; } From patchwork Fri Jan 8 14:36:33 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jinpu Wang X-Patchwork-Id: 12006721 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=-18.8 required=3.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,HEADER_FROM_DIFFERENT_DOMAINS,INCLUDES_CR_TRAILER, INCLUDES_PATCH,MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS,URIBL_BLOCKED, USER_AGENT_GIT autolearn=ham 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 02E32C433E0 for ; Fri, 8 Jan 2021 14:37:24 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id BF9C223884 for ; Fri, 8 Jan 2021 14:37:23 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1727076AbhAHOhX (ORCPT ); Fri, 8 Jan 2021 09:37:23 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:55994 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1727040AbhAHOhU (ORCPT ); Fri, 8 Jan 2021 09:37:20 -0500 Received: from mail-ed1-x52d.google.com (mail-ed1-x52d.google.com [IPv6:2a00:1450:4864:20::52d]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 7E4ADC0612FE for ; Fri, 8 Jan 2021 06:36:40 -0800 (PST) Received: by mail-ed1-x52d.google.com with SMTP id y24so11366401edt.10 for ; Fri, 08 Jan 2021 06:36:40 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=cloud.ionos.com; s=google; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=ZdhYqzo7vGHt0kaFItNFL8QlDmgaVS2uhNAqxmjrpdU=; b=Q5NkzXOb1zqk1ACAFnCSwmXnUm40Pa2+oS5BVplA3rYKnIzDHYl+p3QZtsJG2MB3U8 nWVJgwaDbbwi4RoRscdFsrPZc+df8QVYd9JpYh/ZG8ucrO2GkAErpTByh/eBZ/P6PK3J nz+YOuA+nD4tFPuFJ2z4imcafvbcnegcgJBWCdQJ3TYY4qav7G6AtmJkX5BKqryA1g9U kdda9RfV4yyefxfPvrGXnoLLo8dZpgVuritiTtp7G8lEkIc1xKnsOlG2h2pUj4SeXIDv u1mt4Uf1A3C6ktDDHb8EcBdaQra9v/RaJO+ks855eepc4uEYcvxTQVZQEHYlPPuH7lV6 m+QA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=ZdhYqzo7vGHt0kaFItNFL8QlDmgaVS2uhNAqxmjrpdU=; b=aSoZzcKDstxZjh9A3+khHnKOkTL8vltV41T82le71Yup0jh1Uchjfh2iSrkcO/JcOa deWvgqv6mQEslMTb6eRGZ+0YV+oBxvj1YNz5iLMdqNO5NIONW9h2ADAK86cw1qivS5D/ XAcmFl422ZzkGV10In61ZRYOMGr/cxvS/ObZYtLkMg2HX2VGIV77k7pRt6PsY4LuQc7+ 7EvHo9v9Lfi9rBtaRH0/1bB0nSGQgKDIL8KOEuqw74uoxgDE7atE6/lCYRTeKPrVGw7o tVOf7K11QaaoyPxRhBsZcdqJ2b3/kVDwRJZWac5irz/k5Be3TxH9nIKOLHKkCQ76uuPa gyxw== X-Gm-Message-State: AOAM53392T3NtjDCSMr6/zqkADsQaN5obGNjWy3KZFZO7kkJ7S6YV6zq PhTUkdGCERGCFUsRA1rilFfpSX5B/wh+WA== X-Google-Smtp-Source: ABdhPJyh81QCgA8fVsaRaSru1rNwtnMg2jXBG7J9/SANWKKG26wI+YIeI7rJi8A8aXaXfIBQ91Z3pw== X-Received: by 2002:a50:abc6:: with SMTP id u64mr5546709edc.21.1610116599197; Fri, 08 Jan 2021 06:36:39 -0800 (PST) Received: from jwang-Latitude-5491.fkb.profitbricks.net ([2001:16b8:4906:c200:31ac:50df:cd1f:f7fc]) by smtp.gmail.com with ESMTPSA id e25sm3858698edq.24.2021.01.08.06.36.38 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 08 Jan 2021 06:36:38 -0800 (PST) From: Jack Wang To: linux-block@vger.kernel.org Cc: axboe@kernel.dk, hch@infradead.org, sagi@grimberg.me, bvanassche@acm.org, danil.kipnis@cloud.ionos.com, Swapnil Ingle Subject: [PATCH for-rc 4/5] block/rnbd: Adding name to the Contributors List Date: Fri, 8 Jan 2021 15:36:33 +0100 Message-Id: <20210108143634.175394-5-jinpu.wang@cloud.ionos.com> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20210108143634.175394-1-jinpu.wang@cloud.ionos.com> References: <20210108143634.175394-1-jinpu.wang@cloud.ionos.com> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: linux-block@vger.kernel.org From: Swapnil Ingle Adding name to the Contributors List Signed-off-by: Swapnil Ingle Acked-by: Jack Wang Acked-by: Danil Kipnis Signed-off-by: Jack Wang --- drivers/block/rnbd/README | 1 + 1 file changed, 1 insertion(+) diff --git a/drivers/block/rnbd/README b/drivers/block/rnbd/README index 1773c0aa0bd4..080f58a5400a 100644 --- a/drivers/block/rnbd/README +++ b/drivers/block/rnbd/README @@ -90,3 +90,4 @@ Kleber Souza Lutz Pogrell Milind Dumbare Roman Penyaev +Swapnil Ingle From patchwork Fri Jan 8 14:36:34 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jinpu Wang X-Patchwork-Id: 12006729 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=-18.8 required=3.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,HEADER_FROM_DIFFERENT_DOMAINS,INCLUDES_CR_TRAILER, INCLUDES_PATCH,MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS,URIBL_BLOCKED, USER_AGENT_GIT autolearn=ham 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 7A752C4332D for ; Fri, 8 Jan 2021 14:38:04 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 3FC8B23884 for ; Fri, 8 Jan 2021 14:38:04 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1727494AbhAHOh6 (ORCPT ); Fri, 8 Jan 2021 09:37:58 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:56092 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726748AbhAHOh5 (ORCPT ); Fri, 8 Jan 2021 09:37:57 -0500 Received: from mail-ed1-x530.google.com (mail-ed1-x530.google.com [IPv6:2a00:1450:4864:20::530]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 692CEC0612FF for ; Fri, 8 Jan 2021 06:36:41 -0800 (PST) Received: by mail-ed1-x530.google.com with SMTP id u19so11451711edx.2 for ; Fri, 08 Jan 2021 06:36:41 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=cloud.ionos.com; s=google; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=ScMrBuTqjTl8319DDqHcMUIBD1FsCL0Z6pG3bPYJIM4=; b=H7A4uGKBnPTa7bvvSnMq0Jt7V5kVZC/xTLbWWQzKDgMLJSXQqVKt7sXR1j973lyYkV OtQj49+RUzyS4i7VBPhEpgV5AMy6HT+7lkTadhZ1r+706jrfSR0kdTvncTDteo50trpZ 5PAnYsYm9O7MannRIMDUW9+z34ZwXQGKsMmzjDFHLOsgHDV5Pm2/DN2gnZKokVaANUT9 WJKiZwvlsCmuz8EYg2yXncGnVG/EsFyz3EV9VAbYYsxZMzZXF6bL0n35AaXqnBkjcPGW mom0VEaQj1Aqzi0B/ZFvZLghVREBwOSsgWlZQtB6i4B94hIhRwhj10KD5X8Prd8Lin83 EyJw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=ScMrBuTqjTl8319DDqHcMUIBD1FsCL0Z6pG3bPYJIM4=; b=VxF0uBLPxK92MeBqDg/6lN49H9bnjzD6Zr5xq+BBlEgcRDQKrHqIG6XXrvM2RNjNCS TV0uQ+pzWbk/Ldd/gRDCDIdBLuZDqupl/lcyNMPGrq60CKj2KiDD9F2Rto4tpuGkK9CI p5wvTdYBXkhOGpPSZKJaEHiYEjXv8b7oxQ33do/jhZmrc6KB1QyPXOl0iChSUFgzWLsL DSWTaeJMm6cqRu24vOOJEv1VNYiUMACFEU6SDxVSi17xMFyWA44NgBb394/DuRXrJK2X faxwiKM7m1s5k0kFBy1zhvxCwQSDlMPE7mbFx8V3F0Lc1XEljk23pYP1dWPysqxBg1bQ VAIg== X-Gm-Message-State: AOAM532qOxnieuVey1B7tvy9RDRR1aBwmDXV5hs52w2WlXkqhra3iW4K 3RbVyfkqksGCaPOHjIWLg8T7YfgPiki/1A== X-Google-Smtp-Source: ABdhPJz+Vb7nmsHRmskf7mb3upTeTt8wbLoY7+LjVjje+rEqNONSgjuvL2ZTD5AbrJkjoFBCHrn8Ow== X-Received: by 2002:aa7:c58a:: with SMTP id g10mr5409627edq.315.1610116600052; Fri, 08 Jan 2021 06:36:40 -0800 (PST) Received: from jwang-Latitude-5491.fkb.profitbricks.net ([2001:16b8:4906:c200:31ac:50df:cd1f:f7fc]) by smtp.gmail.com with ESMTPSA id e25sm3858698edq.24.2021.01.08.06.36.39 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 08 Jan 2021 06:36:39 -0800 (PST) From: Jack Wang To: linux-block@vger.kernel.org Cc: axboe@kernel.dk, hch@infradead.org, sagi@grimberg.me, bvanassche@acm.org, danil.kipnis@cloud.ionos.com, Gioh Kim Subject: [PATCH for-rc 5/5] block/rnbd-clt: avoid module unload race with close confirmation Date: Fri, 8 Jan 2021 15:36:34 +0100 Message-Id: <20210108143634.175394-6-jinpu.wang@cloud.ionos.com> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20210108143634.175394-1-jinpu.wang@cloud.ionos.com> References: <20210108143634.175394-1-jinpu.wang@cloud.ionos.com> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: linux-block@vger.kernel.org We had kernel panic, it is caused by unload module and last close confirmation. call trace: [1196029.743127] free_sess+0x15/0x50 [rtrs_client] [1196029.743128] rtrs_clt_close+0x4c/0x70 [rtrs_client] [1196029.743129] ? rnbd_clt_unmap_device+0x1b0/0x1b0 [rnbd_client] [1196029.743130] close_rtrs+0x25/0x50 [rnbd_client] [1196029.743131] rnbd_client_exit+0x93/0xb99 [rnbd_client] [1196029.743132] __x64_sys_delete_module+0x190/0x260 And in the crashdump confirmation kworker is also running. PID: 6943 TASK: ffff9e2ac8098000 CPU: 4 COMMAND: "kworker/4:2" #0 [ffffb206cf337c30] __schedule at ffffffff9f93f891 #1 [ffffb206cf337cc8] schedule at ffffffff9f93fe98 #2 [ffffb206cf337cd0] schedule_timeout at ffffffff9f943938 #3 [ffffb206cf337d50] wait_for_completion at ffffffff9f9410a7 #4 [ffffb206cf337da0] __flush_work at ffffffff9f08ce0e #5 [ffffb206cf337e20] rtrs_clt_close_conns at ffffffffc0d5f668 [rtrs_client] #6 [ffffb206cf337e48] rtrs_clt_close at ffffffffc0d5f801 [rtrs_client] #7 [ffffb206cf337e68] close_rtrs at ffffffffc0d26255 [rnbd_client] #8 [ffffb206cf337e78] free_sess at ffffffffc0d262ad [rnbd_client] #9 [ffffb206cf337e88] rnbd_clt_put_dev at ffffffffc0d266a7 [rnbd_client] The problem is both code path try to close same session, which lead to panic. To fix it, just skip the sess if the refcount already drop to 0. Fixes: f7a7a5c228d4 ("block/rnbd: client: main functionality") Signed-off-by: Jack Wang Reviewed-by: Gioh Kim --- drivers/block/rnbd/rnbd-clt.c | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/drivers/block/rnbd/rnbd-clt.c b/drivers/block/rnbd/rnbd-clt.c index c696c3a937d7..7bdd26229c70 100644 --- a/drivers/block/rnbd/rnbd-clt.c +++ b/drivers/block/rnbd/rnbd-clt.c @@ -1697,7 +1697,8 @@ static void rnbd_destroy_sessions(void) */ list_for_each_entry_safe(sess, sn, &sess_list, list) { - WARN_ON(!rnbd_clt_get_sess(sess)); + if (!rnbd_clt_get_sess(sess)) + continue; close_rtrs(sess); list_for_each_entry_safe(dev, tn, &sess->devs_list, list) { /*