Received: by 2002:a05:6a11:4021:0:0:0:0 with SMTP id ky33csp2353662pxb; Mon, 20 Sep 2021 19:52:14 -0700 (PDT) X-Google-Smtp-Source: ABdhPJzoCKdbQaksa9SGCY+Cp9Owi53o7lIaUDtqPL1zaPh1qi4Se8NK0cRlkLiCY1ofcMQMnV0J X-Received: by 2002:a05:6e02:20c7:: with SMTP id 7mr20207337ilq.118.1632192734844; Mon, 20 Sep 2021 19:52:14 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1632192734; cv=none; d=google.com; s=arc-20160816; b=lKMDt65tRACcIWynhYwZHri3ViflqUJ2f0T05z0+5ouzpySOjcz3jm5kSxEAec/1TF uRaQrNNT1Cy4oJoisrLyArxAhA4gLunGeKk/JzQQIM8D/laangXnqVTLDzDK+shQ3QID FKeLuRtAKnhuEZXjFqVpvVSylEo0b3oFjvIi2334dwT2Xpkt0XohhE26PCmXKxrk6Emf q8s8fW9JSXudkrDST6x9rm28jfwKKUKT76Y0XVXc45Ox+99gd9ocojL8hpnyfhvdSSAp +er6dH6XGTGL0Gw5UosgdAls0N76kQGKo0o04Wujfwc4NnMiz9d3KHniFQaAFlNUq833 80UA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :user-agent:references:in-reply-to:message-id:date:subject:cc:to :from:dkim-signature; bh=/W4bGwPlr8PSRMW3J2DeXMSxHQvFSbbxt8SDSiTxrAE=; b=MxPgZ9jjZPbEhgrB/kypG9AYfoqVuyRNCxt07/yX1hekcQytRzCWkSZG4hf0Lw2pMo osXKs/atj1jY3Dg2eGhXCn3/HTh7oiVnfLX+thoRnd1oB8h82jVEIdKpOtO5X9mdmqV7 Lm6FoCOP29uQ02RyElOsVMFnKYQgFLnNeMNTCLBR2T8L/wyeorkiWE6PE0dnKnaCD0h6 A4DWJRFPRQ2RwBVz1hxZ8EXWVD5ktzb6UYEUsRvKEE7R9+plY7DJXioYWdz408lBVKrL FzlFHwGMn94t4R4sxNdBWH1cwnlAmcY7o2oqYGiejrF8nI6TVpU6H2MuFs9ezIW8w73t 5f8A== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b=gRV6Q7q0; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linuxfoundation.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id i12si13291438jaf.41.2021.09.20.19.52.04; Mon, 20 Sep 2021 19:52:14 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) client-ip=23.128.96.18; Authentication-Results: mx.google.com; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b=gRV6Q7q0; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linuxfoundation.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1354128AbhITSrX (ORCPT + 99 others); Mon, 20 Sep 2021 14:47:23 -0400 Received: from mail.kernel.org ([198.145.29.99]:56388 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1382849AbhITSmb (ORCPT ); Mon, 20 Sep 2021 14:42:31 -0400 Received: by mail.kernel.org (Postfix) with ESMTPSA id 3828163349; Mon, 20 Sep 2021 17:32:04 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linuxfoundation.org; s=korg; t=1632159124; bh=JSlWRf+J8cegpqnrLWzv525DtN5CL4GM48c1AwWkFVg=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=gRV6Q7q0Kb64TVogi19cmYmZh2OanXEVq7PTf50tr0uGjoCVKFkPKr8kV2SS6DXCy ZffMMwbrT+wQJ7lL4wTXD47we2aTBnIXCAdUb4ST0JzV1zCgCdf5PNJwmwgz4LxrkQ K6DSVLUQa6HhOrJ1FKavSaVPRc2jsz12gfviGoxY= From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , stable@vger.kernel.org, syzbot+01321b15cc98e6bf96d6@syzkaller.appspotmail.com, Yanfei Xu , Tejun Heo , Jens Axboe , Sasha Levin Subject: [PATCH 5.14 087/168] blkcg: fix memory leak in blk_iolatency_init Date: Mon, 20 Sep 2021 18:43:45 +0200 Message-Id: <20210920163924.494984171@linuxfoundation.org> X-Mailer: git-send-email 2.33.0 In-Reply-To: <20210920163921.633181900@linuxfoundation.org> References: <20210920163921.633181900@linuxfoundation.org> User-Agent: quilt/0.66 MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org From: Yanfei Xu [ Upstream commit 6f5ddde41069fcd1f0993ec76c9dbbf9d021fd4d ] BUG: memory leak unreferenced object 0xffff888129acdb80 (size 96): comm "syz-executor.1", pid 12661, jiffies 4294962682 (age 15.220s) hex dump (first 32 bytes): 20 47 c9 85 ff ff ff ff 20 d4 8e 29 81 88 ff ff G...... ..).... 01 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 ................ backtrace: [] kmalloc include/linux/slab.h:591 [inline] [] kzalloc include/linux/slab.h:721 [inline] [] blk_iolatency_init+0x28/0x190 block/blk-iolatency.c:724 [] blkcg_init_queue+0xb4/0x1c0 block/blk-cgroup.c:1185 [] blk_alloc_queue+0x22a/0x2e0 block/blk-core.c:566 [] blk_mq_init_queue_data block/blk-mq.c:3100 [inline] [] __blk_mq_alloc_disk+0x25/0xd0 block/blk-mq.c:3124 [] loop_add+0x1c3/0x360 drivers/block/loop.c:2344 [] loop_control_get_free drivers/block/loop.c:2501 [inline] [] loop_control_ioctl+0x17e/0x2e0 drivers/block/loop.c:2516 [] vfs_ioctl fs/ioctl.c:51 [inline] [] __do_sys_ioctl fs/ioctl.c:874 [inline] [] __se_sys_ioctl fs/ioctl.c:860 [inline] [] __x64_sys_ioctl+0xfc/0x140 fs/ioctl.c:860 [] do_syscall_x64 arch/x86/entry/common.c:50 [inline] [] do_syscall_64+0x35/0xb0 arch/x86/entry/common.c:80 [] entry_SYSCALL_64_after_hwframe+0x44/0xae Once blk_throtl_init() queue init failed, blkcg_iolatency_exit() will not be invoked for cleanup. That leads a memory leak. Swap the blk_throtl_init() and blk_iolatency_init() calls can solve this. Reported-by: syzbot+01321b15cc98e6bf96d6@syzkaller.appspotmail.com Fixes: 19688d7f9592 (block/blk-cgroup: Swap the blk_throtl_init() and blk_iolatency_init() calls) Signed-off-by: Yanfei Xu Acked-by: Tejun Heo Link: https://lore.kernel.org/r/20210915072426.4022924-1-yanfei.xu@windriver.com Signed-off-by: Jens Axboe Signed-off-by: Sasha Levin --- block/blk-cgroup.c | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) diff --git a/block/blk-cgroup.c b/block/blk-cgroup.c index 31fe9be179d9..26446f97deee 100644 --- a/block/blk-cgroup.c +++ b/block/blk-cgroup.c @@ -1201,10 +1201,6 @@ int blkcg_init_queue(struct request_queue *q) if (preloaded) radix_tree_preload_end(); - ret = blk_iolatency_init(q); - if (ret) - goto err_destroy_all; - ret = blk_ioprio_init(q); if (ret) goto err_destroy_all; @@ -1213,6 +1209,12 @@ int blkcg_init_queue(struct request_queue *q) if (ret) goto err_destroy_all; + ret = blk_iolatency_init(q); + if (ret) { + blk_throtl_exit(q); + goto err_destroy_all; + } + return 0; err_destroy_all: -- 2.30.2