Received: by 2002:ac0:a5a7:0:0:0:0:0 with SMTP id m36-v6csp2043771imm; Mon, 16 Jul 2018 00:46:46 -0700 (PDT) X-Google-Smtp-Source: AAOMgpcz3racU1Vkwz/TNYNkWjlX/3kagVGek3Hcz20o8USaVwkRRAOXELChQm2qZYsIOW04iovr X-Received: by 2002:a17:902:6902:: with SMTP id j2-v6mr15576125plk.323.1531727206790; Mon, 16 Jul 2018 00:46:46 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1531727206; cv=none; d=google.com; s=arc-20160816; b=i2g4KM8QreoOFtji1+LTcDlEA0gWH0FIYRfXDM1RH928lR+s3LnGOMVnLrG4MfiWQ4 sGyr0dAuI0StzJbxJMgwRJQ9CjJztu2S+1ovVPaNktlQelr7KATbI1ieuUqoQAIQjU5B 5CtQlmrfR42vERvF+GTdfIEwMaUMMGlsxUH83+f5P9GR4K1pfAthCoPAeVjRsIa9X5Bn YuY/CpZt25nSpnxb9xzAje1FHVnHX7Q9Le0i1x2XC96FMeNzRRrlWNYeHhONvurOm5hL 1WwBN7Gy/UDehSSmlEqRqDMnwjXZ9laKfRJzuoBD5pwHimKtGi0J0OFVPwIfVQt4EmDB tCNg== 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=z3O5DDmGf1IsKiUX68AJ0s03ueQOSvitIXMEfTkmavM=; b=enB7RGyAlEeY4FNJtc9176jHiPbMOvoctJ7A+G2N3MbEo7VcNFUJ8cbBkloEsV4y/0 IIxUSiGr2K+4YjUDzEJ2aszBxHTIlc9Tl0tlbVwqwgGast1+qg6imUhXE6tG1Xc8guHV mFV2eteDxm8ZdaG/Z9t+Ca4iza6lQHrNi+nmYowK2QFKk/VItReN4TnR9qhgrFaBvKuo +bEl2D0FwHV9/+l/oa+YZFo7TJyAfKwNFY/sBnsQOTHKyX9u7Nb68AwJ0QvihrypnkRj +L+XtoDocRbgUhskXXyIfZtNKnx8+gk3ZiVLvM+VTTbDXl1jwnBTmqLRZy8P29kDKfFT uAgw== 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 o20-v6si6108524pgh.319.2018.07.16.00.46.32; Mon, 16 Jul 2018 00:46:46 -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 S2389663AbeGPILk (ORCPT + 99 others); Mon, 16 Jul 2018 04:11:40 -0400 Received: from mail.linuxfoundation.org ([140.211.169.12]:49982 "EHLO mail.linuxfoundation.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S2389111AbeGPILj (ORCPT ); Mon, 16 Jul 2018 04:11:39 -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 9F7BFCA4; Mon, 16 Jul 2018 07:45:35 +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.4 43/43] loop: remember whether sysfs_create_group() was done Date: Mon, 16 Jul 2018 09:36:48 +0200 Message-Id: <20180716073516.619912920@linuxfoundation.org> X-Mailer: git-send-email 2.18.0 In-Reply-To: <20180716073511.796555857@linuxfoundation.org> References: <20180716073511.796555857@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.4-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 @@ -835,16 +835,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 @@ -59,6 +59,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;