Received: by 2002:ad5:474a:0:0:0:0:0 with SMTP id i10csp638564imu; Thu, 3 Jan 2019 04:34:32 -0800 (PST) X-Google-Smtp-Source: ALg8bN5MjyASzE1dwJJaKYaN0VMK06yODZT16NVe7bbDda4IuYIY0fovLH87NSEY+tg7QotuoVEk X-Received: by 2002:a65:5bc4:: with SMTP id o4mr17070905pgr.426.1546518872062; Thu, 03 Jan 2019 04:34:32 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1546518872; cv=none; d=google.com; s=arc-20160816; b=QqXxSQI4Tf4akCvZ/X06Zf/sQCySox+zwpvlmqJ5JkJ9cflaDZ2CacURcPuU2yhirG FDmJ5xe5E0RiIsqieV13FWR6rRW+Oku6uL+fR1xwkvBjyKjZVGxzJQehCvz7N5G26mUB b4oXCprQpTA5sMFVkJpKfRctSTcfX4ZbY8Tipaw8DpxNCqu8vT5wqsXKlgHZ5KW1yeE6 MkN8G3rTKPiFZiwzlzdiwChifEzMh12/InNkhNLejzimx31BjQfOvzSnZpc45fGFnS04 nS7Yj+Ms/YsvMpn19tyVr99HjbeoGzV5yqgIMTx1KtQUNdsrX1weMvHUAFYwP+ZOFvdD OUyw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:user-agent:in-reply-to :content-disposition:mime-version:references:message-id:subject:cc :to:from:date:dkim-signature; bh=OXSjdv7FNKJ3cXueu7MvDhBruci2XeG6ByypEZO9aOE=; b=xJ2v5fQpSM2zOXFv3D9Xr8QoyObyX0rcvhvQ+6pziZC1nv4vss223uw24y0+5w0A2y QkpJUGkG5ebBezKZis3XMfey0bRRknFglLP0LE3u/B8HJUcnyZqKwn/GORPlB2I68bQc seWkj9Eu5noJRDsCrmcphmupwB2NMbgOUjI1XpPIalyAH5gUdFK4G5qwlFvsDOdv8ap8 5X9kKo8k/JPkK1vo/tSlpasgt0cGrMPaehSGtiUph3fEdUTnZRR1qqgP1DCBfEHW53qR J4LgQz2JgLpkrHBKHUEL1LZAje7nRbla+g8HaT0STiPsSAHYoPL8z5aexJ1xtOYecFdY QrLA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=default header.b=ozzmUrjm; 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 y10si8310747pgp.348.2019.01.03.04.34.16; Thu, 03 Jan 2019 04:34:32 -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; dkim=pass header.i=@kernel.org header.s=default header.b=ozzmUrjm; 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 S1730452AbfACJ01 (ORCPT + 99 others); Thu, 3 Jan 2019 04:26:27 -0500 Received: from mail.kernel.org ([198.145.29.99]:40472 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1727175AbfACJ0Z (ORCPT ); Thu, 3 Jan 2019 04:26:25 -0500 Received: from localhost (5356596B.cm-6-7b.dynamic.ziggo.nl [83.86.89.107]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPSA id 7E3AC21019; Thu, 3 Jan 2019 09:26:24 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1546507585; bh=HjWtj5FjfbsJj6gIH5lEqYnIcppI3FkQdMgD6ayTm2Y=; h=Date:From:To:Cc:Subject:References:In-Reply-To:From; b=ozzmUrjmWB3lRX5E6fBZMbZ62OCA/H6Kdf6pXtm78r9UfwYK4wHARYOUkoSBxKxRg 78sKRkBVVioAOPr9/GjqpHhfXiVPWVn1IDaqQIc7KEbJDCHiiNYInGRbhMKJCaF0Tt kGxnC6xVsmoboxWQ2yBYS2dsSmQd+5q4N/mA6KH0= Date: Thu, 3 Jan 2019 10:26:22 +0100 From: Greg Kroah-Hartman To: "Rafael J. Wysocki" Cc: Linus Torvalds , kernel test robot , David Woodhouse , Brian Norris , =?utf-8?B?UmFmYcWCIE1pxYJlY2tp?= , Richard Weinberger , Alban Bedel , Bartosz Golaszewski , Boris Brezillon , LKML , LKP Subject: Re: [LKP] [mtd] c4dfa25ab3: kernel_BUG_at_fs/sysfs/file.c Message-ID: <20190103092622.GA6262@kroah.com> References: <20190102005704.GC17624@shao2-debian> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: User-Agent: Mutt/1.11.1 (2018-12-01) Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org 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? -------------- 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. -- 2.20.1