Received: by 2002:a25:824b:0:0:0:0:0 with SMTP id d11csp1188770ybn; Wed, 2 Oct 2019 12:10:07 -0700 (PDT) X-Google-Smtp-Source: APXvYqwkMEg60YtJ7nxftM/YQpQ01hkWMxvMv/K3KLFvaiJJdNM1sPZipG0zHZXNv/EquIWpOBDB X-Received: by 2002:a50:9e0a:: with SMTP id z10mr5610983ede.202.1570043407264; Wed, 02 Oct 2019 12:10:07 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1570043407; cv=none; d=google.com; s=arc-20160816; b=sFQg8GeWDBhLN+XsWTVPgZA9v0oGB2nwkNbKhTKdcPtwSiAJcDKqQ2gTsDbUdaE6Bg vdmAFeHmVwjH9aA8Lv7fOPYsUe6EUplxPrrbnwx5dobXQO4RzOy7DPcDw2MLsirNkwA5 Qddu/acUPni/NPcAK0zD8VeOwhKzdItUkHKcakVF+3qjy7beo/0cNWMxZ1jgzoyCyriR qOYZGGFn+cO800IhsFB5W3BJWd4ve88aMP/x//CEVRBtVmPotrBHsOoy3drB7BYq0epn Ji27ZxaJdjHF0GRuqLKZ8z0bQKi5/JfI80ExG1MVq3s1aQ5F7PEnrX5OxWMieF/tdSz3 U2DA== 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=iNsHSoqlKhQZ0ooz67E8KN0AZlFcGpvc74oL9Y77mbY=; b=IB4EQ86rIYyepogeAVwU7GOrM58aLUfUQQVD1UFHBccYN5UrPcRp5LzTZOzz9Qn3tn ztF4RNTmAPL+1V2RQSOvx1GcFnvfgQnlf6hT9ltW8C+Hn9BvHs9RTSBjfb2HM4sZbkm/ uNOXRvnZaApTbRp+/L++OrKBni71sp6ITZaGbl6Fg/sHHyIUiCGkM7nwUqks3nvXARGr //u7pIExd6kntSDpO7MPbaQdZQxRMdTVHDsV+yrTuVnS8xY5hNiSmwfhFqP/TEMuk/XN Yrtnra12HooRIcAVHnYy7tbG2LcvxFvn7bL+khRPoKJbFwD7OTWxhCmNyfsBOevD+bNd 1FMg== 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 w2si10250edc.386.2019.10.02.12.09.43; Wed, 02 Oct 2019 12:10:07 -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; 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 S1729439AbfJBTI0 (ORCPT + 99 others); Wed, 2 Oct 2019 15:08:26 -0400 Received: from shadbolt.e.decadent.org.uk ([88.96.1.126]:35620 "EHLO shadbolt.e.decadent.org.uk" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1729217AbfJBTIM (ORCPT ); Wed, 2 Oct 2019 15:08:12 -0400 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 1iFjyr-000364-G9; Wed, 02 Oct 2019 20:08:09 +0100 Received: from ben by deadeye with local (Exim 4.92.1) (envelope-from ) id 1iFjyo-0003ds-Hj; Wed, 02 Oct 2019 20:08:06 +0100 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, Denis Kirjanov , "Oliver Hartkopp" , "YueHaibing" , "Marc Kleine-Budde" Date: Wed, 02 Oct 2019 20:06:51 +0100 Message-ID: X-Mailer: LinuxStableQueue (scripts by bwh) X-Patchwork-Hint: ignore Subject: [PATCH 3.16 50/87] can: af_can: Fix error path of can_init() 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.75-rc1 review patch. If anyone has any objections, please let me know. ------------------ From: YueHaibing commit c5a3aed1cd3152429348ee1fe5cdcca65fe901ce upstream. 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 [bwh: Backported to 3.16: - af_can doesn't register any pernet_operations - It does start a global timer and add procfs entries that need to be cleaned up on the error path] Signed-off-by: Ben Hutchings --- --- a/net/can/af_can.c +++ b/net/can/af_can.c @@ -899,6 +899,8 @@ static struct notifier_block can_netdev_ 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) || @@ -924,12 +926,29 @@ static __init int can_init(void) can_init_proc(); /* 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: + kmem_cache_destroy(rcv_cache); + + if (stats_timer) + del_timer_sync(&can_stattimer); + + can_remove_proc(); + + return err; } static __exit void can_exit(void)