The patch titled Subject: ipc: get rid of ids->tables_initialized hack has been added to the -mm tree. Its filename is ipc-get-rid-of-ids-tables_initialized-hack.patch This patch should soon appear at http://ozlabs.org/~akpm/mmots/broken-out/ipc-get-rid-of-ids-tables_initialized-hack.patch and later at http://ozlabs.org/~akpm/mmotm/broken-out/ipc-get-rid-of-ids-tables_initialized-hack.patch Before you just go and hit "reply", please: a) Consider who else should be cc'ed b) Prefer to cc a suitable mailing list as well c) Ideally: find the original patch on the mailing list and do a reply-to-all to that, adding suitable additional cc's *** Remember to use Documentation/process/submit-checklist.rst when testing your code *** The -mm tree is included into linux-next and is updated there every 3-4 working days ------------------------------------------------------ From: Davidlohr Bueso <dave@xxxxxxxxxxxx> Subject: ipc: get rid of ids->tables_initialized hack In sysvipc we have an ids->tables_initialized regarding the rhashtable, introduced in 0cfb6aee70bd ("ipc: optimize semget/shmget/msgget for lots of keys") It's there, specifically, to prevent nil pointer dereferences, from using an uninitialized api. Considering how rhashtable_init() can fail (probably due to ENOMEM, if anything), this made the overall ipc initialization capable of failure as well. That alone is ugly, but fine, however I've spotted a few issues regarding the semantics of tables_initialized (however unlikely they may be): - There is inconsistency in what we return to userspace: ipc_addid() returns ENOSPC which is certainly _wrong_, while ipc_obtain_object_idr() returns EINVAL. - After we started using rhashtables, ipc_findkey() can return nil upon !tables_initialized, but the caller expects nil for when the ipc structure isn't found, and can therefore call into ipcget() callbacks. Now that rhashtable initialization cannot fail, we can properly get rid of the hack altogether. [manfred@xxxxxxxxxxxxxxxx: commit id extended to 12 digits] Link: http://lkml.kernel.org/r/20180712185241.4017-10-manfred@xxxxxxxxxxxxxxxx Signed-off-by: Davidlohr Bueso <dbueso@xxxxxxx> Signed-off-by: Manfred Spraul <manfred@xxxxxxxxxxxxxxxx> Cc: Dmitry Vyukov <dvyukov@xxxxxxxxxx> Cc: Herbert Xu <herbert@xxxxxxxxxxxxxxxxxxx> Cc: Kees Cook <keescook@xxxxxxxxxxxx> Cc: Michael Kerrisk <mtk.manpages@xxxxxxxxx> Cc: Michal Hocko <mhocko@xxxxxxxx> Signed-off-by: Andrew Morton <akpm@xxxxxxxxxxxxxxxxxxxx> --- diff -puN include/linux/ipc_namespace.h~ipc-get-rid-of-ids-tables_initialized-hack include/linux/ipc_namespace.h --- a/include/linux/ipc_namespace.h~ipc-get-rid-of-ids-tables_initialized-hack +++ a/include/linux/ipc_namespace.h @@ -16,7 +16,6 @@ struct user_namespace; struct ipc_ids { int in_use; unsigned short seq; - bool tables_initialized; struct rw_semaphore rwsem; struct idr ipcs_idr; int max_id; diff -puN ipc/util.c~ipc-get-rid-of-ids-tables_initialized-hack ipc/util.c --- a/ipc/util.c~ipc-get-rid-of-ids-tables_initialized-hack +++ a/ipc/util.c @@ -125,7 +125,6 @@ int ipc_init_ids(struct ipc_ids *ids) if (err) return err; idr_init(&ids->ipcs_idr); - ids->tables_initialized = true; ids->max_id = -1; #ifdef CONFIG_CHECKPOINT_RESTORE ids->next_id = -1; @@ -178,19 +177,16 @@ void __init ipc_init_proc_interface(cons */ static struct kern_ipc_perm *ipc_findkey(struct ipc_ids *ids, key_t key) { - struct kern_ipc_perm *ipcp = NULL; + struct kern_ipc_perm *ipcp; - if (likely(ids->tables_initialized)) - ipcp = rhashtable_lookup_fast(&ids->key_ht, &key, + ipcp = rhashtable_lookup_fast(&ids->key_ht, &key, ipc_kht_params); + if (!ipcp) + return NULL; - if (ipcp) { - rcu_read_lock(); - ipc_lock_object(ipcp); - return ipcp; - } - - return NULL; + rcu_read_lock(); + ipc_lock_object(ipcp); + return ipcp; } /* @@ -268,7 +264,7 @@ int ipc_addid(struct ipc_ids *ids, struc if (limit > IPCMNI) limit = IPCMNI; - if (!ids->tables_initialized || ids->in_use >= limit) + if (ids->in_use >= limit) return -ENOSPC; idr_preload(GFP_KERNEL); @@ -577,9 +573,6 @@ struct kern_ipc_perm *ipc_obtain_object_ struct kern_ipc_perm *out; int lid = ipcid_to_idx(id); - if (unlikely(!ids->tables_initialized)) - return ERR_PTR(-EINVAL); - out = idr_find(&ids->ipcs_idr, lid); if (!out) return ERR_PTR(-EINVAL); _ Patches currently in -mm which might be from dave@xxxxxxxxxxxx are ipc-drop-ipc_lock.patch lib-rhashtable-simplify-bucket_table_alloc.patch lib-rhashtable-guarantee-initial-hashtable-allocation.patch ipc-get-rid-of-ids-tables_initialized-hack.patch ipc-simplify-ipc-initialization.patch -- To unsubscribe from this list: send the line "unsubscribe mm-commits" in the body of a message to majordomo@xxxxxxxxxxxxxxx More majordomo info at http://vger.kernel.org/majordomo-info.html