Received: by 2002:ad5:474a:0:0:0:0:0 with SMTP id i10csp646931imu; Thu, 3 Jan 2019 04:44:24 -0800 (PST) X-Google-Smtp-Source: ALg8bN4hLjh/V2N9mJyAGQ8OE+KzfQNTjn1SZM7+T9aUrPq4i22oWDxAU+bHjg8SQ6Y6CqTqIGJj X-Received: by 2002:a63:65c7:: with SMTP id z190mr16872487pgb.249.1546519464543; Thu, 03 Jan 2019 04:44:24 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1546519464; cv=none; d=google.com; s=arc-20160816; b=RL7FBCBm/f6WosbqD8E/2/2Nv2ujZWehnqCjdTvToZVLz3eZZ0XWBPvOoOO9ZrMs9c I8VlVvr4RL4Kk6kqNU94HqlESvTXQH5vuLH4qKSVXyMZigI6ae9XchwTi9LN7t+m0qaV C23OM+sCJJPF2b6Z0nPQzr6lGWLDmCOzuHgw5ylC0/S4QM40m1dtF+sOnMJbipIj/830 Yeoprfl1cY/ZUA9MWeLeH8cylOQ2fwO5xiFnWNWcptSdfEKPPETl/pqGYXkkGsrJjPz6 jRJc40TR5JAanTlYV+VkVA7Re+za+D2mHo0TvI+8Kx72A11AEcsih2o/N0To123XogU7 A20g== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:cc:to:subject:message-id:date:from :in-reply-to:references:mime-version; bh=GbOPGJ3IJDcBrfRMPKv/jkAuNaYdqSWYsR7bgi+yrfw=; b=TV9BrTk2Cu8twS/ePtNaTs+T2yfGUssB3+k6W+5tmzRaaNMSRRenJa7XBqWDrWqoCe gMmmUhrnlnVRr5Qgy9PrRQOqjX6khdgkYBIOW2vbJQY8WGthf/KGDuXZWBbTDfXvtpKx QtmFEgb1cg7ddXrHEXkd0CkrEIphPcpBFw3I63B3W2ko0KAXXvGsBqyMVcwXYY8KQ/vE asY8UEsbNeV3y/qs9Sg5G8/5R7rx+NU7tOjpvv5pvmTTOL2iKsCm7wS9PQVJl13gIFxT NlO+LthNTYQwvWTuFrH9l4PpWzN0HgTEjuOGGMH4Ymb7pyKgIylbebzBMfB7vEj5H5J6 DoWw== 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; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id u129si32653235pfu.117.2019.01.03.04.44.05; Thu, 03 Jan 2019 04:44:24 -0800 (PST) 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; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1729704AbfACJaL (ORCPT + 99 others); Thu, 3 Jan 2019 04:30:11 -0500 Received: from mail-ot1-f65.google.com ([209.85.210.65]:39991 "EHLO mail-ot1-f65.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726152AbfACJaK (ORCPT ); Thu, 3 Jan 2019 04:30:10 -0500 Received: by mail-ot1-f65.google.com with SMTP id s5so28889495oth.7 for ; Thu, 03 Jan 2019 01:30:10 -0800 (PST) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:mime-version:references:in-reply-to:from:date :message-id:subject:to:cc; bh=GbOPGJ3IJDcBrfRMPKv/jkAuNaYdqSWYsR7bgi+yrfw=; b=KnFM4Gg0TPGgQasu3oa5FSQe4C7cFfqNl8c6peQz7Esq4SJmtfeGMhxnXDaPLTtfE+ a57RjJ7ibzltKIVQBGnB5BwnCXdKEYixtLYsNjxeQInYkL63DYJGArVULvXOJlDpAwK5 D7gna5QlopFPa4vR2bjj60JRArIi8S62uEisLNizoYN8DqvVKFJcDnH1yWaTn2nj797f 8kIYvsPDKIukiMvzxoSzF35H+W1+Giuo5pBW0hQ6XD3/9ATCMpQXwccZjAETdg+5FC3Z r8Sm4BZx+3tY2e4rf9ZgDf76CzEwhRp8n5Tla940bvsWkVD/zGKwpRYXj+9zrokLJwT6 Iulg== X-Gm-Message-State: AJcUukfh2/AxX5GSOt18j3mYGg+2MBqh2RbgExkL70hSqjEEsPKsPII4 P13onwecLs7mWh71QVU/4Jvc6HHg8CRZhYHcExU= X-Received: by 2002:a9d:7f0d:: with SMTP id j13mr30873358otq.119.1546507809667; Thu, 03 Jan 2019 01:30:09 -0800 (PST) MIME-Version: 1.0 References: <20190102005704.GC17624@shao2-debian> <20190103092622.GA6262@kroah.com> In-Reply-To: <20190103092622.GA6262@kroah.com> From: "Rafael J. Wysocki" Date: Thu, 3 Jan 2019 10:29:58 +0100 Message-ID: Subject: Re: [LKP] [mtd] c4dfa25ab3: kernel_BUG_at_fs/sysfs/file.c To: Greg Kroah-Hartman Cc: "Rafael J. Wysocki" , Linus Torvalds , kernel test robot , David Woodhouse , Brian Norris , =?UTF-8?B?UmFmYcWCIE1pxYJlY2tp?= , Richard Weinberger , Alban Bedel , Bartosz Golaszewski , Boris Brezillon , LKML , LKP 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 On Thu, Jan 3, 2019 at 10:26 AM Greg Kroah-Hartman wrote: > > On Wed, Jan 02, 2019 at 10:44:50PM +0100, Rafael J. Wysocki wrote: > > On Wed, Jan 2, 2019 at 8:53 PM Linus Torvalds > > wrote: > > > > [cut] > > > > > Greg, Rafael: it does strike me that the "BUG_ON()" in > > > sysfs_create_file_ns() could easily have been a > > > > > > if (WARN_ON(..)) > > > return -EINVAL; > > > > > > which would have made the machine boot and probably make things easier > > > for normal users to report. The kernel test robot doesn't care, but > > > non-booting kernels are usually not nice to debug or report for normal > > > human beings.. > > > > I agree. > > > > This isn't a good enough reason to crash the kernel IMO. > > I agree too. > > Here's a patch for this, I'll queue it up after -rc1 is out. Rafael, > look good to you? Yes, it does. Please feel free to add Reviewed-by: Rafael J. Wysocki to it. > > -------------- > > From: Greg Kroah-Hartman > Subject: [PATCH] sysfs: convert BUG_ON to WARN_ON > > It's rude to crash the system just because the developer did something > wrong, as it prevents them from usually even seeing what went wrong. > > So convert the few BUG_ON() calls that have snuck into the sysfs code > over the years to WARN_ON() to make it more "friendly". All of these > are able to be recovered from, so it makes no sense to crash. > > Reported-by: Linus Torvalds > Cc: "Rafael J. Wysocki" > Signed-off-by: Greg Kroah-Hartman > --- > fs/sysfs/dir.c | 3 ++- > fs/sysfs/file.c | 6 ++++-- > fs/sysfs/group.c | 3 ++- > fs/sysfs/symlink.c | 3 ++- > 4 files changed, 10 insertions(+), 5 deletions(-) > > diff --git a/fs/sysfs/dir.c b/fs/sysfs/dir.c > index feeae8081c22..aa85f2874a9f 100644 > --- a/fs/sysfs/dir.c > +++ b/fs/sysfs/dir.c > @@ -43,7 +43,8 @@ int sysfs_create_dir_ns(struct kobject *kobj, const void *ns) > kuid_t uid; > kgid_t gid; > > - BUG_ON(!kobj); > + if (WARN_ON(!kobj)) > + return -EINVAL; > > if (kobj->parent) > parent = kobj->parent->sd; > diff --git a/fs/sysfs/file.c b/fs/sysfs/file.c > index bb71db63c99c..51398457fe00 100644 > --- a/fs/sysfs/file.c > +++ b/fs/sysfs/file.c > @@ -325,7 +325,8 @@ int sysfs_create_file_ns(struct kobject *kobj, const struct attribute *attr, > kuid_t uid; > kgid_t gid; > > - BUG_ON(!kobj || !kobj->sd || !attr); > + if (WARN_ON(!kobj || !kobj->sd || !attr)) > + return -EINVAL; > > kobject_get_ownership(kobj, &uid, &gid); > return sysfs_add_file_mode_ns(kobj->sd, attr, false, attr->mode, > @@ -537,7 +538,8 @@ int sysfs_create_bin_file(struct kobject *kobj, > kuid_t uid; > kgid_t gid; > > - BUG_ON(!kobj || !kobj->sd || !attr); > + if (WARN_ON(!kobj || !kobj->sd || !attr)) > + return -EINVAL; > > kobject_get_ownership(kobj, &uid, &gid); > return sysfs_add_file_mode_ns(kobj->sd, &attr->attr, true, > diff --git a/fs/sysfs/group.c b/fs/sysfs/group.c > index 1eb2d6307663..57038604d4a8 100644 > --- a/fs/sysfs/group.c > +++ b/fs/sysfs/group.c > @@ -112,7 +112,8 @@ static int internal_create_group(struct kobject *kobj, int update, > kgid_t gid; > int error; > > - BUG_ON(!kobj || (!update && !kobj->sd)); > + if (WARN_ON(!kobj || (!update && !kobj->sd))) > + return -EINVAL; > > /* Updates may happen before the object has been instantiated */ > if (unlikely(update && !kobj->sd)) > diff --git a/fs/sysfs/symlink.c b/fs/sysfs/symlink.c > index 215c225b2ca1..c4deecc80f67 100644 > --- a/fs/sysfs/symlink.c > +++ b/fs/sysfs/symlink.c > @@ -23,7 +23,8 @@ static int sysfs_do_create_link_sd(struct kernfs_node *parent, > { > struct kernfs_node *kn, *target = NULL; > > - BUG_ON(!name || !parent); > + if (WARN_ON(!name || !parent)) > + return -EINVAL; > > /* > * We don't own @target_kobj and it may be removed at any time. > --