Bug 27124

Summary: libio vtable hardening bypass via obstack files
Product: glibc Reporter: Will Coster <willcoster>
Component: stdioAssignee: Not yet assigned to anyone <unassigned>
Status: RESOLVED FIXED    
Severity: normal CC: fweimer
Priority: P2 Flags: fweimer: security-
Version: 2.32   
Target Milestone: 2.37   
Host: Target:
Build: Last reconfirmed:
Project(s) to access: ssh public key:

Description Will Coster 2020-12-28 23:15:07 UTC
It is possible to bypass existing libio vtable hardening by using the _IO_obstack_jumps vtable and a forged obstack.

The obstack struct contains unmangled pointers to a custom allocator [1] which is used when growing an obstack [2, 3, 4].

Both of the methods listed in the _IO_obstack_jumps vtable attempt to grow an obstack when certain conditions are met [5, 6].

This is similar to Bug 23236 and would allow an attacker with the ability to corrupt FILE objects to gain code execution. I have tested and confirmed that this works on glibc 2.32.

I am filing this in the public tracker in accordance with the guidance that hardening bypasses are not considered security issues in and of themselves [7].

[1] https://sourceware.org/git/?p=glibc.git;a=blob;f=malloc/obstack.h;h=4b1ba80047b378fa63739e5dbbbf748ca026e197;hb=refs/heads/release/2.32/master#l153
[2] https://sourceware.org/git/?p=glibc.git;a=blob;f=malloc/obstack.h;h=4b1ba80047b378fa63739e5dbbbf748ca026e197;hb=refs/heads/release/2.32/master#l296
[3] https://sourceware.org/git/?p=glibc.git;a=blob;f=malloc/obstack.c;h=0d652be9f5d4c0e88e55bf84bbc1053c20d7ce83;hb=refs/heads/release/2.32/master#l261
[4] https://sourceware.org/git/?p=glibc.git;a=blob;f=malloc/obstack.c;h=0d652be9f5d4c0e88e55bf84bbc1053c20d7ce83;hb=refs/heads/release/2.32/master#l121
[5] https://sourceware.org/git/?p=glibc.git;a=blob;f=libio/obprintf.c;h=e440cd74c3caf3ee5bbfec9aa1e3ff880f0b3fb7;hb=refs/heads/release/2.32/master#l48
[6] https://sourceware.org/git/?p=glibc.git;a=blob;f=libio/obprintf.c;h=e440cd74c3caf3ee5bbfec9aa1e3ff880f0b3fb7;hb=refs/heads/release/2.32/master#l76
[7] https://sourceware.org/glibc/wiki/Security%20Exceptions#Post-exploitation_countermeasures
Comment 1 Florian Weimer 2022-04-26 09:18:43 UTC
Patch posted:

[PATCH 25/26] libio: Convert __obstack_vprintf_internal to buffers (bug 27124)
<https://sourceware.org/pipermail/libc-alpha/2022-March/137157.html>
Comment 2 Sourceware Commits 2022-12-19 18:56:46 UTC
The master branch has been updated by Florian Weimer <fw@sourceware.org>:

https://sourceware.org/git/gitweb.cgi?p=glibc.git;h=5365acc567a49270b4341b9d325794ec554258d9

commit 5365acc567a49270b4341b9d325794ec554258d9
Author: Florian Weimer <fweimer@redhat.com>
Date:   Mon Dec 19 18:56:55 2022 +0100

    libio: Convert __obstack_vprintf_internal to buffers (bug 27124)
    
    This fixes bug 27124 because the problematic built-in vtable is gone.
    
    Reviewed-by: Adhemerval Zanella  <adhemerval.zanella@linaro.org>
Comment 3 Florian Weimer 2023-07-05 08:30:38 UTC
Fixed in glibc 2.37.