Received: by 2002:ac0:a594:0:0:0:0:0 with SMTP id m20-v6csp2951146imm; Thu, 24 May 2018 19:45:07 -0700 (PDT) X-Google-Smtp-Source: AB8JxZpjb5enYfg8wszk3fXlET2e1slI8RsBJXd2DmSbFoiIW7Wos8HzI4uD9g8M0UmIJ2Mzqq6v X-Received: by 2002:a62:3bcb:: with SMTP id w72-v6mr585278pfj.129.1527216307867; Thu, 24 May 2018 19:45:07 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1527216307; cv=none; d=google.com; s=arc-20160816; b=zLxwszAgdtV9lBcuwbJH58YsmyestlMk4GWyjysP+5Q1wofGSuNrfZy8aCI8qTY+Bc 72WLsg2oRDTbFBROc2B/+pqwik7wwmDPGEnMqp1SDnWXnt1PW18RINznYC/kZbRdnaH3 UejR7wQI1oD0criFyoOpgtFjbRvKVtNTm1uTOyM+A82Yd359rD0PfYtXEHa3gAPhheJm EqsU9bXWFVNLgYc/K0/00Gws4G0Zez50YuHwlP0O4MQH8bd3offwZ2Qb4QCwRIHhXYJh ZW6M7DO1Ngyyu4VaURF2VmZkvIRlVsF+UUWoeVvbRt3EHw4OJ6mCYpQ3iUCUf3w3rQrU UXNQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:references:in-reply-to:message-id:date :subject:cc:to:from:arc-authentication-results; bh=xZBsdvQ2wMNefQkcra0Hlw0BhKZlpviENb64iP3W1Mw=; b=YjEzC5mUS3OHYerexBVziGOAyE927IuCCt0rJuiUhrKBHV282+HEmX3Jkj7mi4YS2x gd708+z5jsp0YCQ/LbSc8yA0KKh4sWy1KTR91dwNx0yzX2aUWq0mX7B+I7HdWCUt/eMG VCc0yN93W8FujNsRnEgjLgdllKIlPMDO7xJw3kC1qfVlSv9E4DSjO/Pe1J+TsHaTjbAQ G1Cv+svZWPSyuXXX7nadibMS3JWFdjFaH8xwERBz3LS9G7h5h7+Zp0RLE2lHT/5K+nRx v/IPKgBJ4GFRNIirpra/xpSd4KkkL1UimwjpXqSWBfFC+vsXyzMdhl00MIjFwpLH0h42 VGJg== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id n6-v6si22044831pfi.360.2018.05.24.19.44.53; Thu, 24 May 2018 19:45:07 -0700 (PDT) Received-SPF: pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1161414AbeEXV3T (ORCPT + 99 others); Thu, 24 May 2018 17:29:19 -0400 Received: from smtp2.provo.novell.com ([137.65.250.81]:36415 "EHLO smtp2.provo.novell.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1161359AbeEXV2e (ORCPT ); Thu, 24 May 2018 17:28:34 -0400 Received: from linux-n805.suse.de (prv-ext-foundry1int.gns.novell.com [137.65.251.240]) by smtp2.provo.novell.com with ESMTP (TLS encrypted); Thu, 24 May 2018 15:28:26 -0600 From: Davidlohr Bueso To: akpm@linux-foundation.org, torvalds@linux-foundation.org Cc: tgraf@suug.ch, herbert@gondor.apana.org.au, manfred@colorfullife.com, guillaume.knispel@supersonicimagine.com, linux-api@vger.kernel.org, linux-kernel@vger.kernel.org, Davidlohr Bueso , Davidlohr Bueso Subject: [PATCH 4/6] ipc: get rid of ids->tables_initialized hack Date: Thu, 24 May 2018 14:11:33 -0700 Message-Id: <20180524211135.27760-5-dave@stgolabs.net> X-Mailer: git-send-email 2.13.6 In-Reply-To: <20180524211135.27760-1-dave@stgolabs.net> References: <20180524211135.27760-1-dave@stgolabs.net> Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org In sysvipc we have an ids->tables_initialized regarding the rhashtable, introduced in: 0cfb6aee70b (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. Signed-off-by: Davidlohr Bueso --- include/linux/ipc_namespace.h | 1 - ipc/util.c | 23 ++++++++--------------- 2 files changed, 8 insertions(+), 16 deletions(-) diff --git a/include/linux/ipc_namespace.h b/include/linux/ipc_namespace.h index b5630c8eb2f3..37f3a4b7c637 100644 --- a/include/linux/ipc_namespace.h +++ b/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 --git a/ipc/util.c b/ipc/util.c index 4e81182fa0ac..823e09e72c58 100644 --- a/ipc/util.c +++ b/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(const char *path, const char *header, */ 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; } #ifdef CONFIG_CHECKPOINT_RESTORE @@ -255,7 +251,7 @@ int ipc_addid(struct ipc_ids *ids, struct kern_ipc_perm *new, int limit) if (limit > IPCMNI) limit = IPCMNI; - if (!ids->tables_initialized || ids->in_use >= limit) + if (ids->in_use >= limit) return -ENOSPC; idr_preload(GFP_KERNEL); @@ -566,9 +562,6 @@ struct kern_ipc_perm *ipc_obtain_object_idr(struct ipc_ids *ids, int id) 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); -- 2.13.6