ANDROID: af_unix: Allocate memory for the largest possible size of 'struct scm_fp_list'

In order to work around some fairly intrusive ABI infringements, we have
2 choices.  Either create a whole new structure to wrap around 'struct
scm_fp_list' or push all of the new field entries to the bottom of the
existing struct.

Initially we opted for the first choice, since this seemed to save a
substantial amount of memory (~500KB) due to the kmemdup() magic found
in scm_fp_dup().  However, this required some far reaching adaptions to
the current code, meaning that the chances of conflicts in the future
would have been significant and maintenance costs would have remained
high.

However, it turns out that each block of 2KB that is allocated in
scm_fp_dup() is not accumulative and only exists for a short amount of
time before being subsequently freed.  Thus, the hit taken with respect
to the extra memory used by simply allocating the largest possible size
of the struct is now considered to be a good trade-off.  So let's do
that.

Bug: 404256079
Signed-off-by: Lee Jones <joneslee@google.com>
Change-Id: Id8fc8dd01deae75d87dce16f46a59ff67cac0832
This commit is contained in:
Lee Jones
2025-06-16 16:55:21 +01:00
parent b077571da9
commit f972f2d7b1

View File

@@ -371,7 +371,7 @@ struct scm_fp_list *scm_fp_dup(struct scm_fp_list *fpl)
if (!fpl)
return NULL;
new_fpl = kmemdup(fpl, offsetof(struct scm_fp_list, fp[fpl->count]),
new_fpl = kmemdup(fpl, sizeof(*fpl),
GFP_KERNEL_ACCOUNT);
if (new_fpl) {
for (i = 0; i < fpl->count; i++)