From f972f2d7b1fb4ff5bd880e53f964598d8ef54cf7 Mon Sep 17 00:00:00 2001 From: Lee Jones Date: Mon, 16 Jun 2025 16:55:21 +0100 Subject: [PATCH] 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 Change-Id: Id8fc8dd01deae75d87dce16f46a59ff67cac0832 --- net/core/scm.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/net/core/scm.c b/net/core/scm.c index 574607b1c2d9..8076f091003f 100644 --- a/net/core/scm.c +++ b/net/core/scm.c @@ -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++)