From patchwork Tue Jan 2 07:11:47 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Markus Elfring X-Patchwork-Id: 13508871 X-Patchwork-Delegate: kuba@kernel.org Received: from mout.web.de (mout.web.de [212.227.15.4]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 47A2120F5; Tue, 2 Jan 2024 07:12:02 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=quarantine dis=none) header.from=web.de Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=web.de Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=web.de header.i=markus.elfring@web.de header.b="Y8f7sCRQ" DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=web.de; s=s29768273; t=1704179508; x=1704784308; i=markus.elfring@web.de; bh=V53RxSn45Of6qQKpHmIQL7d5i6Uj4RYbOSBA1Ek79pU=; h=X-UI-Sender-Class:Date:Subject:From:To:Cc:References: In-Reply-To; b=Y8f7sCRQHnrSUdosDFxS7ot/bgBH4fRzW+edTj2Ya0s4eJKETS06OuQFjf7aYoY5 RwVHcX4dIh7xJRUb9cGo3OgGqV46IPVQfixd2PYq/N52LTPytLbyeewmy/tmEBBfs Hy0PYVJm+9jKzkOy2cKbLgrpBiWRsOgcNLJDGNi5YYqpS3l7coJRx8M91eoWp8CmY 1Nt69XT7zF147mUKcgzg0qSotRbO7shjJ3R2NNwUk155W1DNDQvshJ4ftuxtlpQLJ t65y1QjpiaNln8eIwa5dOVWA1v142PPfzzPOf/q1NVq9UBsM5ptZWMU2P5knZ1dBk FP1FGDaxcMdSTmirzA== X-UI-Sender-Class: 814a7b36-bfc1-4dae-8640-3722d8ec6cd6 Received: from [192.168.178.21] ([94.31.91.95]) by smtp.web.de (mrweb006 [213.165.67.108]) with ESMTPSA (Nemesis) id 1Mt8gP-1r4pPG3DJJ-00t5Ck; Tue, 02 Jan 2024 08:11:47 +0100 Message-ID: <54dc53f8-5f08-4f1d-938a-c845c8ec0d44@web.de> Date: Tue, 2 Jan 2024 08:11:47 +0100 Precedence: bulk X-Mailing-List: netdev@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 User-Agent: Mozilla Thunderbird Subject: [PATCH 1/2] batman-adv: Return directly after a failed batadv_dat_select_candidates() in batadv_dat_forward_data() Content-Language: en-GB From: Markus Elfring To: b.a.t.m.a.n@lists.open-mesh.org, netdev@vger.kernel.org, kernel-janitors@vger.kernel.org, Antonio Quartulli , "David S. Miller" , Eric Dumazet , Jakub Kicinski , Marek Lindner , Paolo Abeni , Simon Wunderlich , Sven Eckelmann Cc: LKML References: <8588cafe-3c61-40a6-b071-0877632a2a1e@web.de> In-Reply-To: <8588cafe-3c61-40a6-b071-0877632a2a1e@web.de> X-Provags-ID: V03:K1:Aa/rztWe/OKkxjpDmxNoqQjPyzaHKv8xKPJ8QBGSYir2aUs9wDc hAx5dt+2EqvulF6HrKiKtryVzbaltQ3ZrIogjp1ELjbso1QJMUZ6EjRpYtjHBUYbATrGe5e E0y8IJ0zU9v56pDAb3zvFfiJp0gmJ6B5ZU4w+4iWUez1RO9OaHOKoNcLjA8i0HBzqJfYE2T sJX/sMP4LrFkGxdZpK6Eg== X-Spam-Flag: NO UI-OutboundReport: notjunk:1;M01:P0:7mrs2rexnTs=;nQXkY8Kc5fVXWDIu+nDG+pagpaJ 1wDztkHmrGcwFFlSV2v0MG24Bi9GNBh9mlg91AOZ59UEeM+AlMF0mKHG2cjNwX3Tt/U/OeQb8 vHHTFSLrVMh1DerU3CnmJ/3pQqcZkKJEaZyhnK5nRzRhJrfw37HP9PUJ8jprDAxWZb2bny1ZF B6L8LkmXGIEaOE2JO9xwNnubZq9xFVNyqeKDybT3gNaUJZNpiQqCwf53fuGXnUoXlxmHb9ipP ONwVWKMccpIi0Ug/PlUSiSVRsOM/pnKEbTqiZOQtVsLou0PySCkC1RMqLpXb2zXNkO0u13X0P wYrYWffNGr31GDYUxxsSzkfHywWy1aYrf4oXbnF5OuS6Z1wC0zvXbEoB0YGsyuCTtiYVZxxqW U7Owm6MYRYUrgQkfrDGLvDtbU31sLM7F+qMnUDN7o4DQbonULYDiFjQ/qlyKueAfHdcC9nkFV XbgmgC5YpDcyFGGm9sjBnc2oKrZAyf/DCqJ5Img6bWZxdXusdD3iRrYfO7oCbcAIJBEZ9CdJK ecyjERhAIeVwcrd4l8wzgqm1aq9qiRUz16/KKWAm060P1eBh0DEQ7D8DnXp+6iqyPHKKF2ISA esNU4/gjIG/FrfmGqLeikkr995V2mxavAYZrwoROp8NurE/YinQUjQuj1vdcTs62unLREa5uf xIlvn2prnccrwkyolxXi0bJEx7NBPir6BLrihcjr1RoWypNb73HXBen3uQOgw8nDDXJ0tX6Xa NfIIUQyIGncHXDzjEElrDRa3OAtvJtb8j8Da69Fe+EpatZUzVZijfOE+4RsUNJi4Bt/q5SthS fFxd9pQDze4uq1MJ7hTR8hMttH4XNzMbB4mCMJHJcwLH2cSBWVEa2eeQw8y4/03IUGo8hSKGB jasLYy632feg672vjfXxU1WuFKmLW3b2HftvYP1OpmtlOvf5sE9argmp9L7W1shC137gYaGK2 8XvEww== X-Patchwork-Delegate: kuba@kernel.org From: Markus Elfring Date: Tue, 2 Jan 2024 07:27:45 +0100 The kfree() function was called in one case by the batadv_dat_forward_data() function during error handling even if the passed variable contained a null pointer. This issue was detected by using the Coccinelle software. * Thus return directly after a batadv_dat_select_candidates() call failed at the beginning. * Delete the label “out” which became unnecessary with this refactoring. Signed-off-by: Markus Elfring Acked-by: Sven Eckelmann --- net/batman-adv/distributed-arp-table.c | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) -- 2.43.0 diff --git a/net/batman-adv/distributed-arp-table.c b/net/batman-adv/distributed-arp-table.c index 28a939d56090..4c7e85534324 100644 --- a/net/batman-adv/distributed-arp-table.c +++ b/net/batman-adv/distributed-arp-table.c @@ -684,7 +684,7 @@ static bool batadv_dat_forward_data(struct batadv_priv *bat_priv, cand = batadv_dat_select_candidates(bat_priv, ip, vid); if (!cand) - goto out; + return ret; batadv_dbg(BATADV_DBG_DAT, bat_priv, "DHT_SEND for %pI4\n", &ip); @@ -728,7 +728,6 @@ static bool batadv_dat_forward_data(struct batadv_priv *bat_priv, batadv_orig_node_put(cand[i].orig_node); } -out: kfree(cand); return ret; } From patchwork Tue Jan 2 07:12:56 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Markus Elfring X-Patchwork-Id: 13508872 X-Patchwork-Delegate: kuba@kernel.org Received: from mout.web.de (mout.web.de [212.227.15.14]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 1C94D20F9; Tue, 2 Jan 2024 07:13:12 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=quarantine dis=none) header.from=web.de Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=web.de Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=web.de header.i=markus.elfring@web.de header.b="Y2CkeGTg" DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=web.de; s=s29768273; t=1704179577; x=1704784377; i=markus.elfring@web.de; bh=BzfHfM8ElsvZex/Uect+kFopl0XLqwkwH+F+arwONTs=; h=X-UI-Sender-Class:Date:Subject:From:To:Cc:References: In-Reply-To; b=Y2CkeGTgDSesaLttaMthQObZ1uW4skPAqChG/k58SisrwhJ/RnSaAcPeMc7wTmrL 2Wwu7w6+jSTJJ/b5R32ky01lqPjtcnrUVXuGM4npTKjVIIrEV79eymRjXGkNBR7lO 2tBeeuAqYG/vBbU4xDmBJOGRT/Eh5ynZu0uWqTwd5rrgzCikNFOzSxWgbklyp1zTB BTmDtQqM3rESmQDrsF21D7mUnTRM5OngLmNx1cjZGvA8tU7KVhYsiEd6OlnAb3kSJ A7WekoInu6+ic136epG3LhxdzLSW9A2T0ILFVXcuUSDR+y0gA9cxbwdQk7YP8Gj4F B0IFC6Bw79JJUN91Dg== X-UI-Sender-Class: 814a7b36-bfc1-4dae-8640-3722d8ec6cd6 Received: from [192.168.178.21] ([94.31.91.95]) by smtp.web.de (mrweb006 [213.165.67.108]) with ESMTPSA (Nemesis) id 1MumJD-1r24Ec1OQV-00rRZw; Tue, 02 Jan 2024 08:12:57 +0100 Message-ID: Date: Tue, 2 Jan 2024 08:12:56 +0100 Precedence: bulk X-Mailing-List: netdev@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 User-Agent: Mozilla Thunderbird Subject: [PATCH 2/2] batman-adv: Improve exception handling in batadv_throw_uevent() Content-Language: en-GB From: Markus Elfring To: b.a.t.m.a.n@lists.open-mesh.org, netdev@vger.kernel.org, kernel-janitors@vger.kernel.org, Antonio Quartulli , "David S. Miller" , Eric Dumazet , Jakub Kicinski , Marek Lindner , Paolo Abeni , Simon Wunderlich , Sven Eckelmann Cc: LKML References: <8588cafe-3c61-40a6-b071-0877632a2a1e@web.de> In-Reply-To: <8588cafe-3c61-40a6-b071-0877632a2a1e@web.de> X-Provags-ID: V03:K1:X8tI5V2tYneXOsAvm6L5iObE7FR3QlCz66qzzSaWxhd2o876S7p 8qtEp1ZdHpHXIUIl/sGZ7gk5ZChmppeDJ2SCctoTwAhiA/p/RGgAzWLQOUFo95dSBxDj5MM fwp/6Psyok7/zLxcCxvSFSKQHwhal0M5PRT+KHgeO1uGX5J1tao8rfEbdMy+ATuGV3Q96nq VnVOYEyfPH8Id8tdczjyQ== X-Spam-Flag: NO UI-OutboundReport: notjunk:1;M01:P0:k1BY0oVzLbo=;Dvl3Si46wFYS3jSy7Kllf1tk0wQ Lg7A3i+fI2SSage3Fbl1/cQseWp/3tjxhcwh4Kptz69UwP0hnVrVHSEyXRcgbKvfrak0dXSbl iEx7cXE5+H9Izm+4gvFSzkkFj4FQ8ujDwRta6apTsKLM5bhs7zLXIh+Rze8wk9w/Uz9rwbsXH VJ2w0oDJ3TLC9qfHkQw+oVkRk+XT24xqtdp6z/QYRJ5GGhc7AG95AXmzugDcHAgt5FE7gvi8U +n+d+FJTwXRDKFru7KzGpoD3ZALgzoTodQACOtl0YrJHsIxR0ckFh7qUAuiq3UI+WiXsQMzC3 dUZ+20rVwnp2RnlGkfAz5iVdcgTFTvweVInL+BVq8zrwZIzBhR9+C66a9Apz9afPImHW/I99R ouJ70dqvRkeI6yFw5sbWlnZMwdJR6BruTydV3lMlW29hVCSjjG1rQLUohlGt64/r93CLsVeSR KGUrnLLPEedbWG8C4tDA0r3eMj5lw6JzqpomgOvRwht4c4L4Zxuef+OQso3dHKIPwd7wlIfw0 WCCEVqXgOdUqUV+pJLt5DeCLvxHxfY6fCHKUXs5u+gW/iI8GSnXP5mGomXC2FhJdiwkbkqDWA Uc2aUziM3b9TG1mhBbhSxHQ2r29G+5n5y1FMkSBJuCipylQmSvu2UeFhvSvZylqe4GY7M4BdH 7gN4OE6j6NKYBlIba/1N0rloGAJp5S6vAHSX3U/lHOhwxtot6OiSt1M6BZUIi5SJg27bu1n/m PAhY8EfKWH0txytOOar/ub/lN27IiiWckJAjsk9da+gM9uMZpJa+RYNS5gzFNhmYIgd4R8wts CP8lj3mqdUbe17ph+Oe7/dPhU60dGKA0Cz9QmJrRJ88OHn4n81OOu/siEigIBR6W0pyKomEuC +KA9nffLt6EW7RXFtPP9j3+TzcpdUsnGYwM6HOGBxzAh2GPBbLWVr48LF7dnkPqX4/YBweJdu g5bIpQ== X-Patchwork-Delegate: kuba@kernel.org From: Markus Elfring Date: Tue, 2 Jan 2024 07:52:21 +0100 The kfree() function was called in up to three cases by the batadv_throw_uevent() function during error handling even if the passed variable contained a null pointer. This issue was detected by using the Coccinelle software. * Thus adjust jump targets. * Reorder kfree() calls at the end. Signed-off-by: Markus Elfring Acked-by: Sven Eckelmann --- net/batman-adv/main.c | 14 ++++++++------ 1 file changed, 8 insertions(+), 6 deletions(-) -- 2.43.0 diff --git a/net/batman-adv/main.c b/net/batman-adv/main.c index 5fc754b0b3f7..75119f1ffccc 100644 --- a/net/batman-adv/main.c +++ b/net/batman-adv/main.c @@ -691,29 +691,31 @@ int batadv_throw_uevent(struct batadv_priv *bat_priv, enum batadv_uev_type type, "%s%s", BATADV_UEV_TYPE_VAR, batadv_uev_type_str[type]); if (!uevent_env[0]) - goto out; + goto report_error; uevent_env[1] = kasprintf(GFP_ATOMIC, "%s%s", BATADV_UEV_ACTION_VAR, batadv_uev_action_str[action]); if (!uevent_env[1]) - goto out; + goto free_first_env; /* If the event is DEL, ignore the data field */ if (action != BATADV_UEV_DEL) { uevent_env[2] = kasprintf(GFP_ATOMIC, "%s%s", BATADV_UEV_DATA_VAR, data); if (!uevent_env[2]) - goto out; + goto free_second_env; } ret = kobject_uevent_env(bat_kobj, KOBJ_CHANGE, uevent_env); -out: - kfree(uevent_env[0]); - kfree(uevent_env[1]); kfree(uevent_env[2]); +free_second_env: + kfree(uevent_env[1]); +free_first_env: + kfree(uevent_env[0]); if (ret) +report_error: batadv_dbg(BATADV_DBG_BATMAN, bat_priv, "Impossible to send uevent for (%s,%s,%s) event (err: %d)\n", batadv_uev_type_str[type],