linux-crypto.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH] ASN.1: check for error from ASN1_OP_END__ACT actions
@ 2017-11-27  7:15 Eric Biggers
  2017-11-27  8:19 ` James Morris
  0 siblings, 1 reply; 2+ messages in thread
From: Eric Biggers @ 2017-11-27  7:15 UTC (permalink / raw)
  To: keyrings, David Howells
  Cc: linux-crypto, Alexander Potapenko, Eric Biggers, stable

From: Eric Biggers <ebiggers@google.com>

asn1_ber_decoder() was ignoring errors from actions associated with the
opcodes ASN1_OP_END_SEQ_ACT, ASN1_OP_END_SET_ACT,
ASN1_OP_END_SEQ_OF_ACT, and ASN1_OP_END_SET_OF_ACT.  In practice, this
meant the pkcs7_note_signed_info() action (since that was the only user
of those opcodes).  Fix it by checking for the error, just like the
decoder does for actions associated with the other opcodes.

This bug allowed users to leak slab memory by repeatedly trying to add a
specially crafted "pkcs7_test" key (requires CONFIG_PKCS7_TEST_KEY).

In theory, this bug could also be used to bypass module signature
verification, by providing a PKCS#7 message that is misparsed such that
a signature's ->authattrs do not contain its ->msgdigest.  But it
doesn't seem practical in normal cases, due to restrictions on the
format of the ->authattrs.

Fixes: 42d5ec27f873 ("X.509: Add an ASN.1 decoder")
Cc: <stable@vger.kernel.org> # v3.7+
Signed-off-by: Eric Biggers <ebiggers@google.com>
---
 lib/asn1_decoder.c | 2 ++
 1 file changed, 2 insertions(+)

diff --git a/lib/asn1_decoder.c b/lib/asn1_decoder.c
index d77cdfc4b554..dc14beae2c9a 100644
--- a/lib/asn1_decoder.c
+++ b/lib/asn1_decoder.c
@@ -439,6 +439,8 @@ int asn1_ber_decoder(const struct asn1_decoder *decoder,
 			else
 				act = machine[pc + 1];
 			ret = actions[act](context, hdr, 0, data + tdp, len);
+			if (ret < 0)
+				return ret;
 		}
 		pc += asn1_op_lengths[op];
 		goto next_op;
-- 
2.15.0

^ permalink raw reply related	[flat|nested] 2+ messages in thread

* Re: [PATCH] ASN.1: check for error from ASN1_OP_END__ACT actions
  2017-11-27  7:15 [PATCH] ASN.1: check for error from ASN1_OP_END__ACT actions Eric Biggers
@ 2017-11-27  8:19 ` James Morris
  0 siblings, 0 replies; 2+ messages in thread
From: James Morris @ 2017-11-27  8:19 UTC (permalink / raw)
  To: Eric Biggers
  Cc: keyrings, David Howells, linux-crypto, Alexander Potapenko,
	Eric Biggers, stable

On Sun, 26 Nov 2017, Eric Biggers wrote:

> Fixes: 42d5ec27f873 ("X.509: Add an ASN.1 decoder")
> Cc: <stable@vger.kernel.org> # v3.7+
> Signed-off-by: Eric Biggers <ebiggers@google.com>


Reviewed-by: James Morris <james.l.morris@oracle.com>

-- 
James Morris
<james.l.morris@oracle.com>

^ permalink raw reply	[flat|nested] 2+ messages in thread

end of thread, other threads:[~2017-11-27  8:19 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2017-11-27  7:15 [PATCH] ASN.1: check for error from ASN1_OP_END__ACT actions Eric Biggers
2017-11-27  8:19 ` James Morris

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).