CVE-2022-32746 ldb: Ensure shallow copy modifications do not affect original message
authorJoseph Sutton <josephsutton@catalyst.net.nz>
Tue, 15 Feb 2022 23:35:13 +0000 (12:35 +1300)
committerJule Anger <janger@samba.org>
Sun, 24 Jul 2022 09:41:53 +0000 (11:41 +0200)
commit4e5fb78c3dcff60aa8fd4b07dad4660bbb30532b
tree7ea7f7b426e84fcbbbd0a2f974434d74bca5a996
parentfaa61ab3053d077ac9d0aa67e955217e85b660f4
CVE-2022-32746 ldb: Ensure shallow copy modifications do not affect original message

Using the newly added ldb flag, we can now detect when a message has
been shallow-copied so that its elements share their values with the
original message elements. Then when adding values to the copied
message, we now make a copy of the shared values array first.

This should prevent a use-after-free that occurred in LDB modules when
new values were added to a shallow copy of a message by calling
talloc_realloc() on the original values array, invalidating the 'values'
pointer in the original message element. The original values pointer can
later be used in the database audit logging module which logs database
requests, and potentially cause a crash.

BUG: https://bugzilla.samba.org/show_bug.cgi?id=15009

Signed-off-by: Joseph Sutton <josephsutton@catalyst.net.nz>
lib/ldb/common/ldb_msg.c
lib/ldb/include/ldb.h
source4/dsdb/common/util.c