Received: by 2002:a25:ad19:0:0:0:0:0 with SMTP id y25csp837147ybi; Fri, 12 Jul 2019 05:28:45 -0700 (PDT) X-Google-Smtp-Source: APXvYqykhz2YLui69RDfT99QuUDWWR5VZvpMYgYxbQZC+N03rhuXPXiRal+FSpbi8zNaaNEThv7x X-Received: by 2002:a17:902:2884:: with SMTP id f4mr11022993plb.286.1562934525042; Fri, 12 Jul 2019 05:28:45 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1562934525; cv=none; d=google.com; s=arc-20160816; b=dSb/FSKrSJtz1gSJq4qixwIr7znMrkAozmApRZMxKBY2bce88XAP7e3I6R/Z0Qef6V I6qz2RbzMwkFctgaRHZ0GUo5RehpJTFzlWZpO5mgxK/ypAe/4j5bPUy8tfYEgCXOn1l+ 6wzFEu1L9y2APcqLSsHv25wplIpHfariuwt2uTjT7Lkno8Iw9lX0u04keIu8Qrr7iJxJ TZ6paNfR9oT5vKxLtPGdUq1hHNZHrvuhUkl668WsmVnWMEtfH7d3pRanBgkHlHV7e0as XAB4YE8gJKhB1r+dOu1K3cOOkA4te6g/+lswGar4PS1RMxb+0hHX687Y8RWTX+WgFBV7 9IFg== 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=WoQEVvIvVK/ydxai+AhKI4Gg3m3cKrdjTyhgaFj5N3A=; b=SlquDk3BZANWH6mXHGpAxwjyW+wRKLliqJ8NXk5+wksRbomigC6927dZPktA/jeSSa N7l5OgEJ7xl6mpiC+tHkoDOXmgNrGt6yyMwhdS4Jxb2SeX0cHsnW7qCRP7oO9jZ/cx5W XXNL+ghJiqGF7fOMCKKc/zWIXaSIG4OwTZAorQ9SI14P4RNaTjPMxhy0QGDutI7YhpJV WwDlw+/QOarpkAF7q7JS8NNJR36nIv6oC52I8F/cg49ELEuQF41X5iRT3s49Vi2+HQaS A0FV6/ACjK1cNSFfSoxTgzdE/genl1+ECGEsIOqVac0n6L5una/0kZGDZKNWJURbHcvR ph1g== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=default header.b=CiEoBY19; 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 12si8160920pfz.66.2019.07.12.05.28.28; Fri, 12 Jul 2019 05:28:45 -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=CiEoBY19; 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 S1728441AbfGLM0V (ORCPT + 99 others); Fri, 12 Jul 2019 08:26:21 -0400 Received: from mail.kernel.org ([198.145.29.99]:37384 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1727891AbfGLM0T (ORCPT ); Fri, 12 Jul 2019 08:26:19 -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 6486C2084B; Fri, 12 Jul 2019 12:26:18 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1562934378; bh=lUM4YCGKvNWFCOk/arLaupJ/88bRs1Q8JoFExYmsvu8=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=CiEoBY19LNDllOJIuhq8HqdWB++BeJOdLXJcM2+zcjqWvtJAObCzAH9PKHhMetzvn zAS+lS1zUJAOuZh2Q+qhO2toU2ANg9yad/d+KPZHdr5y3cUzYLqqj9ku29lKzV369c 4nt2B3ql5MTKJDMt+Xn+XZXqf67elxYzI/zS5/fQ= From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , stable@vger.kernel.org, YueHaibing , Oliver Hartkopp , Marc Kleine-Budde , Sasha Levin Subject: [PATCH 5.1 037/138] can: af_can: Fix error path of can_init() Date: Fri, 12 Jul 2019 14:18:21 +0200 Message-Id: <20190712121630.108968716@linuxfoundation.org> X-Mailer: git-send-email 2.22.0 In-Reply-To: <20190712121628.731888964@linuxfoundation.org> References: <20190712121628.731888964@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 [ Upstream commit c5a3aed1cd3152429348ee1fe5cdcca65fe901ce ] This patch add error path for can_init() to avoid possible crash if some error occurs. Fixes: 0d66548a10cb ("[CAN]: Add PF_CAN core module") Signed-off-by: YueHaibing Acked-by: Oliver Hartkopp Signed-off-by: Marc Kleine-Budde Signed-off-by: Sasha Levin --- net/can/af_can.c | 24 +++++++++++++++++++++--- 1 file changed, 21 insertions(+), 3 deletions(-) diff --git a/net/can/af_can.c b/net/can/af_can.c index e386d654116d..04132b0b5d36 100644 --- a/net/can/af_can.c +++ b/net/can/af_can.c @@ -959,6 +959,8 @@ static struct pernet_operations can_pernet_ops __read_mostly = { static __init int can_init(void) { + int err; + /* check for correct padding to be able to use the structs similarly */ BUILD_BUG_ON(offsetof(struct can_frame, can_dlc) != offsetof(struct canfd_frame, len) || @@ -972,15 +974,31 @@ static __init int can_init(void) if (!rcv_cache) return -ENOMEM; - register_pernet_subsys(&can_pernet_ops); + err = register_pernet_subsys(&can_pernet_ops); + if (err) + goto out_pernet; /* protocol register */ - sock_register(&can_family_ops); - register_netdevice_notifier(&can_netdev_notifier); + err = sock_register(&can_family_ops); + if (err) + goto out_sock; + err = register_netdevice_notifier(&can_netdev_notifier); + if (err) + goto out_notifier; + dev_add_pack(&can_packet); dev_add_pack(&canfd_packet); return 0; + +out_notifier: + sock_unregister(PF_CAN); +out_sock: + unregister_pernet_subsys(&can_pernet_ops); +out_pernet: + kmem_cache_destroy(rcv_cache); + + return err; } static __exit void can_exit(void) -- 2.20.1