Received: by 2002:a05:6358:d09b:b0:dc:cd0c:909e with SMTP id jc27csp7334631rwb; Mon, 12 Dec 2022 13:16:51 -0800 (PST) X-Google-Smtp-Source: AA0mqf4/3bp7tNiNfaAaK/ATWan2Km/sHJxz0qrIX2G6KzLQY6W/baIA11JF0bpH1sixG7PDf0qC X-Received: by 2002:a17:906:a148:b0:7af:bc9:5e51 with SMTP id bu8-20020a170906a14800b007af0bc95e51mr15822675ejb.41.1670879810970; Mon, 12 Dec 2022 13:16:50 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1670879810; cv=none; d=google.com; s=arc-20160816; b=uZr9OJiLUB10PsNp2u58An+wLKdkcRfGcEFk4Xtaa8WJ0bZ+7ZStDqjenb81CJxh0S 1Ud66i0h9s5p5UO47eOczklpkO97NtfL7LMm60WyF8uZ8h6nBBT71TP9OBZoFQyFErPM /bJAvhoMq016R83fZTZCPpmQkiSn15MDYTl8pOVn1jra0pI/y8kThBw6U09OnaVLonEA 7cWYbjmYt8JkO2xHJzt4Qer0IrsyEhIdc5XeTcRhxmYP/3/bF+5fwFwOLYhqy5L+TbPG 2VvuNB45qHRcLcFzAsgbZBxvOfofls1Q8EhCby1H10wF0QbsQgadFQUVyhXLPhy51h4G s86w== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :message-id:date:subject:cc:to:from; bh=4x+w5uqY6SNtLvnFDiNrZm7FcWjNR3yj1jwDNThfcIE=; b=YDxCDgvlNXXRFrOrIdJx4NMW7yyZmco0uVAAI3CxSxD0NI+WWpXdT2QndQ8/s0qIIl E+g3hiOyeVgen3/DuBMNPOkuvP3fMa3pIaLQ9DaKhDsPHAhnZ94vy4ObigjoAVTSSdb+ ETsntRlgTadbOVzBF5Hg9iWVjsvzqhcx8p/fn8mJoE2k4NewxXuPNnIkkp5cO576D5gC oAoWeEHg2s05eW8yAfQt5OtSCxXJ16Bns5UMWZBW1UX5MBb/WeGKGCc/IC69do8yBqih SBUL9cDyhYfDhHM2NdIdqOjncplTxuKnKMbzOMMjukMRyt3v0G6u0D4sfRobeYCtNX3J lDow== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Return-Path: Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id cw26-20020a056402229a00b0046abb9e43a8si7737464edb.321.2022.12.12.13.16.32; Mon, 12 Dec 2022 13:16:50 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) client-ip=2620:137:e000::1:20; Authentication-Results: mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S233142AbiLLVFC (ORCPT + 75 others); Mon, 12 Dec 2022 16:05:02 -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: 8bit X-Spam-Status: No, score=-1.9 required=5.0 tests=BAYES_00,RCVD_IN_DNSWL_NONE, RCVD_IN_MSPIKE_H2,SPF_HELO_PASS,SPF_PASS autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org 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 dumping") 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_callback *cb) } ctx->op_iter = kmalloc(sizeof(*ctx->op_iter), GFP_KERNEL); - if (!ctx->op_iter) - return -ENOMEM; + if (!ctx->op_iter) { + err = -ENOMEM; + goto err_free_state; + } genl_op_iter_init(rt, ctx->op_iter); ctx->dump_map = genl_op_iter_next(ctx->op_iter); -- 2.34.1