Page MenuHome GnuPG

738_0001-gpg-Fix-TOCTTOU-when-updating-keyblocks.patch
AbandonedPublic

Authored by neal on Dec 15 2015, 8:08 PM.

Details

Reviewers
None
Summary

From 75725f88640fee6943c47db6ad33c8f4d076c158 Mon Sep 17 00:00:00 2001
From: "Neal H. Walfield" <neal@g10code.com>
Date: Tue, 15 Dec 2015 20:05:20 +0100
Subject: [PATCH] gpg: Fix TOCTTOU when updating keyblocks.

  • g10/keydb.c (keydb_update_keyblock): Don't replace the record at the

current offset. After taking the lock, extract the fingerprint from
the keyblock, find it and then replace it.

Signed-off-by: Neal H. Walfield <neal@g10code.com>
GnuPG-bug-id: 2193

Between locating the record to update and actually updating the
keyblock, it is possible that another process modifies the keyring,
which causes the update to corrupt the keyring. This is due to a time
of check to time of use bug. The fix is straightforward: both
operations must be done while holding the lock. This changes the
semantics of the function slightly, but no callers need to be
modified. Further, it now becomes impossible to replace key A with B;

this function will only ever update B.

g10/keydb.c | 24 +++++++++++++++++++++---
g10/keydb.h | 15 ++++++++++++---
2 files changed, 33 insertions(+), 6 deletions(-)

2.1.4

Test Plan

Diff Detail

Lint
Lint Skipped
Unit
Unit Tests Skipped