From patchwork Fri Dec 11 18:53:02 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Andrea Claudi X-Patchwork-Id: 11969407 X-Patchwork-Delegate: stephen@networkplumber.org Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-15.8 required=3.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,HEADER_FROM_DIFFERENT_DOMAINS, INCLUDES_CR_TRAILER,INCLUDES_PATCH,MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS autolearn=ham autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 51475C4361B for ; Fri, 11 Dec 2020 20:40:07 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 0307523BCD for ; Fri, 11 Dec 2020 20:40:06 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S2389604AbgLKSz1 (ORCPT ); Fri, 11 Dec 2020 13:55:27 -0500 Received: from us-smtp-delivery-124.mimecast.com ([216.205.24.124]:23140 "EHLO us-smtp-delivery-124.mimecast.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S2389428AbgLKSyr (ORCPT ); Fri, 11 Dec 2020 13:54:47 -0500 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1607712801; 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=qvLV71yDCCqHXyaS6wZyntv25eF4ZCINFLjbVMSSzrc=; b=MLaqgi3p7KaDAE14CQUk76h2i/IEkAagrzOn+mjDqhWe0vN96lHOR2lF9LWiP0IMVX+71r 6POfssiJB8SKvPKoXrsvJtBf/FthvflbE9mWZePFQRpvnC2WDnCLz59AsEmKhDZ8oTHbQY w0a7IrkXBnJ+LoEVciIFg7FZmykALdU= Received: from mimecast-mx01.redhat.com (mimecast-mx01.redhat.com [209.132.183.4]) (Using TLS) by relay.mimecast.com with ESMTP id us-mta-421-BGWJncqKPyWCHHoLEOaeTg-1; Fri, 11 Dec 2020 13:53:18 -0500 X-MC-Unique: BGWJncqKPyWCHHoLEOaeTg-1 Received: from smtp.corp.redhat.com (int-mx02.intmail.prod.int.phx2.redhat.com [10.5.11.12]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx01.redhat.com (Postfix) with ESMTPS id 9A29B19251A0; Fri, 11 Dec 2020 18:53:17 +0000 (UTC) Received: from localhost.localdomain.com (ovpn-114-11.ams2.redhat.com [10.36.114.11]) by smtp.corp.redhat.com (Postfix) with ESMTP id BEE1560BE5; Fri, 11 Dec 2020 18:53:16 +0000 (UTC) From: Andrea Claudi To: netdev@vger.kernel.org Cc: stephen@networkplumber.org, dsahern@gmail.com Subject: [PATCH iproute2 1/2] devlink: fix memory leak in cmd_dev_flash() Date: Fri, 11 Dec 2020 19:53:02 +0100 Message-Id: <0552db30b97ec8db87d82ef5d6def490510ce6aa.1607712061.git.aclaudi@redhat.com> In-Reply-To: References: MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.79 on 10.5.11.12 Precedence: bulk List-ID: X-Mailing-List: netdev@vger.kernel.org X-Patchwork-Delegate: dsahern@gmail.com nlg_ntf is dinamically allocated in mnlg_socket_open(), and is freed on the out: return path. However, some error paths do not free it, resulting in memory leak. This commit fix this using mnlg_socket_close(), and reporting the correct error number when required. Fixes: 9b13cddfe268 ("devlink: implement flash status monitoring") Signed-off-by: Andrea Claudi --- devlink/devlink.c | 13 ++++++++----- 1 file changed, 8 insertions(+), 5 deletions(-) diff --git a/devlink/devlink.c b/devlink/devlink.c index ca99732e..43549965 100644 --- a/devlink/devlink.c +++ b/devlink/devlink.c @@ -3371,19 +3371,21 @@ static int cmd_dev_flash(struct dl *dl) err = _mnlg_socket_group_add(nlg_ntf, DEVLINK_GENL_MCGRP_CONFIG_NAME); if (err) - return err; + goto err_socket; err = pipe(pipe_fds); - if (err == -1) - return -errno; + if (err == -1) { + err = -errno; + goto err_socket; + } pipe_r = pipe_fds[0]; pipe_w = pipe_fds[1]; pid = fork(); if (pid == -1) { - close(pipe_r); close(pipe_w); - return -errno; + err = -errno; + goto out; } else if (!pid) { /* In child, just execute the flash and pass returned * value through pipe once it is done. @@ -3412,6 +3414,7 @@ static int cmd_dev_flash(struct dl *dl) err = _mnlg_socket_recv_run(dl->nlg, NULL, NULL); out: close(pipe_r); +err_socket: mnlg_socket_close(nlg_ntf); return err; } From patchwork Fri Dec 11 18:53:03 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Andrea Claudi X-Patchwork-Id: 11969409 X-Patchwork-Delegate: stephen@networkplumber.org Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-15.8 required=3.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,HEADER_FROM_DIFFERENT_DOMAINS, INCLUDES_CR_TRAILER,INCLUDES_PATCH,MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS autolearn=ham autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id A1852C433FE for ; Fri, 11 Dec 2020 20:40:22 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 5EBB423BCD for ; Fri, 11 Dec 2020 20:40:22 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S2390920AbgLKSzk (ORCPT ); Fri, 11 Dec 2020 13:55:40 -0500 Received: from us-smtp-delivery-124.mimecast.com ([216.205.24.124]:38204 "EHLO us-smtp-delivery-124.mimecast.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S2389455AbgLKSyr (ORCPT ); Fri, 11 Dec 2020 13:54:47 -0500 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1607712802; 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=gYvPlMxgSa/S/NGYqFw1rXj3z3erU+lWixL46UYSdbA=; b=eMU5HrE5wUkxPB6hgdHn1lVU4WW8O8kbIyqAbGkmxUu5l27bN6BC1zOlrzNseO3ZDmlBnf XgzS1RB4eqtaKyPfEdGPCyS1Q0rOOeAHHfRXipdziMPQn30i7biz0mYvY8zbQRXge7bNv0 OsFHBB0aZnOle2Kgk4YHXXMD+2XBDa4= Received: from mimecast-mx01.redhat.com (mimecast-mx01.redhat.com [209.132.183.4]) (Using TLS) by relay.mimecast.com with ESMTP id us-mta-291--c0zgdZ1OOCdzHHM7NUtMA-1; Fri, 11 Dec 2020 13:53:20 -0500 X-MC-Unique: -c0zgdZ1OOCdzHHM7NUtMA-1 Received: from smtp.corp.redhat.com (int-mx02.intmail.prod.int.phx2.redhat.com [10.5.11.12]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx01.redhat.com (Postfix) with ESMTPS id 747B8107ACF7; Fri, 11 Dec 2020 18:53:19 +0000 (UTC) Received: from localhost.localdomain.com (ovpn-114-11.ams2.redhat.com [10.36.114.11]) by smtp.corp.redhat.com (Postfix) with ESMTP id 7E26B60BE5; Fri, 11 Dec 2020 18:53:18 +0000 (UTC) From: Andrea Claudi To: netdev@vger.kernel.org Cc: stephen@networkplumber.org, dsahern@gmail.com Subject: [PATCH iproute2 2/2] tc: pedit: fix memory leak in print_pedit Date: Fri, 11 Dec 2020 19:53:03 +0100 Message-Id: <3045373e80b840cc2c658696af1c6b7fb367c96e.1607712061.git.aclaudi@redhat.com> In-Reply-To: References: MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.79 on 10.5.11.12 Precedence: bulk List-ID: X-Mailing-List: netdev@vger.kernel.org X-Patchwork-Delegate: dsahern@gmail.com keys_ex is dinamically allocated with calloc on line 770, but is not freed in case of error at line 823. Fixes: 081d6c310d3a ("tc: pedit: Support JSON dumping") Signed-off-by: Andrea Claudi --- tc/m_pedit.c | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/tc/m_pedit.c b/tc/m_pedit.c index 51dcf109..aa874408 100644 --- a/tc/m_pedit.c +++ b/tc/m_pedit.c @@ -819,8 +819,10 @@ static int print_pedit(struct action_util *au, FILE *f, struct rtattr *arg) print_uint(PRINT_FP, NULL, "\n\t key #%d at ", i); err = print_pedit_location(f, htype, key->off); - if (err) + if (err) { + free(keys_ex); return err; + } /* In FP, report the "set" command as "val" to keep * backward compatibility. Report the true name in JSON.