The patch titled Subject: ipc: conserve sequence numbers in ipcmni_extend mode has been removed from the -mm tree. Its filename was ipc-conserve-sequence-numbers-in-ipcmni_extend-mode.patch This patch was dropped because an updated version will be merged ------------------------------------------------------ From: Waiman Long <longman@xxxxxxxxxx> Subject: ipc: conserve sequence numbers in ipcmni_extend mode The mixing in of a sequence number into the IPC IDs is probably to avoid ID reuse in userspace as much as possible. With ipcmni_extend mode, the number of usable sequence numbers is greatly reduced leading to higher chance of ID reuse. To address this issue, we need to conserve the sequence number space as much as possible. Right now, the sequence number is incremented for every new ID created. In reality, we only need to increment the sequence number when new allocated ID is not greater than the last one allocated. It is in such case that the new ID may collide with an existing one. This is being done irrespective of the ipcmni mode. Link: http://lkml.kernel.org/r/1551379645-819-3-git-send-email-longman@xxxxxxxxxx Suggested-by: Matthew Wilcox <willy@xxxxxxxxxxxxx> Signed-off-by: Waiman Long <longman@xxxxxxxxxx> Cc: Al Viro <viro@xxxxxxxxxxxxxxxxxx> Cc: Davidlohr Bueso <dbueso@xxxxxxx> Cc: "Eric W. Biederman" <ebiederm@xxxxxxxxxxxx> Cc: Jonathan Corbet <corbet@xxxxxxx> Cc: Kees Cook <keescook@xxxxxxxxxxxx> Cc: "Luis R. Rodriguez" <mcgrof@xxxxxxxxxx> Cc: Manfred Spraul <manfred@xxxxxxxxxxxxxxxx> Cc: Takashi Iwai <tiwai@xxxxxxx> Signed-off-by: Andrew Morton <akpm@xxxxxxxxxxxxxxxxxxxx> --- --- a/include/linux/ipc_namespace.h~ipc-conserve-sequence-numbers-in-ipcmni_extend-mode +++ a/include/linux/ipc_namespace.h @@ -19,6 +19,7 @@ struct ipc_ids { struct rw_semaphore rwsem; struct idr ipcs_idr; int max_idx; + int last_idx; /* For wrap around detection */ #ifdef CONFIG_CHECKPOINT_RESTORE int next_id; #endif --- a/ipc/util.c~ipc-conserve-sequence-numbers-in-ipcmni_extend-mode +++ a/ipc/util.c @@ -120,6 +120,7 @@ void ipc_init_ids(struct ipc_ids *ids) rhashtable_init(&ids->key_ht, &ipc_kht_params); idr_init(&ids->ipcs_idr); ids->max_idx = -1; + ids->last_idx = -1; #ifdef CONFIG_CHECKPOINT_RESTORE ids->next_id = -1; #endif @@ -193,6 +194,10 @@ static struct kern_ipc_perm *ipc_findkey * * The caller must own kern_ipc_perm.lock.of the new object. * On error, the function returns a (negative) error code. + * + * To conserve sequence number space, especially with extended ipc_mni, + * the sequence number is incremented only when the returned ID is less than + * the last one. */ static inline int ipc_idr_alloc(struct ipc_ids *ids, struct kern_ipc_perm *new) { @@ -216,10 +221,11 @@ static inline int ipc_idr_alloc(struct i */ if (next_id < 0) { /* !CHECKPOINT_RESTORE or next_id is unset */ - new->seq = ids->seq++; - if (ids->seq > IPCID_SEQ_MAX) - ids->seq = 0; idx = idr_alloc(&ids->ipcs_idr, new, 0, 0, GFP_NOWAIT); + if ((idx <= ids->last_idx) && (++ids->seq > IPCID_SEQ_MAX)) + ids->seq = 0; + new->seq = ids->seq; + ids->last_idx = idx; } else { new->seq = ipcid_to_seqx(next_id); idx = idr_alloc(&ids->ipcs_idr, new, ipcid_to_idx(next_id), _ Patches currently in -mm which might be from longman@xxxxxxxxxx are debugobjects-move-printk-out-of-db-lock-critical-sections.patch ipc-allow-boot-time-extension-of-ipcmni-from-32k-to-16m.patch ipc-do-cyclic-id-allocation-with-ipcmni_extend-mode.patch