From nobody Thu Sep 18 01:17:57 2025 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id D4D6BC4332F for ; Mon, 12 Dec 2022 21:05:05 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S233489AbiLLVFD (ORCPT ); Mon, 12 Dec 2022 16:05:03 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:41938 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S233479AbiLLVEk (ORCPT ); Mon, 12 Dec 2022 16:04:40 -0500 Received: from smtp.smtpout.orange.fr (smtp-23.smtpout.orange.fr [80.12.242.23]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 860DB192AC for ; Mon, 12 Dec 2022 13:03:13 -0800 (PST) Received: from pop-os.home ([86.243.100.34]) by smtp.orange.fr with ESMTPA id 4px6pWxRHfRXa4px6p0kgM; Mon, 12 Dec 2022 22:03:10 +0100 X-ME-Helo: pop-os.home X-ME-Auth: Y2hyaXN0b3BoZS5qYWlsbGV0QHdhbmFkb28uZnI= X-ME-Date: Mon, 12 Dec 2022 22:03:10 +0100 X-ME-IP: 86.243.100.34 From: Christophe JAILLET To: "David S. Miller" , Eric Dumazet , Jakub Kicinski , Paolo Abeni , Jacob Keller Cc: linux-kernel@vger.kernel.org, kernel-janitors@vger.kernel.org, Christophe JAILLET , netdev@vger.kernel.org Subject: [PATCH net] genetlink: Fix an error handling path in ctrl_dumppolicy_start() Date: Mon, 12 Dec 2022 22:03:06 +0100 Message-Id: <7186dae6d951495f6918c45f8250e6407d71e88f.1670878949.git.christophe.jaillet@wanadoo.fr> X-Mailer: git-send-email 2.34.1 MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Content-Type: text/plain; charset="utf-8" If this memory allocation fails, some resources need to be freed. Add the missing goto to the error handling path. Fixes: b502b3185cd6 ("genetlink: use iterator in the op to policy map dumpi= ng") Signed-off-by: Christophe JAILLET --- This patch is speculative. This function is a callback and I don't know how the core works and handles such situation, so review with care! More-over, should this kmalloc() be a kzalloc()? genl_op_iter_init() below does not initialize all fields, be they are maybe set correctly before uses. --- net/netlink/genetlink.c | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/net/netlink/genetlink.c b/net/netlink/genetlink.c index 600993c80050..7b9f04bd85a2 100644 --- a/net/netlink/genetlink.c +++ b/net/netlink/genetlink.c @@ -1451,8 +1451,10 @@ static int ctrl_dumppolicy_start(struct netlink_call= back *cb) } =20 ctx->op_iter =3D kmalloc(sizeof(*ctx->op_iter), GFP_KERNEL); - if (!ctx->op_iter) - return -ENOMEM; + if (!ctx->op_iter) { + err =3D -ENOMEM; + goto err_free_state; + } =20 genl_op_iter_init(rt, ctx->op_iter); ctx->dump_map =3D genl_op_iter_next(ctx->op_iter); --=20 2.34.1