Received: by 2002:ad5:474a:0:0:0:0:0 with SMTP id i10csp3311175imu; Sun, 11 Nov 2018 12:07:22 -0800 (PST) X-Google-Smtp-Source: AJdET5dXA/e6G54/k5z+Mgmlo8Xn8TY53PPJHn47lwrFxiMj5Vl229WcXJRakfyz6GEDNZ/1xDoy X-Received: by 2002:a62:56dd:: with SMTP id h90-v6mr17236804pfj.225.1541966842185; Sun, 11 Nov 2018 12:07:22 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1541966842; cv=none; d=google.com; s=arc-20160816; b=Gtb6qB8EnZVfTWI/qNow+Z1QrLh+oN7aR7B53F/pV0uqkP0ptMfWFCwwm84AL9Jc0o /AOXi6TrBZdZ4ZaGf+3Ax3bVViSswPF88DagTu0wxRThVAqRgu0NrAT7m7EA75dUfVOy PEQesHArIHwCviEfB2hK7Mi/WFpGZwp+2UFRnWtrwCb651NmEFpbeYX3MBMtseYgZngD aECylHinVK+eiYtNumnMWXW+gUfvTsHYJWeLk/iWJEnfGkeBTgDF2VOqeLxjUqs2lQBJ SVhM1XnQ1E5nZ0eigJ6wGSd9/tYjuj3XIZGY9oFpzPoiuK4/kvvte5UdibkQ5JY5pKAC Ub2w== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:in-reply-to:subject:message-id:date:cc:to :from:mime-version:content-transfer-encoding:content-disposition; bh=nWBVVRQxZLRUu/Aw1x5Tfd1ko3SZDuA1ZoUIe+ud3mQ=; b=pRVf0yzssltfq4ohnVezZ+tNhTeD32NPzrVDocmiH6qbYP6CvMlmTkkDyOUkuOcpB4 9E2P1DKULxE17z4rWxLWejK+XII0Cow7q7B2GlgVLWsfUSaHSWTW76DPeSPxA1f2Fg9P skCm8KUaQCNpW8+/6Z/0qjqoSQnd2jJKPvtZoryHvk1i+yQkuwtdDWyxkyFNERvBsJMi 6TBtWy2Pip7BjDkzf6v27OwRBppIT0Q1eF7ajly/fpFVoo/hlhmhEk3xzubYuZO7VYTO OAEJi5eygNEAUpegsMZdXUTiXR7qpG2s9TgZOtex6VZGjfriCoTdxzWgOEsVt/FxFy5s spEw== 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 g12si5774908pgd.567.2018.11.11.12.07.06; Sun, 11 Nov 2018 12:07:22 -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 Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1731265AbeKLFy6 (ORCPT + 99 others); Mon, 12 Nov 2018 00:54:58 -0500 Received: from shadbolt.e.decadent.org.uk ([88.96.1.126]:51810 "EHLO shadbolt.e.decadent.org.uk" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726992AbeKLFy5 (ORCPT ); Mon, 12 Nov 2018 00:54:57 -0500 Received: from [192.168.4.242] (helo=deadeye) by shadbolt.decadent.org.uk with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.89) (envelope-from ) id 1gLvtB-0000lG-4U; Sun, 11 Nov 2018 19:59:21 +0000 Received: from ben by deadeye with local (Exim 4.91) (envelope-from ) id 1gLvsP-0001QD-0h; Sun, 11 Nov 2018 19:58:33 +0000 Content-Type: text/plain; charset="UTF-8" Content-Disposition: inline Content-Transfer-Encoding: 8bit MIME-Version: 1.0 From: Ben Hutchings To: linux-kernel@vger.kernel.org, stable@vger.kernel.org CC: akpm@linux-foundation.org, "Tetsuo Handa" , "Greg Kroah-Hartman" , "syzbot" Date: Sun, 11 Nov 2018 19:49:05 +0000 Message-ID: X-Mailer: LinuxStableQueue (scripts by bwh) Subject: [PATCH 3.16 052/366] driver core: Don't ignore class_dir_create_and_add() failure. In-Reply-To: X-SA-Exim-Connect-IP: 192.168.4.242 X-SA-Exim-Mail-From: ben@decadent.org.uk X-SA-Exim-Scanned: No (on shadbolt.decadent.org.uk); SAEximRunCond expanded to false Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org 3.16.61-rc1 review patch. If anyone has any objections, please let me know. ------------------ From: Tetsuo Handa commit 84d0c27d6233a9ba0578b20f5a09701eb66cee42 upstream. syzbot is hitting WARN() at kernfs_add_one() [1]. This is because kernfs_create_link() is confused by previous device_add() call which continued without setting dev->kobj.parent field when get_device_parent() failed by memory allocation fault injection. Fix this by propagating the error from class_dir_create_and_add() to the calllers of get_device_parent(). [1] https://syzkaller.appspot.com/bug?id=fae0fb607989ea744526d1c082a5b8de6529116f Signed-off-by: Tetsuo Handa Reported-by: syzbot Cc: Greg Kroah-Hartman Signed-off-by: Greg Kroah-Hartman [bwh: Backported to 3.16: adjust context] Signed-off-by: Ben Hutchings --- drivers/base/core.c | 14 ++++++++++++-- 1 file changed, 12 insertions(+), 2 deletions(-) --- a/drivers/base/core.c +++ b/drivers/base/core.c @@ -709,7 +709,7 @@ class_dir_create_and_add(struct class *c dir = kzalloc(sizeof(*dir), GFP_KERNEL); if (!dir) - return NULL; + return ERR_PTR(-ENOMEM); dir->class = class; kobject_init(&dir->kobj, &class_dir_ktype); @@ -719,7 +719,7 @@ class_dir_create_and_add(struct class *c retval = kobject_add(&dir->kobj, parent_kobj, "%s", class->name); if (retval < 0) { kobject_put(&dir->kobj); - return NULL; + return ERR_PTR(retval); } return &dir->kobj; } @@ -1000,6 +1000,10 @@ int device_add(struct device *dev) parent = get_device(dev->parent); kobj = get_device_parent(dev, parent); + if (IS_ERR(kobj)) { + error = PTR_ERR(kobj); + goto parent_error; + } if (kobj) dev->kobj.parent = kobj; @@ -1097,6 +1101,7 @@ done: kobject_del(&dev->kobj); Error: cleanup_device_parent(dev); +parent_error: if (parent) put_device(parent); name_error: @@ -1867,6 +1872,11 @@ int device_move(struct device *dev, stru device_pm_lock(); new_parent = get_device(new_parent); new_parent_kobj = get_device_parent(dev, new_parent); + if (IS_ERR(new_parent_kobj)) { + error = PTR_ERR(new_parent_kobj); + put_device(new_parent); + goto out; + } pr_debug("device: '%s': %s: moving to '%s'\n", dev_name(dev), __func__, new_parent ? dev_name(new_parent) : "");