Received: by 2002:a25:6193:0:0:0:0:0 with SMTP id v141csp3286419ybb; Tue, 31 Mar 2020 02:07:28 -0700 (PDT) X-Google-Smtp-Source: ADFU+vurxYNfBguYzMPf79ahw+4/lnL3VgzHeR5ZaD+3jQ1FiDeWL4o0xM5p/hE5iPpmBKB+7IfO X-Received: by 2002:a54:4f0a:: with SMTP id e10mr1396539oiy.127.1585645648321; Tue, 31 Mar 2020 02:07:28 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1585645648; cv=none; d=google.com; s=arc-20160816; b=bLlYndbYQgc9RTCPiqJDROSR/RKMfpl3fEKY5quZVkEo9ysKAe4CDZPM05SypPN87N ldf44PZFp4A//FV18Ox3sxhWy8OB25lN94TaC7TPHNFWugBo6l6p4p3JZqpE6iiU+4TY oy9Ch05mvlk4dd9sAZbQK/s2my1UG4AmFyCBnn6gHyyKGEWv5UZTbGOjVnPeqtxKmWJC qPRy+CPFPSFoIKTFreKKtcqxpaazgKC95WxDVTuUMMRAywkRqEXsMvelg6ojEfvp6Dns AwY1npSHGw1BneRU3AVgkcfLDLLz9/Hn7DZFtZIu17jVs6qNyv0p+ZfUwHaA4Vad7Odb y4gg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:content-transfer-encoding:mime-version :user-agent:references:in-reply-to:message-id:date:subject:cc:to :from:dkim-signature; bh=1TzDFSa4DUAwXJHCZPnH04xyJVboNkj0s8eKglfByM4=; b=sYjSuvqdwePFFrrZFVGJbT40b5hV8jx5/FMjVWhOYzpzV6UqYKdOdgsPqU1GPhR5XQ ufTLIDNmXs3SucoX/SXBQL3ed72f+Z2NFtJwnqs7OT9aQlE03HxfJbmLFS8qUPbRF8ID 6vNbFQcya6CTz50JTsafPerVW/eeQv87ypBRWLZW7W9w6onntNhA+CeOI1dPkDImuxDd tL1KsgGxDkee1BaUxrN0+vAJt/30UVJyeeLq41ppZkTav8596CdbQ1kYz4hiANYpceEh xSgb+SBqqEOOuKxcDuL00F1wt6TrZqbMyNnAvGLoKWzVHk/aRzStsCGWZui/RJy8BkQd DNqg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=default header.b=YPCLK1Vw; 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 o5si4846723otp.191.2020.03.31.02.07.16; Tue, 31 Mar 2020 02:07:28 -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; dkim=pass header.i=@kernel.org header.s=default header.b=YPCLK1Vw; 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 S1731083AbgCaJFt (ORCPT + 99 others); Tue, 31 Mar 2020 05:05:49 -0400 Received: from mail.kernel.org ([198.145.29.99]:46980 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1730053AbgCaJFr (ORCPT ); Tue, 31 Mar 2020 05:05:47 -0400 Received: from localhost (83-86-89-107.cable.dynamic.v4.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 5E3C821744; Tue, 31 Mar 2020 09:05:46 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1585645546; bh=AmV39TMQGWsiI2F+39TlEpVOQx8ahhIop5s/WGgN9jU=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=YPCLK1VwyOaELUFdmj3jSjL2lXjXjeOErsK5llDFE9GtTgFkvORPXtPJrpb9vwMZD v2BFn6E6RfKbE4rfWJoj+tpOczwAE9DtJSizco0BOQ0S+CarIyf0o6Zd3FHmTXS4SW aarRkGNmd3mVXNtqNH8s7umLVuLBe2UGvf0uTgmE= From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , stable@vger.kernel.org, stable@kernel.org, syzbot+ab4dae63f7d310641ded@syzkaller.appspotmail.com, Jason Gunthorpe Subject: [PATCH 5.5 087/170] RDMA/core: Fix missing error check on dev_set_name() Date: Tue, 31 Mar 2020 10:58:21 +0200 Message-Id: <20200331085433.531541289@linuxfoundation.org> X-Mailer: git-send-email 2.26.0 In-Reply-To: <20200331085423.990189598@linuxfoundation.org> References: <20200331085423.990189598@linuxfoundation.org> User-Agent: quilt/0.66 MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org From: Jason Gunthorpe commit f2f2b3bbf0d9f8d090b9a019679223b2bd1c66c4 upstream. If name memory allocation fails the name will be left empty and device_add_one() will crash: kobject: (0000000004952746): attempted to be registered with empty name! WARNING: CPU: 0 PID: 329 at lib/kobject.c:234 kobject_add_internal+0x7ac/0x9a0 lib/kobject.c:234 Kernel panic - not syncing: panic_on_warn set ... CPU: 0 PID: 329 Comm: syz-executor.5 Not tainted 5.6.0-rc2-syzkaller #0 Hardware name: Google Google Compute Engine/Google Compute Engine, BIOS Google 01/01/2011 Call Trace: __dump_stack lib/dump_stack.c:77 [inline] dump_stack+0x197/0x210 lib/dump_stack.c:118 panic+0x2e3/0x75c kernel/panic.c:221 __warn.cold+0x2f/0x3e kernel/panic.c:582 report_bug+0x289/0x300 lib/bug.c:195 fixup_bug arch/x86/kernel/traps.c:174 [inline] fixup_bug arch/x86/kernel/traps.c:169 [inline] do_error_trap+0x11b/0x200 arch/x86/kernel/traps.c:267 do_invalid_op+0x37/0x50 arch/x86/kernel/traps.c:286 invalid_op+0x23/0x30 arch/x86/entry/entry_64.S:1027 RIP: 0010:kobject_add_internal+0x7ac/0x9a0 lib/kobject.c:234 Code: 1a 98 ca f9 e9 f0 f8 ff ff 4c 89 f7 e8 6d 98 ca f9 e9 95 f9 ff ff e8 c3 f0 8b f9 4c 89 e6 48 c7 c7 a0 0e 1a 89 e8 e3 41 5c f9 <0f> 0b 41 bd ea ff ff ff e9 52 ff ff ff e8 a2 f0 8b f9 0f 0b e8 9b RSP: 0018:ffffc90005b27908 EFLAGS: 00010286 RAX: 0000000000000000 RBX: 0000000000000000 RCX: 0000000000000000 RDX: 0000000000040000 RSI: ffffffff815eae46 RDI: fffff52000b64f13 RBP: ffffc90005b27960 R08: ffff88805aeba480 R09: ffffed1015d06659 R10: ffffed1015d06658 R11: ffff8880ae8332c7 R12: ffff8880a37fd000 R13: 0000000000000000 R14: ffff888096691780 R15: 0000000000000001 kobject_add_varg lib/kobject.c:390 [inline] kobject_add+0x150/0x1c0 lib/kobject.c:442 device_add+0x3be/0x1d00 drivers/base/core.c:2412 add_one_compat_dev drivers/infiniband/core/device.c:901 [inline] add_one_compat_dev+0x46a/0x7e0 drivers/infiniband/core/device.c:857 rdma_dev_init_net+0x2eb/0x490 drivers/infiniband/core/device.c:1120 ops_init+0xb3/0x420 net/core/net_namespace.c:137 setup_net+0x2d5/0x8b0 net/core/net_namespace.c:327 copy_net_ns+0x29e/0x5a0 net/core/net_namespace.c:468 create_new_namespaces+0x403/0xb50 kernel/nsproxy.c:108 unshare_nsproxy_namespaces+0xc2/0x200 kernel/nsproxy.c:229 ksys_unshare+0x444/0x980 kernel/fork.c:2955 __do_sys_unshare kernel/fork.c:3023 [inline] __se_sys_unshare kernel/fork.c:3021 [inline] __x64_sys_unshare+0x31/0x40 kernel/fork.c:3021 do_syscall_64+0xfa/0x790 arch/x86/entry/common.c:294 entry_SYSCALL_64_after_hwframe+0x49/0xbe Link: https://lore.kernel.org/r/20200309193200.GA10633@ziepe.ca Cc: stable@kernel.org Fixes: 4e0f7b907072 ("RDMA/core: Implement compat device/sysfs tree in net namespace") Reported-by: syzbot+ab4dae63f7d310641ded@syzkaller.appspotmail.com Signed-off-by: Jason Gunthorpe Signed-off-by: Greg Kroah-Hartman --- drivers/infiniband/core/device.c | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) --- a/drivers/infiniband/core/device.c +++ b/drivers/infiniband/core/device.c @@ -896,7 +896,9 @@ static int add_one_compat_dev(struct ib_ cdev->dev.parent = device->dev.parent; rdma_init_coredev(cdev, device, read_pnet(&rnet->net)); cdev->dev.release = compatdev_release; - dev_set_name(&cdev->dev, "%s", dev_name(&device->dev)); + ret = dev_set_name(&cdev->dev, "%s", dev_name(&device->dev)); + if (ret) + goto add_err; ret = device_add(&cdev->dev); if (ret)