From 15c909dc178691f1b37cae44d2f154eeb3a7a224 Mon Sep 17 00:00:00 2001 From: Ksawlii Date: Sun, 24 Nov 2024 00:23:50 +0100 Subject: [PATCH] Revert "ipc: replace costly bailout check in sysvipc_find_ipc()" This reverts commit 5d6d68e94e752339ed6152071ec7e70700dc64af. --- ipc/util.c | 16 ++++++++++++---- 1 file changed, 12 insertions(+), 4 deletions(-) diff --git a/ipc/util.c b/ipc/util.c index 7c3601dad..bbb5190af 100755 --- a/ipc/util.c +++ b/ipc/util.c @@ -754,13 +754,21 @@ struct pid_namespace *ipc_seq_pid_ns(struct seq_file *s) static struct kern_ipc_perm *sysvipc_find_ipc(struct ipc_ids *ids, loff_t pos, loff_t *new_pos) { - struct kern_ipc_perm *ipc = NULL; - int max_idx = ipc_get_maxidx(ids); + struct kern_ipc_perm *ipc; + int total, id; - if (max_idx == -1 || pos > max_idx) + total = 0; + for (id = 0; id < pos && total < ids->in_use; id++) { + ipc = idr_find(&ids->ipcs_idr, id); + if (ipc != NULL) + total++; + } + + ipc = NULL; + if (total >= ids->in_use) goto out; - for (; pos <= max_idx; pos++) { + for (; pos < ipc_mni; pos++) { ipc = idr_find(&ids->ipcs_idr, pos); if (ipc != NULL) { rcu_read_lock();