Received: by 2002:ac0:a5a7:0:0:0:0:0 with SMTP id m36-v6csp2039477imm; Mon, 16 Jul 2018 00:40:26 -0700 (PDT) X-Google-Smtp-Source: AAOMgpeGXyN3hgZIIJemf9n12Wnoinid5YjHhxZCFgLwd/mUv8tmJXuwuE7PGxAoPdQdq4ykUY/V X-Received: by 2002:a62:8a4f:: with SMTP id y76-v6mr16988485pfd.233.1531726826380; Mon, 16 Jul 2018 00:40:26 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1531726826; cv=none; d=google.com; s=arc-20160816; b=Y+JUlXMMAvZi0LlAg+kdv9Dj1G58xCpq2PG5gg5sTpSGVm3OsvjjmhnC8rtYzWMvjz 7YWU/M3OubwOS0/Xtq809eyoTKNgHQfMLIi6oJmUj6CQ7u0+kW/AwYCfAyl/tIMimqSs OvRiZIMRrAnxco+fNHNGqdA1l6RyCZsLMe0Om3g8hpEqX96QAUuRpq6HiXVtqqJ48RKo 2SmVgwwJyZc1MjanP4CnnibqYGjlAU6uIBdwuS+SVrzTYbS7t+eLcZhGJqWYRfUYiNRJ ecnc1j0hRljNkMe21d/ZW0llWQotiOUr0V/GjMb7htIH4z+5dVGgT8bokL1qeqKipOFY PAoA== 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=T1EsVVTqrL4v5b738mYpeDBLl+7Y4KbX4YcL4KNGNms=; b=s7Pej2+VpJxcqn+nRzsCej1eqg0lOgx6KFvrth3VLFLszVWigL/Nv8mZfxL8HmIbl2 TFsTIdr2XFlaXqeRaR6484ec2ZxhQkbQahgV601gKwgFOudnpsZx+chcQn+fMXDjVaRZ M54dL4AQDXLb2pGJ1Ps8gUJ2d5ZBWhiWL1HXNZaKuznkfcMuj+qW9TrvoAWqfqBwEaLa yVAXL0nBlGgulvJNHkyYIVhZqZ3KcGqPd3ztUJa9DXh2Vm4ipwDn8xuTBBun6Bm2pw5k VRxjfMhZHf97ilkQNQeB55opqMi2qi2JXfa1juZCnj/cU8E7XxNl4hGfzUz4mJAzhih4 WvbQ== 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 m4-v6si7545647pll.461.2018.07.16.00.40.11; Mon, 16 Jul 2018 00:40:26 -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 S2387840AbeGPIFC (ORCPT + 99 others); Mon, 16 Jul 2018 04:05:02 -0400 Received: from mail.linuxfoundation.org ([140.211.169.12]:47040 "EHLO mail.linuxfoundation.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726898AbeGPIFB (ORCPT ); Mon, 16 Jul 2018 04:05:01 -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 A4B31CA0; Mon, 16 Jul 2018 07:38:59 +0000 (UTC) From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , stable@vger.kernel.org, Tetsuo Handa , syzbot , Jens Axboe Subject: [PATCH 4.17 61/67] loop: remember whether sysfs_create_group() was done Date: Mon, 16 Jul 2018 09:35:30 +0200 Message-Id: <20180716073453.556655041@linuxfoundation.org> X-Mailer: git-send-email 2.18.0 In-Reply-To: <20180716073443.294323458@linuxfoundation.org> References: <20180716073443.294323458@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: Tetsuo Handa commit d3349b6b3c373ac1fbfb040b810fcee5e2adc7e0 upstream. syzbot is hitting WARN() triggered by memory allocation fault injection [1] because loop module is calling sysfs_remove_group() when sysfs_create_group() failed. Fix this by remembering whether sysfs_create_group() succeeded. [1] https://syzkaller.appspot.com/bug?id=3f86c0edf75c86d2633aeb9dd69eccc70bc7e90b Signed-off-by: Tetsuo Handa Reported-by: syzbot Reviewed-by: Greg Kroah-Hartman Renamed sysfs_ready -> sysfs_inited. Signed-off-by: Jens Axboe Signed-off-by: Greg Kroah-Hartman --- drivers/block/loop.c | 11 ++++++----- drivers/block/loop.h | 1 + 2 files changed, 7 insertions(+), 5 deletions(-) --- a/drivers/block/loop.c +++ b/drivers/block/loop.c @@ -833,16 +833,17 @@ static struct attribute_group loop_attri .attrs= loop_attrs, }; -static int loop_sysfs_init(struct loop_device *lo) +static void loop_sysfs_init(struct loop_device *lo) { - return sysfs_create_group(&disk_to_dev(lo->lo_disk)->kobj, - &loop_attribute_group); + lo->sysfs_inited = !sysfs_create_group(&disk_to_dev(lo->lo_disk)->kobj, + &loop_attribute_group); } static void loop_sysfs_exit(struct loop_device *lo) { - sysfs_remove_group(&disk_to_dev(lo->lo_disk)->kobj, - &loop_attribute_group); + if (lo->sysfs_inited) + sysfs_remove_group(&disk_to_dev(lo->lo_disk)->kobj, + &loop_attribute_group); } static void loop_config_discard(struct loop_device *lo) --- a/drivers/block/loop.h +++ b/drivers/block/loop.h @@ -58,6 +58,7 @@ struct loop_device { struct kthread_worker worker; struct task_struct *worker_task; bool use_dio; + bool sysfs_inited; struct request_queue *lo_queue; struct blk_mq_tag_set tag_set;