Tristan reports: winbindd Cache Upgrade Missing Return After tdb_delete NULL Dereference ======================================================================= CVSS 3.1: 5.5 (AV:L/AC:L/PR:N/UI:R/S:U/C:N/I:N/A:H) CWE: CWE-476 (NULL Pointer Dereference) Auth: Local (corrupted TDB cache file) Version: Samba 4.24.3, master HEAD File: source3/winbindd/winbindd_cache.c, wbcache_upgrade_v1_to_v2_fn(), line 4180 Root Cause: When a cache entry has data.dptr == NULL or data.dsize == 0, the function deletes the entry via tdb_delete() but does NOT return. Execution falls through to memcpy(blob.dptr, data.dptr, 8) with data.dptr == NULL. if (data.dptr == NULL || data.dsize == 0) { if (tdb_delete(tdb, key) < 0) { DBG_ERR("tdb_delete for [%s] failed!\n", key.dptr); return 1; } // BUG: no return here -- falls through } blob.dsize = data.dsize + 8; // 0 + 8 = 8 blob.dptr = SMB_XMALLOC_ARRAY(uint8_t, blob.dsize); memcpy(blob.dptr, data.dptr, 8); // data.dptr is NULL -> CRASH Data Flow: winbindd starts with outdated cache format (v1) -> tdb_traverse calls wbcache_upgrade_v1_to_v2_fn for each entry -> entry with data.dptr=NULL: tdb_delete succeeds (returns 0) -> missing return after successful delete -> blob.dsize = 0 + 8 = 8, alloc 8 bytes -> memcpy(blob.dptr, NULL, 8) -> SIGSEGV Impact: A corrupted or crafted winbindd_cache.tdb containing a zero-length entry crashes winbindd during the v1-to-v2 cache upgrade at startup. This denies all winbind-dependent authentication on the host. Lab verified: code trace confirmed missing return statement.
> A corrupted or crafted winbindd_cache.tdb containing a zero-length entry > crashes winbindd during the v1-to-v2 cache upgrade at startup. This > denies all winbind-dependent authentication on the host. How does the attacker put a corrupted tdb file there without already having full access to the server?
Iām guessing it rather involved being on the other side of this airtight hatchway. We still may as well fix the bug.
Created attachment 19119 [details] patch for master
(In reply to Douglas Bagnall from comment #1) (In reply to Jennifer Sutton from comment #2) Fair point, writing to winbindd_cache.tdb requires the same access level the crash would give you. This is a code correctness bug, not a security issue. (In reply to Jennifer Sutton from comment #3) Patch is correct, return 0 continues the traverse after a successful delete. Reviewed-by: Tristan Madani <tristan@talencesecurity.com>
[Bulk message on a number of bugs being made public at once] The embargo is being removed from this bug. That is not to say that the issue is not a real bug, but some things are better dealt with in public, where the normal process is both more available to external contributors and much, much more efficient. If you have a patch for this issue, please do contribute it via our normal GitLab process: https://wiki.samba.org/index.php/Contribute#Submitting_Patches_via_GitLab All patches to Samba must follow our copyright policy: https://www.samba.org/samba/devel/copyright-policy.html Thanks to all who report issues to Samba, we value your patience as we, along with the rest of the Open Source and Free Software communities, work though the reported issues.