aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorWerner Koch <[email protected]>2015-02-22 04:10:30 +0000
committerWerner Koch <[email protected]>2015-02-23 09:46:07 +0000
commit81d3e541326e94d26a953aa70afc3cb149d11ebe (patch)
tree1097a2458efcd3308789b8e0c75bf2b096b4eaea
parentgpg: Fix a NULL-deref in export due to invalid packet lengths. (diff)
downloadgnupg-81d3e541326e94d26a953aa70afc3cb149d11ebe.tar.gz
gnupg-81d3e541326e94d26a953aa70afc3cb149d11ebe.zip
gpg: Prevent an invalid memory read using a garbled keyring.
* g10/keyring.c (keyring_get_keyblock): Whitelist allowed packet types. -- The keyring DB code did not reject packets which don't belong into a keyring. If for example the keyblock contains a literal data packet it is expected that the processing code stops at the data packet and reads from the input stream which is referenced from the data packets. Obviously the keyring processing code does not and cannot do that. However, when exporting this messes up the IOBUF and leads to an invalid read of sizeof (int). We now skip all packets which are not allowed in a keyring. Reported-by: Hanno Böck <[email protected]> (back ported from commit f0f71a721ccd7ab9e40b8b6b028b59632c0cc648) [dkg: rebased to STABLE-BRANCH-1-4] Signed-off-by: Daniel Kahn Gillmor <[email protected]>
-rw-r--r--g10/keyring.c24
1 files changed, 21 insertions, 3 deletions
diff --git a/g10/keyring.c b/g10/keyring.c
index 108e107b2..270bf8ee7 100644
--- a/g10/keyring.c
+++ b/g10/keyring.c
@@ -400,8 +400,26 @@ keyring_get_keyblock (KEYRING_HANDLE hd, KBNODE *ret_kb)
rc = G10ERR_INV_KEYRING;
break;
}
- if (pkt->pkttype == PKT_COMPRESSED) {
- log_error ("skipped compressed packet in keyring\n");
+
+ /* Filter allowed packets. */
+ switch (pkt->pkttype){
+ case PKT_PUBLIC_KEY:
+ case PKT_PUBLIC_SUBKEY:
+ case PKT_SECRET_KEY:
+ case PKT_SECRET_SUBKEY:
+ case PKT_USER_ID:
+ case PKT_ATTRIBUTE:
+ case PKT_SIGNATURE:
+ break; /* Allowed per RFC. */
+ case PKT_RING_TRUST:
+ case PKT_OLD_COMMENT:
+ case PKT_COMMENT:
+ case PKT_GPG_CONTROL:
+ break; /* Allowed by us. */
+
+ default:
+ log_error ("skipped packet of type %d in keyring\n",
+ (int)pkt->pkttype);
free_packet(pkt);
init_packet(pkt);
continue;
@@ -467,7 +485,7 @@ keyring_get_keyblock (KEYRING_HANDLE hd, KBNODE *ret_kb)
if (rc || !ret_kb)
release_kbnode (keyblock);
else {
- /*(duplicated form the loop body)*/
+ /*(duplicated from the loop body)*/
if ( pkt && pkt->pkttype == PKT_RING_TRUST
&& lastnode
&& lastnode->pkt->pkttype == PKT_SIGNATURE