From patchwork Tue Mar 24 12:30:52 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Taehee Yoo X-Patchwork-Id: 1260614 X-Patchwork-Delegate: davem@davemloft.net Return-Path: X-Original-To: patchwork-incoming-netdev@ozlabs.org Delivered-To: patchwork-incoming-netdev@ozlabs.org Authentication-Results: ozlabs.org; spf=none (no SPF record) smtp.mailfrom=vger.kernel.org (client-ip=209.132.180.67; helo=vger.kernel.org; envelope-from=netdev-owner@vger.kernel.org; receiver=) Authentication-Results: ozlabs.org; dmarc=pass (p=none dis=none) header.from=gmail.com Authentication-Results: ozlabs.org; dkim=pass (2048-bit key; unprotected) header.d=gmail.com header.i=@gmail.com header.a=rsa-sha256 header.s=20161025 header.b=rjcQwrEE; dkim-atps=neutral Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by ozlabs.org (Postfix) with ESMTP id 48mrFh4J2Cz9sSM for ; Tue, 24 Mar 2020 23:31:04 +1100 (AEDT) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1727580AbgCXMbC (ORCPT ); Tue, 24 Mar 2020 08:31:02 -0400 Received: from mail-pf1-f195.google.com ([209.85.210.195]:38084 "EHLO mail-pf1-f195.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1727256AbgCXMbB (ORCPT ); Tue, 24 Mar 2020 08:31:01 -0400 Received: by mail-pf1-f195.google.com with SMTP id z25so4867447pfa.5; Tue, 24 Mar 2020 05:31:00 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:to:cc:subject:date:message-id; bh=nqAcdWRnqSA/uVQmjWL4caKhzvHsEqccflrG15Mc1BU=; b=rjcQwrEEwd38HKXiiRHyTNtX0owKMWahas2q3bAKpZ1vIA4OUp3hbVUqW1LGfxqMZr erGnJNkhR3tAMGTxniU/ZRotGBQvYFEQEFFDqSzeUTi0ZszrjcoraZE5ZTxWCYUZTmaY I8B9Htzw5eYOpCrniauwt4bO7n72EQtSYl9GjjcCR/KvuI0vLJZiIIQ/9fO5bOZnby0g 3xnh2OnRis2zvZvVO/eeX59k5mwLZhLkV7EZbngbRoTb4nYOi1d8u18WdzfUd5z1KNKd yCWqU799wMfom4lGqpgo+ycYYv+YBAhE5C0/KiK2sKK5rc/0Rln9FPd61TFroyHQZ7mP hEwA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id; bh=nqAcdWRnqSA/uVQmjWL4caKhzvHsEqccflrG15Mc1BU=; b=l+KECkUuPi4c2AZw+tTQFF2RQYogbCY9wT6x2OCmwjcnFmZtrQv6daOS30OsuCAGFU 5g68YZXGatUA+WWJBRiroROeFUcLioAH/VvViYxDdOhs/GmwX3pf+I29EVlI3o6scphE AL+5h4EleqsK+B7OlBzwDt3UNZJmR41A6wgTdRjnIkOUuDv2mqN2cmaHlmg6wp4V528E WPw/QS+/V9GSnO94OUStqod7eOivY/H9i0gh3MtsGi4NsxJ2o9wOabIoUb3WDyh+9dWk 7Qwr6FVBvfXCGC4VGn3bNQSigtDsk0/4PmxTpNpC4Ofg9oouYHwGc3b6G5AdjgsLitNN zHTg== X-Gm-Message-State: ANhLgQ34aae9IL2Kf4KSIHzObJM2rQ8oICtr8IoHxPBvqnwoNDLJOprm l3PwFph2isHec2myixGwdyA= X-Google-Smtp-Source: ADFU+vvf33TJmQrGUFdzHUfRsPxkmjO7EFt1Uq5CQXRJ7pqbjC9tsRCv1U6/9456hIJojqhMXy9JPA== X-Received: by 2002:a63:fd0d:: with SMTP id d13mr23986197pgh.302.1585053059651; Tue, 24 Mar 2020 05:30:59 -0700 (PDT) Received: from localhost.localdomain ([180.70.143.152]) by smtp.gmail.com with ESMTPSA id v26sm2966546pfn.51.2020.03.24.05.30.56 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 24 Mar 2020 05:30:58 -0700 (PDT) From: Taehee Yoo To: davem@davemloft.net, kuba@kernel.org, gregkh@linuxfoundation.org, rafael@kernel.org, j.vosburgh@gmail.com, vfalico@gmail.com, andy@greyhouse.net, netdev@vger.kernel.org, linux-kernel@vger.kernel.org Cc: ap420073@gmail.com, mitch.a.williams@intel.com Subject: [PATCH net 1/3] class: add class_find_and_get_file_ns() helper function Date: Tue, 24 Mar 2020 12:30:52 +0000 Message-Id: <20200324123052.18904-1-ap420073@gmail.com> X-Mailer: git-send-email 2.17.1 Sender: netdev-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: netdev@vger.kernel.org The new helper function is to find and get a class file. This function is useful for checking whether the class file is existing or not. This function will be used by networking stack to check "/sys/class/net/*" file. Reported-by: syzbot+830c6dbfc71edc4f0b8f@syzkaller.appspotmail.com Fixes: b76cdba9cdb2 ("[PATCH] bonding: add sysfs functionality to bonding (large)") Signed-off-by: Taehee Yoo --- drivers/base/class.c | 12 ++++++++++++ include/linux/device/class.h | 4 +++- 2 files changed, 15 insertions(+), 1 deletion(-) diff --git a/drivers/base/class.c b/drivers/base/class.c index bcd410e6d70a..dedf41f32f0d 100644 --- a/drivers/base/class.c +++ b/drivers/base/class.c @@ -105,6 +105,17 @@ void class_remove_file_ns(struct class *cls, const struct class_attribute *attr, sysfs_remove_file_ns(&cls->p->subsys.kobj, &attr->attr, ns); } +struct kernfs_node *class_find_and_get_file_ns(struct class *cls, + const char *name, + const void *ns) +{ + struct kernfs_node *kn = NULL; + + if (cls) + kn = kernfs_find_and_get_ns(cls->p->subsys.kobj.sd, name, ns); + return kn; +} + static struct class *class_get(struct class *cls) { if (cls) @@ -580,6 +591,7 @@ int __init classes_init(void) EXPORT_SYMBOL_GPL(class_create_file_ns); EXPORT_SYMBOL_GPL(class_remove_file_ns); +EXPORT_SYMBOL_GPL(class_find_and_get_file_ns); EXPORT_SYMBOL_GPL(class_unregister); EXPORT_SYMBOL_GPL(class_destroy); diff --git a/include/linux/device/class.h b/include/linux/device/class.h index e8d470c457d1..230cf2ce6d3f 100644 --- a/include/linux/device/class.h +++ b/include/linux/device/class.h @@ -209,7 +209,9 @@ extern int __must_check class_create_file_ns(struct class *class, extern void class_remove_file_ns(struct class *class, const struct class_attribute *attr, const void *ns); - +struct kernfs_node *class_find_and_get_file_ns(struct class *cls, + const char *name, + const void *ns); static inline int __must_check class_create_file(struct class *class, const struct class_attribute *attr) { From patchwork Tue Mar 24 12:31:04 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Taehee Yoo X-Patchwork-Id: 1260615 X-Patchwork-Delegate: davem@davemloft.net Return-Path: X-Original-To: patchwork-incoming-netdev@ozlabs.org Delivered-To: patchwork-incoming-netdev@ozlabs.org Authentication-Results: ozlabs.org; spf=none (no SPF record) smtp.mailfrom=vger.kernel.org (client-ip=209.132.180.67; helo=vger.kernel.org; envelope-from=netdev-owner@vger.kernel.org; receiver=) Authentication-Results: ozlabs.org; dmarc=pass (p=none dis=none) header.from=gmail.com Authentication-Results: ozlabs.org; dkim=pass (2048-bit key; unprotected) header.d=gmail.com header.i=@gmail.com header.a=rsa-sha256 header.s=20161025 header.b=Axg7D1R2; dkim-atps=neutral Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by ozlabs.org (Postfix) with ESMTP id 48mrFw1pjNz9sSM for ; Tue, 24 Mar 2020 23:31:16 +1100 (AEDT) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1727611AbgCXMbN (ORCPT ); Tue, 24 Mar 2020 08:31:13 -0400 Received: from mail-pg1-f196.google.com ([209.85.215.196]:46717 "EHLO mail-pg1-f196.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1727256AbgCXMbM (ORCPT ); Tue, 24 Mar 2020 08:31:12 -0400 Received: by mail-pg1-f196.google.com with SMTP id k191so7800695pgc.13; Tue, 24 Mar 2020 05:31:12 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:to:cc:subject:date:message-id; bh=D3JI0OQU8x2pwfGu19abKz8hfaV3ClUa1LRDR1fAqM4=; b=Axg7D1R2KMjDIo/ri9ExJCeHa7O6Y8Ex2bB17ohf5FrjppjNzZKUc/pnyIYXAsiafS RjXyoB7sQCg6b9x5xZdNCYlhREFsPTQsE9EBtM/LTSMtY1USWfGCQTyk96Q13t1uX41X 2WdkstyddM9tIrUUe7jzNcpTeVpOhO6YPGlRq0kL5XFxRFnQgEcRa+iE8pIbx44VcbUG dGq/mWozbThild/OnXL3cXXhapq9klN5YRs00waue2cgJcjpggJIOFKEu/cEueelV+m+ ubAheNEpg56Wq/K+FtSWL6p2HPVtn6KmFUrUdk48D0V8kTvkvwD+PupLRWRDGAY0crCH s7dg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id; bh=D3JI0OQU8x2pwfGu19abKz8hfaV3ClUa1LRDR1fAqM4=; b=DBmUbQNUyg7iwZ27sw2q6TYk+HMRWioaCzcpLIz/mCStFXuOemgY0UeMx4baGbSMZz Q3DJeOr5EBnEYykbRX0RKIdD9d5NCKxR09bXO7O0lcxrSBKItim6bQZURKGdYO9T8CSF yedcIIw3j/NlMkFDsNz7JWolifWIah28XfxFssQad0GKYwq7a20HZ+Y8aNH9hqgPMMc8 dy0WsvihpQdFM46v4RxYfLy70/pdx1PPUUiNjmjgRUQgLNRabGKVEhWy9Tg5qBU4Chos kJizS9bsA8wRM6UBf8c/ZLireQIho4gYTcEERdqT8c6N1LqoBFGxsageICereeFkv0KI 89vg== X-Gm-Message-State: ANhLgQ2WkysdRdIgD/9Y0z+n/kwzi/0bRjq+JFomBXRppg+vKco/yRg0 kXziKMGvnI09iOmRPzOVoUg= X-Google-Smtp-Source: ADFU+vuvazGxt+ZX6Sa6qam11zv/P2AlsEXxrsMv96eC/57mOzFSHAsbecN95nzF/nJ2FJfdR0s4lQ== X-Received: by 2002:a62:3147:: with SMTP id x68mr1584388pfx.62.1585053071672; Tue, 24 Mar 2020 05:31:11 -0700 (PDT) Received: from localhost.localdomain ([180.70.143.152]) by smtp.gmail.com with ESMTPSA id w6sm15959336pfw.55.2020.03.24.05.31.07 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 24 Mar 2020 05:31:10 -0700 (PDT) From: Taehee Yoo To: davem@davemloft.net, kuba@kernel.org, gregkh@linuxfoundation.org, rafael@kernel.org, j.vosburgh@gmail.com, vfalico@gmail.com, andy@greyhouse.net, netdev@vger.kernel.org, linux-kernel@vger.kernel.org Cc: ap420073@gmail.com, mitch.a.williams@intel.com Subject: [PATCH net 2/3] net: core: add netdev_class_has_file_ns() helper function Date: Tue, 24 Mar 2020 12:31:04 +0000 Message-Id: <20200324123104.18983-1-ap420073@gmail.com> X-Mailer: git-send-email 2.17.1 Sender: netdev-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: netdev@vger.kernel.org This helper function is to check whether the class file "/sys/class/net*" is existing or not. In the next patch, this helper function will be used. Reported-by: syzbot+830c6dbfc71edc4f0b8f@syzkaller.appspotmail.com Fixes: b76cdba9cdb2 ("[PATCH] bonding: add sysfs functionality to bonding (large)") Signed-off-by: Taehee Yoo --- include/linux/netdevice.h | 2 +- net/core/net-sysfs.c | 13 +++++++++++++ 2 files changed, 14 insertions(+), 1 deletion(-) diff --git a/include/linux/netdevice.h b/include/linux/netdevice.h index 6c3f7032e8d9..e32edca79e3a 100644 --- a/include/linux/netdevice.h +++ b/include/linux/netdevice.h @@ -4545,7 +4545,7 @@ int netdev_class_create_file_ns(const struct class_attribute *class_attr, const void *ns); void netdev_class_remove_file_ns(const struct class_attribute *class_attr, const void *ns); - +bool netdev_class_has_file_ns(const char *name, const void *ns); static inline int netdev_class_create_file(const struct class_attribute *class_attr) { return netdev_class_create_file_ns(class_attr, NULL); diff --git a/net/core/net-sysfs.c b/net/core/net-sysfs.c index 4c826b8bf9b1..78de063201bc 100644 --- a/net/core/net-sysfs.c +++ b/net/core/net-sysfs.c @@ -1781,6 +1781,19 @@ void netdev_class_remove_file_ns(const struct class_attribute *class_attr, } EXPORT_SYMBOL(netdev_class_remove_file_ns); +bool netdev_class_has_file_ns(const char *name, const void *ns) +{ + struct kernfs_node *kn; + + kn = class_find_and_get_file_ns(&net_class, name, ns); + if (kn) { + kernfs_put(kn); + return true; + } + return false; +} +EXPORT_SYMBOL(netdev_class_has_file_ns); + int __init netdev_kobject_init(void) { kobj_ns_type_register(&net_ns_type_operations); From patchwork Tue Mar 24 12:31:15 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Taehee Yoo X-Patchwork-Id: 1260616 X-Patchwork-Delegate: davem@davemloft.net Return-Path: X-Original-To: patchwork-incoming-netdev@ozlabs.org Delivered-To: patchwork-incoming-netdev@ozlabs.org Authentication-Results: ozlabs.org; spf=none (no SPF record) smtp.mailfrom=vger.kernel.org (client-ip=209.132.180.67; helo=vger.kernel.org; envelope-from=netdev-owner@vger.kernel.org; receiver=) Authentication-Results: ozlabs.org; dmarc=pass (p=none dis=none) header.from=gmail.com Authentication-Results: ozlabs.org; dkim=pass (2048-bit key; unprotected) header.d=gmail.com header.i=@gmail.com header.a=rsa-sha256 header.s=20161025 header.b=RcKXWgpP; dkim-atps=neutral Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by ozlabs.org (Postfix) with ESMTP id 48mrG84yfXz9sSL for ; Tue, 24 Mar 2020 23:31:28 +1100 (AEDT) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1727640AbgCXMb0 (ORCPT ); Tue, 24 Mar 2020 08:31:26 -0400 Received: from mail-pg1-f195.google.com ([209.85.215.195]:35533 "EHLO mail-pg1-f195.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1727256AbgCXMbZ (ORCPT ); Tue, 24 Mar 2020 08:31:25 -0400 Received: by mail-pg1-f195.google.com with SMTP id 7so8969528pgr.2; Tue, 24 Mar 2020 05:31:24 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:to:cc:subject:date:message-id; bh=djbKCaqS+TKD77Tlh4JwH9yLK2oEV/Wol+ObqXwwa7Q=; b=RcKXWgpPYI5AvCqNOJ2eW7ZIErLVGwFJ75FIJJwWSUkte44zPo98jaQQwgWZNqCWas as2Hd8yLXwG5pdgt1xzqgDq9vxNOZ3KTAb5cR4M+Bu9nYKt+GGAAsJpzVxGgw47dDSwn nDv4P8dMI4wSV87Vgm6v1tPAIWIBrhXK6Ts/fJWnfAG/g1dZEJNkyiVzJVbsfQNJkGId jHjAv6cinJN+9PYOPYwqeOPW15blPYEIz+m/goYrGWgfqUOtjv52T8kfSamk7jxLmXPt 1pc1/TNKjuHsYO+3sFxaP1DeXcNkD6KzkMTSGFGLiLNPR6B74USDulQalkwpcXIqZORp IP3w== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id; bh=djbKCaqS+TKD77Tlh4JwH9yLK2oEV/Wol+ObqXwwa7Q=; b=gJ8+SeUdRgzXnV8E0kTyVmmiEnIICykj1gE8yVjkDkIxpEo/Rl3DqnJSIK2alScyd5 +ugCC61ziWc0HBcmeSiuKPsXndvop/mneU1B06k497FqCWmSD/0yoLBpJwK7SkUpEHrh +oInW+WuH2m55J7vSSQoie/MnEHT/mdUtTqSl6Uv0h5NbyC9O9nABBvA5V5UdMN3W7j0 N4yYL7YR7I+hY/Pb3SKlhM3kxfeFKgPZqosruJGkB2cdDX4N3GKRn5lD0VuQ7FBUJxyS crOB3h1KIrsOCr2OtFRYJzUkExQMKS3zZp+5N8Eho0b6ptoWvdVB2OXBNE86RsiFz+IX S7Yw== X-Gm-Message-State: ANhLgQ3OJsb6MQKnGBYLIY3/m2M43mvTxxV5MpGEVzlhz8twKyizZdHy f/T0RIRIlttUITGC3kLjs8Q= X-Google-Smtp-Source: ADFU+vtNUAXvFR94kwsUBwBDdbO17XfeFEF38u4wAqo4l+XZa01wNMK7+YpH+2F3AsNeCLa84JV9fQ== X-Received: by 2002:a62:7911:: with SMTP id u17mr28535280pfc.305.1585053084203; Tue, 24 Mar 2020 05:31:24 -0700 (PDT) Received: from localhost.localdomain ([180.70.143.152]) by smtp.gmail.com with ESMTPSA id s27sm226122pgn.90.2020.03.24.05.31.20 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 24 Mar 2020 05:31:23 -0700 (PDT) From: Taehee Yoo To: davem@davemloft.net, kuba@kernel.org, gregkh@linuxfoundation.org, rafael@kernel.org, j.vosburgh@gmail.com, vfalico@gmail.com, andy@greyhouse.net, netdev@vger.kernel.org, linux-kernel@vger.kernel.org Cc: ap420073@gmail.com, mitch.a.williams@intel.com Subject: [PATCH net 3/3] net: core: avoid warning in dev_change_net_namespace() Date: Tue, 24 Mar 2020 12:31:15 +0000 Message-Id: <20200324123115.19076-1-ap420073@gmail.com> X-Mailer: git-send-email 2.17.1 Sender: netdev-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: netdev@vger.kernel.org When interface's namespace is being changed, dev_change_net_namespace() is called. This removes and re-allocates many resources that include sysfs files. The "/net/class/net/" is one of them. If the sysfs creation routine(device_rename()) found duplicate sysfs file name, it warns about it and fails. But unfortunately, at that point, dev_change_net_namespace() doesn't return fail because rollback cost is too high. So, the interface can't have a sysfs file. The approach of this patch is to find the duplicate sysfs file as fast as possible. If it found that, dev_change_net_namespace() returns fail immediately with zero rollback cost. This patch includes two other things. a) Acquire rtnl_lock() in both bond_create_sysfs() and bond_destroy_sysfs() to avoid race condition. b) Do not remove "/sys/class/net/bonding_masters" sysfs file by bond_destroy_sysfs() if the file wasn't created by bond_create_sysfs(). Test commands: ip netns add nst ip link add bonding_masters type dummy modprobe bonding ip link set bonding_masters netns nst Splat looks like: [ 32.793965][ T986] WARNING: CPU: 3 PID: 986 at net/core/dev.c:10098 dev_change_net_namespace+0x9be/0xc10 [ 32.795213][ T986] Modules linked in: bonding dummy openvswitch nsh nf_conncount nf_nat nf_conntrack nf_defrag_ipv6 x [ 32.797369][ T986] CPU: 3 PID: 986 Comm: ip Not tainted 5.6.0-rc5+ #474 [ 32.798137][ T986] Hardware name: innotek GmbH VirtualBox/VirtualBox, BIOS VirtualBox 12/01/2006 [ 32.799111][ T986] RIP: 0010:dev_change_net_namespace+0x9be/0xc10 [ 32.799838][ T986] Code: 45 34 b2 c6 05 85 a4 87 01 01 e8 0d aa c7 fe 0f 0b e9 dd f6 ff ff b8 ea ff ff ff e9 82 fb ff [ 32.805599][ T986] RSP: 0018:ffff88804aeeee60 EFLAGS: 00010282 [ 32.806247][ T986] RAX: 00000000ffffffef RBX: ffff888057151000 RCX: 0000000000000006 [ 32.807110][ T986] RDX: 0000000000000000 RSI: 0000000000000008 RDI: ffff88804ac2c014 [ 32.807997][ T986] RBP: ffff8880571510b8 R08: fffffbfff67b65cc R09: fffffbfff67b65cc [ 32.808873][ T986] R10: 0000000000000001 R11: fffffbfff67b65cb R12: ffff8880571510a0 [ 32.809720][ T986] R13: ffff88804b9f0040 R14: ffff888057151090 R15: ffff888057151c08 [ 32.810575][ T986] FS: 00007f0c9d5960c0(0000) GS:ffff88806cc00000(0000) knlGS:0000000000000000 [ 32.811540][ T986] CS: 0010 DS: 0000 ES: 0000 CR0: 0000000080050033 [ 32.812314][ T986] CR2: 00007fcaf6747590 CR3: 0000000049c58005 CR4: 00000000000606e0 [ 32.813191][ T986] DR0: 0000000000000000 DR1: 0000000000000000 DR2: 0000000000000000 [ 32.814052][ T986] DR3: 0000000000000000 DR6: 00000000fffe0ff0 DR7: 0000000000000400 [ 32.822906][ T986] Call Trace: [ 32.823294][ T986] ? do_dup2+0x450/0x450 [ 32.823828][ T986] ? dev_get_valid_name+0xc0/0xc0 [ 32.824421][ T986] ? ns_capable_common+0x5c/0xd0 [ 32.825007][ T986] ? __netlink_ns_capable+0xc3/0xf0 [ 32.825650][ T986] do_setlink+0x163/0x2ef0 [ 32.826088][ T986] ? is_bpf_image_address+0xff/0x1d0 [ 32.826663][ T986] ? rtnl_getlink+0x8a0/0x8a0 [ 32.827275][ T986] ? __kernel_text_address+0xe/0x30 [ 32.827999][ T986] ? unwind_get_return_address+0x5f/0xa0 [ 32.828793][ T986] ? create_prof_cpu_mask+0x20/0x20 [ 32.829391][ T986] ? arch_stack_walk+0x83/0xb0 [ 32.829949][ T986] ? memset+0x1f/0x40 [ 32.830410][ T986] ? __nla_validate_parse+0x98/0x1ab0 [ 32.831046][ T986] ? nla_memcpy+0x90/0x90 [ 32.831544][ T986] ? __lock_acquire+0xdfe/0x3de0 [ 32.832136][ T986] __rtnl_newlink+0x9c5/0x1270 [ ... ] Reported-by: syzbot+830c6dbfc71edc4f0b8f@syzkaller.appspotmail.com Fixes: b76cdba9cdb2 ("[PATCH] bonding: add sysfs functionality to bonding (large)") Signed-off-by: Taehee Yoo --- drivers/net/bonding/bond_sysfs.c | 13 ++++++++++++- include/net/bonding.h | 1 + net/core/dev.c | 4 ++++ 3 files changed, 17 insertions(+), 1 deletion(-) diff --git a/drivers/net/bonding/bond_sysfs.c b/drivers/net/bonding/bond_sysfs.c index 2d615a93685e..02c0ae58b9db 100644 --- a/drivers/net/bonding/bond_sysfs.c +++ b/drivers/net/bonding/bond_sysfs.c @@ -772,9 +772,13 @@ int bond_create_sysfs(struct bond_net *bn) { int ret; + bn->skip_destroy_class = false; bn->class_attr_bonding_masters = class_attr_bonding_masters; sysfs_attr_init(&bn->class_attr_bonding_masters.attr); + rtnl_lock(); + if (netdev_class_has_file_ns("bonding_masters", bn->net)) + goto err; ret = netdev_class_create_file_ns(&bn->class_attr_bonding_masters, bn->net); /* Permit multiple loads of the module by ignoring failures to @@ -788,13 +792,16 @@ int bond_create_sysfs(struct bond_net *bn) * configure multiple bonding devices. */ if (ret == -EEXIST) { +err: /* Is someone being kinky and naming a device bonding_master? */ if (__dev_get_by_name(bn->net, class_attr_bonding_masters.attr.name)) pr_err("network device named %s already exists in sysfs\n", class_attr_bonding_masters.attr.name); ret = 0; + bn->skip_destroy_class = true; } + rtnl_unlock(); return ret; @@ -803,7 +810,11 @@ int bond_create_sysfs(struct bond_net *bn) /* Remove /sys/class/net/bonding_masters. */ void bond_destroy_sysfs(struct bond_net *bn) { - netdev_class_remove_file_ns(&bn->class_attr_bonding_masters, bn->net); + rtnl_lock(); + if (!bn->skip_destroy_class) + netdev_class_remove_file_ns(&bn->class_attr_bonding_masters, + bn->net); + rtnl_unlock(); } /* Initialize sysfs for each bond. This sets up and registers diff --git a/include/net/bonding.h b/include/net/bonding.h index 3d56b026bb9e..725e26c4962c 100644 --- a/include/net/bonding.h +++ b/include/net/bonding.h @@ -607,6 +607,7 @@ struct bond_net { struct proc_dir_entry *proc_dir; #endif struct class_attribute class_attr_bonding_masters; + bool skip_destroy_class; }; int bond_arp_rcv(const struct sk_buff *skb, struct bonding *bond, struct slave *slave); diff --git a/net/core/dev.c b/net/core/dev.c index 402a986659cf..8a4d9a23fb63 100644 --- a/net/core/dev.c +++ b/net/core/dev.c @@ -10037,6 +10037,10 @@ int dev_change_net_namespace(struct net_device *dev, struct net *net, const char goto out; } + err = -EEXIST; + if (netdev_class_has_file_ns(dev->name, net)) + goto out; + /* * And now a mini version of register_netdevice unregister_netdevice. */