From 75725f88640fee6943c47db6ad33c8f4d076c158 Mon Sep 17 00:00:00 2001
From: "Neal H. Walfield" <firstname.lastname@example.org>
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 <email@example.com>
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(-)