nvdimm.lists.linux.dev archive mirror
 help / color / mirror / Atom feed
From: Michal Suchanek <msuchanek@suse.de>
To: linux-nvdimm@lists.01.org
Cc: Michal Suchanek <msuchanek@suse.de>,
	Zhiqiang Liu <liuzhiqiang26@huawei.com>
Subject: [PATCH ndctl] dimm: re-fix potential fd leakage in dimm_action()
Date: Wed,  6 Jan 2021 15:43:43 +0100	[thread overview]
Message-ID: <20210106144343.22099-1-msuchanek@suse.de> (raw)

There are cases not covered by the original fix and cases added by the
latter patch.

Also there is one case of usage added without returning from the
function.

Fixes: ff434d87ccbd ("dimm: fix potential fd leakage in dimm_action()")
Fixes: 41a7e24af5db ("ndctl/dimm: Auto-arm firmware activation")

Signed-off-by: Michal Suchanek <msuchanek@suse.de>
---
 ndctl/dimm.c | 14 ++++++++++----
 1 file changed, 10 insertions(+), 4 deletions(-)

diff --git a/ndctl/dimm.c b/ndctl/dimm.c
index 09ce49e1d2ca..1c177b5494ec 100644
--- a/ndctl/dimm.c
+++ b/ndctl/dimm.c
@@ -1333,12 +1333,15 @@ static int dimm_action(int argc, const char **argv, struct ndctl_ctx *ctx,
 	if (param.arm_set && param.disarm_set) {
 		fprintf(stderr, "set either --arm, or --disarm, not both\n");
 		usage_with_options(u, options);
+		rc = -EINVAL;
+		goto out_close_fout;
 	}
 
 	if (param.disarm_set && !param.disarm) {
 		fprintf(stderr, "--no-disarm syntax not supported\n");
 		usage_with_options(u, options);
-		return -EINVAL;
+		rc = -EINVAL;
+		goto out_close_fout;
 	}
 
 	if (!param.infile) {
@@ -1351,13 +1354,15 @@ static int dimm_action(int argc, const char **argv, struct ndctl_ctx *ctx,
 			if (!param.arm_set && !param.disarm_set) {
 				fprintf(stderr, "require --arm, or --disarm\n");
 				usage_with_options(u, options);
-				return -EINVAL;
+				rc = -EINVAL;
+				goto out_close_fout;
 			}
 
 			if (param.arm_set && !param.arm) {
 				fprintf(stderr, "--no-arm syntax not supported\n");
 				usage_with_options(u, options);
-				return -EINVAL;
+				rc = -EINVAL;
+				goto out_close_fout;
 			}
 		}
 		actx.f_in = stdin;
@@ -1425,7 +1430,8 @@ static int dimm_action(int argc, const char **argv, struct ndctl_ctx *ctx,
 		if (count > 1) {
 			error("write-labels only supports writing a single dimm\n");
 			usage_with_options(u, options);
-			return -EINVAL;
+			rc = -EINVAL;
+			goto out_close_fin_fout;
 		} else if (single)
 			rc = action(single, &actx);
 	}
-- 
2.26.2
_______________________________________________
Linux-nvdimm mailing list -- linux-nvdimm@lists.01.org
To unsubscribe send an email to linux-nvdimm-leave@lists.01.org

             reply	other threads:[~2021-01-06 14:43 UTC|newest]

Thread overview: 2+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2021-01-06 14:43 Michal Suchanek [this message]
2021-02-15 18:15 ` [PATCH ndctl] dimm: re-fix potential fd leakage in dimm_action() Jeff Moyer

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20210106144343.22099-1-msuchanek@suse.de \
    --to=msuchanek@suse.de \
    --cc=linux-nvdimm@lists.01.org \
    --cc=liuzhiqiang26@huawei.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).