Received: by 2002:ac0:a5a7:0:0:0:0:0 with SMTP id m36-v6csp2042965imm; Mon, 16 Jul 2018 00:45:31 -0700 (PDT) X-Google-Smtp-Source: AAOMgpe46VSKWkObvGIxOvVLPgecQhIIv18GB/bYDCgg5QH2Ch7x5ef6Nb9JOTNnG4YozsmaVS2F X-Received: by 2002:a17:902:5a3:: with SMTP id f32-v6mr2839386plf.286.1531727131433; Mon, 16 Jul 2018 00:45:31 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1531727131; cv=none; d=google.com; s=arc-20160816; b=wtlTrOvvJcu89V8vss7zHww8OgGK/IN2vML/ct+QZ3gqxV8bJlJ6kDi05qCRPgdWhC mu31H9xPaX1TxQBYKzt9ZY2Zk1wFnCJnH+Vj1OXOv5Z8Qx7XNK6EW6bf4DVnVYZwHqpE 5aka9MVUSHTqTqpTP86LA6lCD/7S3WL3WyIJ0FAYWW1eYzx9hWQBkb20iPJ2rusUqI+c W4RKPSao6R6WiQVE2c0335glf30LfCcQztWrzqCdv6h0dYLWe0zxN/TALTSAlQsyzulT sXHQrF2fuQhkQnc8u7ubp0sEd5+jFzySXduIr8sD3b5m0/EwpgzL7FztORx+rUiifsK/ YtfA== 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=HnK9af9B79ERQpEJ6ga50k4g19CeHHgHV1CiGGwyAiE=; b=W6u7RBxWLH/X0PNdYWvWBGNGhbvuex3NDyJKil2BBSex23GHRo02tykkZaQHWUcKtH qQ2qj2Q2kEOcZenQSOe0TJX6gqv0WZWrYYH5ho5pPjG6OIA9ED7gfc7dHzPXmcLTZIfb 7HxMmcdGX2ByU6CfAVhSx6bUbtUQmSbeOVMBKBB1XjTFjyLRCHV/9ML7G7bkZkkgpp/a i3I7lcGtKFXtscp5w1E3HW6phUMN5UhL1sz/F+cXazx/+Q0L/yrdIEccHmUkYayWTgvV zGd+we5tvcW2KKcMb9rd9AjG2zvX++wwLn+9EKClhe4jHsYCQzKxj87INpDtACOC9VM9 aQNQ== 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 p67-v6si21990835pfg.295.2018.07.16.00.45.16; Mon, 16 Jul 2018 00:45:31 -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 S2389073AbeGPIJf (ORCPT + 99 others); Mon, 16 Jul 2018 04:09:35 -0400 Received: from mail.linuxfoundation.org ([140.211.169.12]:48014 "EHLO mail.linuxfoundation.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S2388675AbeGPIJe (ORCPT ); Mon, 16 Jul 2018 04:09:34 -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 AC856CA0; Mon, 16 Jul 2018 07:43:30 +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.9 32/32] loop: remember whether sysfs_create_group() was done Date: Mon, 16 Jul 2018 09:36:40 +0200 Message-Id: <20180716073508.445812597@linuxfoundation.org> X-Mailer: git-send-email 2.18.0 In-Reply-To: <20180716073504.433996952@linuxfoundation.org> References: <20180716073504.433996952@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.9-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 Signed-off-by: Greg Kroah-Hartman Renamed sysfs_ready -> sysfs_inited. Signed-off-by: Jens Axboe --- 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 @@ -824,16 +824,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;