mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
From: David Howells <dhowells@redhat.com>
To: Dmitry Kasatkin <d.kasatkin@samsung.com>
Cc: dhowells@redhat.com, rusty@rustcorp.com.au, mmarek@suse.cz,
	keyrings@linux-nfs.org, linux-kernel@vger.kernel.org,
	linux-security-module@vger.kernel.org, zohar@linux.vnet.ibm.com
Subject: Re: [PATCH 4/5] MODSIGN: Provide a utility to append a PKCS#7 signature to a module [ver #2]
Date: Thu, 11 Dec 2014 16:41:19 +0000	[thread overview]
Message-ID: <10249.1418316079@warthog.procyon.org.uk> (raw)
In-Reply-To: <548172DE.9090007@samsung.com>

Dmitry Kasatkin <d.kasatkin@samsung.com> wrote:

> sign-file.c produce lots of annoying noise.

Compiling it manually with -Wformat-security found those problems you listed
and add -W found yet another problem.  Differential patch attached.  I've
folded it into the patch that adds sign-file.c.

David
---
diff --git a/scripts/sign-file.c b/scripts/sign-file.c
index 3f9bedbd185f..7941f499ddba 100755
--- a/scripts/sign-file.c
+++ b/scripts/sign-file.c
@@ -62,12 +62,12 @@ static void display_openssl_errors(int l)
 }
 
 
-#define ERR(cond, ...)				  \
+#define ERR(cond, fmt, ...)			  \
 	do {					  \
 		bool __cond = (cond);		  \
 		display_openssl_errors(__LINE__); \
 		if (__cond) {			  \
-			err(1, ## __VA_ARGS__);	  \
+			err(1, fmt, ## __VA_ARGS__);	\
 		}				  \
 	} while(0)
 
@@ -133,7 +133,7 @@ int main(int argc, char **argv)
 	 * across as we read it.
 	 */
 	bd = BIO_new_file(dest_name, "wb");
-	ERR(!bd, dest_name);
+	ERR(!bd, "%s", dest_name);
 
 	/* Digest the module data. */
 	OpenSSL_add_all_digests();
@@ -149,7 +149,7 @@ int main(int argc, char **argv)
 			   PKCS7_NOCERTS | PKCS7_PARTIAL | PKCS7_BINARY | PKCS7_DETACHED | PKCS7_STREAM);
 	ERR(!pkcs7, "PKCS7_sign");
 
-	ERR(PKCS7_sign_add_signer(pkcs7, x509, private_key, digest_algo, PKCS7_NOCERTS | PKCS7_BINARY) < 0,
+	ERR(!PKCS7_sign_add_signer(pkcs7, x509, private_key, digest_algo, PKCS7_NOCERTS | PKCS7_BINARY),
 	    "PKCS7_sign_add_signer");
 	ERR(PKCS7_final(pkcs7, bm, PKCS7_NOCERTS | PKCS7_BINARY) < 0,
 	    "PKCS7_final");
@@ -159,31 +159,31 @@ int main(int argc, char **argv)
 
 		ERR(asprintf(&pkcs7_name, "%s.pkcs7", module_name) < 0, "asprintf");
 		b = BIO_new_file(pkcs7_name, "wb");
-		ERR(!b, pkcs7_name);
-		ERR(i2d_PKCS7_bio_stream(b, pkcs7, NULL, 0) < 0, pkcs7_name);
+		ERR(!b, "%s", pkcs7_name);
+		ERR(i2d_PKCS7_bio_stream(b, pkcs7, NULL, 0) < 0, "%s", pkcs7_name);
 		BIO_free(b);
 	}
 
 	/* Append the marker and the PKCS#7 message to the destination file */
-	ERR(BIO_reset(bm) < 0, module_name);
+	ERR(BIO_reset(bm) < 0, "%s", module_name);
 	while ((n = BIO_read(bm, buf, sizeof(buf))),
 	       n > 0) {
-		ERR(BIO_write(bd, buf, n) < 0, dest_name);
+		ERR(BIO_write(bd, buf, n) < 0, "%s", dest_name);
 	}
-	ERR(n < 0, module_name);
+	ERR(n < 0, "%s", module_name);
 	module_size = BIO_number_written(bd);
 
-	ERR(i2d_PKCS7_bio_stream(bd, pkcs7, NULL, 0) < 0, dest_name);
+	ERR(i2d_PKCS7_bio_stream(bd, pkcs7, NULL, 0) < 0, "%s", dest_name);
 	pkcs7_size = BIO_number_written(bd) - module_size;
 	sig_info.sig_len = htonl(pkcs7_size);
-	ERR(BIO_write(bd, &sig_info, sizeof(sig_info)) < 0, dest_name);
-	ERR(BIO_write(bd, magic_number, sizeof(magic_number) - 1) < 0, dest_name);
+	ERR(BIO_write(bd, &sig_info, sizeof(sig_info)) < 0, "%s", dest_name);
+	ERR(BIO_write(bd, magic_number, sizeof(magic_number) - 1) < 0, "%s", dest_name);
 
-	ERR(BIO_free(bd) < 0, dest_name);
+	ERR(BIO_free(bd) < 0, "%s", dest_name);
 
 	/* Finally, if we're signing in place, replace the original. */
 	if (replace_orig)
-		ERR(rename(dest_name, module_name) < 0, dest_name);
+		ERR(rename(dest_name, module_name) < 0, "%s", dest_name);
 
 	return 0;
 }

  parent reply	other threads:[~2014-12-11 16:41 UTC|newest]

Thread overview: 16+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2014-11-26 14:17 [PATCH 0/5] MODSIGN: Use PKCS#7 for module signatures " David Howells
2014-11-26 14:17 ` [PATCH 1/5] X.509: Extract both parts of the AuthorityKeyIdentifier " David Howells
2014-12-04 12:14   ` Dmitry Kasatkin
2014-12-04 12:51   ` David Howells
2014-11-26 14:17 ` [PATCH 2/5] X.509: Support X.509 lookup by Issuer+Serial form " David Howells
2014-11-26 14:17 ` [PATCH 3/5] PKCS#7: Allow detached data to be supplied for signature checking purposes " David Howells
2014-11-26 14:17 ` [PATCH 4/5] MODSIGN: Provide a utility to append a PKCS#7 signature to a module " David Howells
2014-12-05  8:54   ` Dmitry Kasatkin
2014-12-05 10:23   ` David Howells
2014-12-05 12:47     ` Dmitry Kasatkin
2014-12-05 12:49       ` Dmitry Kasatkin
2014-12-05 14:04     ` David Howells
2014-12-05 14:37       ` Dmitry Kasatkin
2014-12-11 16:41   ` David Howells [this message]
2014-11-26 14:18 ` [PATCH 5/5] MODSIGN: Use PKCS#7 messages as module signatures " David Howells
2014-12-04 18:56 ` [PATCH 0/5] MODSIGN: Use PKCS#7 for " Vivek Goyal

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=10249.1418316079@warthog.procyon.org.uk \
    --to=dhowells@redhat.com \
    --cc=d.kasatkin@samsung.com \
    --cc=keyrings@linux-nfs.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux-security-module@vger.kernel.org \
    --cc=mmarek@suse.cz \
    --cc=rusty@rustcorp.com.au \
    --cc=zohar@linux.vnet.ibm.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

Powered by JetHome