Received: by 2002:a05:6a10:5bc5:0:0:0:0 with SMTP id os5csp3667013pxb; Sun, 24 Oct 2021 08:05:17 -0700 (PDT) X-Google-Smtp-Source: ABdhPJw5F5UdoJXX5zgkDroklTMISOlgawu5+B7ICRHue0YxLMISmS3QWpqrmn0Pa7BFxCV+bgDZ X-Received: by 2002:a17:907:d87:: with SMTP id go7mr6422131ejc.249.1635087917151; Sun, 24 Oct 2021 08:05:17 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1635087917; cv=none; d=google.com; s=arc-20160816; b=jAdnE1jbcCASr4GYjC9IPkbEvhJjccNUufdN+ZTN9Gb5ENG2GsxKZ15FvvV0IV/lm/ WKqozXK8a1PDkNhV4LAR1Fbcfp5zlHtKloSxBJvH4Gg3gha8nix/fYyf50In12sk1Fnz Amg64AwjbDE3myVL1NymgsoGOz54OKMiEE6Nbilt73bdiLgvSAg09qvoX9RYvbPO4f1b KqbL0uOqPDY30TL5yucOP/I1m8o5socEFM6eBOtI75nxmdnTXMiylx3Nw+EqOa+pwG3e uginly3UzRK7uXZIC4gy4+rH6B8Zui6cpchraBppWHpctclGCI7rowWmMjP3Ns9NZZF8 JKhw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:mime-version:references:in-reply-to:message-id :date:subject:cc:to:from:dkim-signature; bh=sFbUc8CH71I0jSgZO4ezMiudXcKS9p8Pep/RP8lHGug=; b=OULMhBom2CfpmpWd41htzd7K3BUNYUi9cH39bhMOhUMiLD+xNZgEGQXbQFO1DN+nmW +MeZMCnzgB62w8la9V3sZcTvc3/qPUjnKPhZYam/oX7IEo3NB/Y0Y2NeozGEQb2TwxFi xbDl0AiP0hHyJ1zsXLsrx60uD89YgT1UDChkvk105A4UezNOXpfjomDtXXMEcoHcEReX 4wyzH4pvARGH4v6OlnQ2bZVe2Ui9CZQX0IGBLhAJyFS0F5hvQywfSY6BZUaIgva9foxZ NB9DY0ITRzE5IA1+uxPXOEFbekPaj3PcRtP0CXFyizoRQB0l25PXB0i0yxSbQyCvxkz1 6Wrg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@narfation.org header.s=20121 header.b=onXqedq8; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=narfation.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id h4si22665058edt.426.2021.10.24.08.04.33; Sun, 24 Oct 2021 08:05:17 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) client-ip=23.128.96.18; Authentication-Results: mx.google.com; dkim=pass header.i=@narfation.org header.s=20121 header.b=onXqedq8; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=narfation.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S231563AbhJXPBI (ORCPT + 99 others); Sun, 24 Oct 2021 11:01:08 -0400 Received: from dvalin.narfation.org ([213.160.73.56]:51976 "EHLO dvalin.narfation.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231256AbhJXPBE (ORCPT ); Sun, 24 Oct 2021 11:01:04 -0400 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=narfation.org; s=20121; t=1635087521; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: in-reply-to:in-reply-to:references:references; bh=sFbUc8CH71I0jSgZO4ezMiudXcKS9p8Pep/RP8lHGug=; b=onXqedq85vG7HWIpWdR/vkLSFlPlah9x5M5rwGArkgrceQOk95crCPaAomGS8aF3surxTf HVQcDTAo+y2Ev0WDsziT5KFV5XMDQ3XBBnyurfcax0wtYRautxQDVkLt+OVGPMi4X8bO6/ 2UW+CygPECbMqNC1e0dTYSFvuxgK7Jo= From: Sven Eckelmann To: mareklindner@neomailbox.ch, sw@simonwunderlich.de, a@unstable.cc, davem@davemloft.net, kuba@kernel.org, Pavel Skripkin Cc: b.a.t.m.a.n@lists.open-mesh.org, netdev@vger.kernel.org, linux-kernel@vger.kernel.org, Pavel Skripkin , syzbot+28b0702ada0bf7381f58@syzkaller.appspotmail.com Subject: Re: [PATCH] net: batman-adv: fix error handling Date: Sun, 24 Oct 2021 16:58:30 +0200 Message-ID: <2526100.mKikVBQdmv@sven-l14> In-Reply-To: <20211024131356.10699-1-paskripkin@gmail.com> References: <2056331.oJahCzYEoq@sven-desktop> <20211024131356.10699-1-paskripkin@gmail.com> MIME-Version: 1.0 Content-Type: multipart/signed; boundary="nextPart2606459.3l26UXsCK9"; micalg="pgp-sha512"; protocol="application/pgp-signature" Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org --nextPart2606459.3l26UXsCK9 Content-Transfer-Encoding: 7Bit Content-Type: text/plain; charset="us-ascii"; protected-headers="v1" From: Sven Eckelmann To: mareklindner@neomailbox.ch, sw@simonwunderlich.de, a@unstable.cc, davem@davemloft.net, kuba@kernel.org, Pavel Skripkin Cc: b.a.t.m.a.n@lists.open-mesh.org, netdev@vger.kernel.org, linux-kernel@vger.kernel.org, Pavel Skripkin , syzbot+28b0702ada0bf7381f58@syzkaller.appspotmail.com Subject: Re: [PATCH] net: batman-adv: fix error handling Date: Sun, 24 Oct 2021 16:58:30 +0200 Message-ID: <2526100.mKikVBQdmv@sven-l14> In-Reply-To: <20211024131356.10699-1-paskripkin@gmail.com> References: <2056331.oJahCzYEoq@sven-desktop> <20211024131356.10699-1-paskripkin@gmail.com> On Sunday, 24 October 2021 15:13:56 CEST Pavel Skripkin wrote: > Syzbot reported ODEBUG warning in batadv_nc_mesh_free(). The problem was > in wrong error handling in batadv_mesh_init(). > > Before this patch batadv_mesh_init() was calling batadv_mesh_free() in case > of any batadv_*_init() calls failure. This approach may work well, when > there is some kind of indicator, which can tell which parts of batadv are > initialized; but there isn't any. > > All written above lead to cleaning up uninitialized fields. Even if we hide > ODEBUG warning by initializing bat_priv->nc.work, syzbot was able to hit > GPF in batadv_nc_purge_paths(), because hash pointer in still NULL. [1] > > To fix these bugs we can unwind batadv_*_init() calls one by one. > It is good approach for 2 reasons: 1) It fixes bugs on error handling > path 2) It improves the performance, since we won't call unneeded > batadv_*_free() functions. > > So, this patch makes all batadv_*_init() clean up all allocated memory > before returning with an error to no call correspoing batadv_*_free() > and open-codes batadv_mesh_free() with proper order to avoid touching > uninitialized fields. > > Link: https://lore.kernel.org/netdev/000000000000c87fbd05cef6bcb0@google.com/ [1] > Reported-and-tested-by: syzbot+28b0702ada0bf7381f58@syzkaller.appspotmail.com > Fixes: c6c8fea29769 ("net: Add batman-adv meshing protocol") > Signed-off-by: Pavel Skripkin Acked-by: Sven Eckelmann Kind regards, Sven --nextPart2606459.3l26UXsCK9 Content-Type: application/pgp-signature; name="signature.asc" Content-Description: This is a digitally signed message part. Content-Transfer-Encoding: 7Bit -----BEGIN PGP SIGNATURE----- iQIzBAABCgAdFiEEF10rh2Elc9zjMuACXYcKB8Eme0YFAmF1dJYACgkQXYcKB8Em e0bQcQ//Sla8E/Y1+ZjgSouR6oFVDORn2++Z0+TxHuzHzNw1m6/XePtcgybcRHXO LSAFMlQjhm6s0Rb4oJx3v4RUraWQgb87EZSXReFl85xWByHHZ61at3na6e/cmgdG BzYXkTynIb0BI4j2MVV7xE0bBDGzcdm2drlEGE/BOpughyUISpFqhv/S4Y6fPHl8 x9HyGlWZU/Iud2tIN6hkYAJFWCkFYryqh9eKQ2kE8rWugKyLiwuc71JDcFgALx1f GjSEyBIok+m4nMOkXhx8VA9aJCVd8yzxml0Cs9Tnge+AwAA9xpR8Xl9wvfHHflM3 cKwjv8rOl4KbXuhs++I0Qsqb6IciUUCMIFzLhw89daEKVEkzTnHIWBQPaGq+87Pi YM8LnVkUx0Bepsig5DArFIxBjVQS7tP9agvza8Skcgw46q+gcaC3QqJBfpoi1NAy aiAWCJDMr3q6ui/R4fmMCJh7lGHveKwF91yuSOl5V1RCao7L/Ltix4+GapUYiDky 0Vg5XDy97jMJp+hcVhT1Lmd5ZbAzzbl1nQLyTeg/+aTwraLQFKOM9QfEfsR4ce4h IgkOKVTekBJ6b7NUcgZP2CnJ2fncNm3B9AA//8mUjzFgUQV+ST5jwpue44c/y25d sUVpC2h7rh9uH3Stc9IlECudAihLrkQLxr+L2hvMqUu+F/86yjA= =OD+V -----END PGP SIGNATURE----- --nextPart2606459.3l26UXsCK9--