From patchwork Thu Feb 1 11:07:55 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Simon Wunderlich X-Patchwork-Id: 18633 X-Patchwork-Delegate: sw@simonwunderlich.de Return-Path: X-Original-To: patchwork@open-mesh.org Delivered-To: patchwork@open-mesh.org Received: from diktynna.open-mesh.org (localhost [IPv6:::1]) by diktynna.open-mesh.org (Postfix) with ESMTP id A02E9844A0 for ; Thu, 1 Feb 2024 12:10:39 +0100 (CET) ARC-Seal: i=2; cv=pass; a=rsa-sha256; d=open-mesh.org; s=20121; t=1706785839; b=zzV08UB/sG4tp9wXLbmg56sTHBGAY64EHK3ZVWEdy2gmj5oqwq0Aax5nIC5y91mrZinNp 9rBivn9E02WZnEmPId1R4GFqVE7SQfzZkNttlcw8s+k3NPgRwbDWGXCpF6jL6ugTZhvu7Zk VaKVSDhq6ug31RyiSyiL4+LDBxkVBZ4= ARC-Message-Signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=open-mesh.org; s=20121; t=1706785839; h=from : sender : reply-to : subject : date : message-id : to : cc : mime-version : content-type : content-transfer-encoding : content-id : content-description : resent-date : resent-from : resent-sender : resent-to : resent-cc : resent-message-id : in-reply-to : references : list-id : list-help : list-unsubscribe : list-subscribe : list-post : list-owner : list-archive; bh=/3lHsh112Rhgr3F7kK+hW2dW58kE9t3CmWFBOkwXXx0=; b=QdAcHSTahD6s1SoFyghuMljOx7Hk4HnjgZiiXo8PTqHOSLNRX+ekCBIQjgOunvHOKSgss ATQm16csXwGSQ9vZi4NClfybfyS7oxNjmOaM3J/BO8MqJLTX0aMvMwZrrd51/Dq1/LkADYM FmeSXmiZWo11WUHKnZoZdrFUt0ubGi8= ARC-Authentication-Results: i=2; open-mesh.org; dkim=fail; arc=pass; dmarc=fail (Used From Domain Record) header.from=simonwunderlich.de policy.dmarc=none Authentication-Results: open-mesh.org; dkim=fail; arc=pass; dmarc=fail (Used From Domain Record) header.from=simonwunderlich.de policy.dmarc=none Received: from mail.simonwunderlich.de (mail.simonwunderlich.de [23.88.38.48]) by diktynna.open-mesh.org (Postfix) with ESMTPS id 8ECCE8342A for ; Thu, 1 Feb 2024 12:08:00 +0100 (CET) ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=open-mesh.org; s=20121; t=1706785680; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=/3lHsh112Rhgr3F7kK+hW2dW58kE9t3CmWFBOkwXXx0=; b=nM9Sev6SxtD5oygFtGBshfuMvaUBeLAUxHttSzrmWTsYZhb+zJU1fCi+JHKWKPUu/POz2K b2DRgslKgaAu2m+App8afi6+81zLp3d/mqfO/SLKFGn3/oPZeFNg0uob+xyvqO6srj4D+h oMVjCKJfFJ/pCQQWquHAx49qvcSZyEk= ARC-Authentication-Results: i=1; diktynna.open-mesh.org; dkim=none; spf=pass (diktynna.open-mesh.org: domain of sw@simonwunderlich.de designates 23.88.38.48 as permitted sender) smtp.mailfrom=sw@simonwunderlich.de; dmarc=pass (policy=none) header.from=simonwunderlich.de ARC-Seal: i=1; s=20121; d=open-mesh.org; t=1706785680; a=rsa-sha256; cv=none; b=N9c+29rJx3Zsux6xYmxOFgGdbqXhmiBvSKTGe9ZXRGscegEdPCEdXCDJLJb1E8H4mzqZRH 2FLynqyBB11FL+XNDMqvxEFEq3i+uqTzri6XphaP0jSH1Q3diKmMTrOySxMZ1DjMWG5/gU hARYMWSW29f3Ia8i6aSvfilqMoyP9v0= Received: from kero.packetmixer.de (p200300C59712c7D8d89318FB9D63b559.dip0.t-ipconnect.de [IPv6:2003:c5:9712:c7d8:d893:18fb:9d63:b559]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange ECDHE (P-256) server-signature RSA-PSS (2048 bits) server-digest SHA256) (No client certificate requested) by mail.simonwunderlich.de (Postfix) with ESMTPSA id 583FDFA9B5; Thu, 1 Feb 2024 12:08:00 +0100 (CET) From: Simon Wunderlich To: kuba@kernel.org, davem@davemloft.net Cc: netdev@vger.kernel.org, b.a.t.m.a.n@lists.open-mesh.org, Markus Elfring , Sven Eckelmann , Simon Wunderlich Subject: [PATCH 3/4] batman-adv: Improve exception handling in batadv_throw_uevent() Date: Thu, 1 Feb 2024 12:07:55 +0100 Message-Id: <20240201110756.29728-4-sw@simonwunderlich.de> X-Mailer: git-send-email 2.39.2 In-Reply-To: <20240201110756.29728-1-sw@simonwunderlich.de> References: <20240201110756.29728-1-sw@simonwunderlich.de> MIME-Version: 1.0 Message-ID-Hash: XI4OMJ7WZ3CGVDOJI2IAN6SO4C5O2A73 X-Message-ID-Hash: XI4OMJ7WZ3CGVDOJI2IAN6SO4C5O2A73 X-MailFrom: sw@simonwunderlich.de X-Mailman-Rule-Misses: dmarc-mitigation; no-senders; approved; emergency; loop; banned-address; member-moderation; header-match-b.a.t.m.a.n.lists.open-mesh.org-0; header-match-b.a.t.m.a.n.lists.open-mesh.org-1; header-match-b.a.t.m.a.n.lists.open-mesh.org-2; nonmember-moderation; administrivia; implicit-dest; max-recipients; max-size; news-moderation; no-subject; digests; suspicious-header X-Mailman-Version: 3.3.8 Precedence: list List-Id: The list for a Better Approach To Mobile Ad-hoc Networking Archived-At: List-Archive: List-Help: List-Owner: List-Post: List-Subscribe: List-Unsubscribe: From: Markus Elfring 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 Signed-off-by: Simon Wunderlich --- net/batman-adv/main.c | 14 ++++++++------ 1 file changed, 8 insertions(+), 6 deletions(-) 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],