]> git.pond.sub.org Git - empserver/commit
edit: Fix stack smash in sector key 'L'
authorMarkus Armbruster <armbru@pond.sub.org>
Sun, 27 Jan 2013 08:28:34 +0000 (09:28 +0100)
committerMarkus Armbruster <armbru@pond.sub.org>
Thu, 6 Jun 2013 17:55:01 +0000 (19:55 +0200)
commit5497126d0522169a6b7b3ad147102344aa27a55c
treeaf30196f4c84b6c74617687d5f746c9ebab77fd7
parenteb60b38a261d994b281cebc276e6357ef41d18a2
edit: Fix stack smash in sector key 'L'

Key 'L' copies the source sector to a destination sector.  Bug: it
doesn't copy, it messes up the source sector badly instead, and can
smash the stack on some machines.

Root cause: doland() passes &sect instead of sect to ef_set_uid().
Impact:

1. ef_setuid() clobbers a few bytes at &sect.

   When the bitfield and uid fit into sizeof(sect) bytes, it clobbers
   just sect, which has no effect, because doland() returns without
   using it again.  This is the case on a typical 64-bit machine: bit
   field and uid are both 4 bytes, sizeof(sect) is 8.

   When they don't fit, whatever is adjacent to sect gets clobbered.
   On a typical 32-bit machine with stack growing down, that's p.
   Again, no effect, because doland() returns without using it again.
   With stack growing up, it could well be the return address,
   crashing the server.

2. ef_setuid() fails to update *sect.  Impact (when we survive 1):

   sect->sct_uid remains unchanged.  putsect() writes to the source
   sector instead of the destination sector, clobbering the source's
   sct_x, sct_y.  Breaks invariant sctoff(sct_x, sct_y) == sct_uid!
   Subsequent edits are all applied to the source sector.

   sect->sct_seqno remains unchanged.  No effect, because we write to
   the source sector, and the unchanged sequence number is the right
   one there.

Broken in commit 536ef0b0, v4.3.15.

Signed-off-by: Markus Armbruster <armbru@pond.sub.org>
src/lib/commands/edit.c
tests/actofgod/actofgod.xdump