Bug 16168 - winbindd Cache Upgrade Missing Return After tdb_delete NULL Dereference
Summary: winbindd Cache Upgrade Missing Return After tdb_delete NULL Dereference
Status: ASSIGNED
Alias: None
Product: Samba 4.1 and newer
Classification: Unclassified
Component: Winbind (show other bugs)
Version: 4.24.3
Hardware: All All
: P5 normal (vote)
Target Milestone: ---
Assignee: Jennifer Sutton
QA Contact: Samba QA Contact
URL:
Keywords:
Depends on:
Blocks:
 
Reported: 2026-07-09 03:15 UTC by Douglas Bagnall
Modified: 2026-11-01 06:19 UTC (History)
3 users (show)

See Also:


Attachments
patch for master (805 bytes, patch)
2026-07-17 03:18 UTC, Jennifer Sutton
no flags Details

Note You need to log in before you can comment on or make changes to this bug.
Description Douglas Bagnall 2026-07-09 03:15:11 UTC
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.
Comment 1 Douglas Bagnall 2026-07-09 03:17:39 UTC
> 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?
Comment 2 Jennifer Sutton 2026-07-17 02:46:14 UTC
I’m guessing it rather involved being on the other side of this airtight hatchway.

We still may as well fix the bug.
Comment 3 Jennifer Sutton 2026-07-17 03:18:52 UTC
Created attachment 19119 [details]
patch for master
Comment 4 TristanInSec 2026-07-22 13:54:58 UTC
(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>
Comment 5 Andrew Bartlett 2026-11-01 06:10:57 UTC
[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.