Received: by 2002:ac0:a5b6:0:0:0:0:0 with SMTP id m51-v6csp759372imm; Fri, 1 Jun 2018 09:03:28 -0700 (PDT) X-Google-Smtp-Source: ADUXVKLgevGVgq0RggLIZqf3G9LD+Vni9pI5OEZYyWQmpNeAP7QuKFiIivxLah7NjfoLtN3P2y4H X-Received: by 2002:a63:3348:: with SMTP id z69-v6mr5918236pgz.171.1527869008540; Fri, 01 Jun 2018 09:03:28 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1527869008; cv=none; d=google.com; s=arc-20160816; b=RKnJmYkZr4/HjmA02ndPNM5r0ooXdPqxWlsV6/999YEdEyYe4O1lRHOQKPPmzAt9sQ KsuhgooUCqyjcFZiLrzrnOiOEQ3bhNIo1t18nezm9KMDapG2XZmwSHEutFdBFGQoiVuS 5DymS1sckCkV8AACj6mMzcJNpMW2mDcaEmAmKiAwX9IfBOivwENPA4z2mcSSuHr+TLau bvl3KJtfuufh2G2ZAuQ4+Rrram/Sl4KekbhcoRr6GqkSwXWJ6cps6MUNZ3YA21YJquhX LNJ/ZOZMXCQ+8DgzDrc4ALvBXyJw178ztxekLMe34rNmx+Mba31XQJBf63uDzJo2kLd0 N1Gw== 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=nzyt8A6c3FgpnkFp4imqla0CKxbeu4yiUEfyOhHON54=; b=nUFhLuPUV3fwAqt4jXBCS1kYU/K0vomFfU7RQPvr93OlTepamAFqgCV5Q7pLHWiWe9 fmhARh/xlSaEMRmxTnfqBfmI7vHwHD+cBopeXPppjI0+5b6FI6akLcaZ/dmYbqVZ32BT nz3ncvdM0HzhrkkySxnQJ63sbPRjlrWnVIneyb6LRyR8U2rs0wRiYNDC96ICbOU9QWQb f8mHVxRUOGgn0Fqts8YJXNigMuNCS1tATeoFEnlJ5CCmYvMc7dQKsCDlcaygxXZgAW2c qBaUD/iEGXh6WqqjzWPzIPA7+3wVUAi9v5XQCu8zgrZPFxhy4645isuQ15MZnKx/ee8b WPUw== 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 d16-v6si221288pli.201.2018.06.01.09.03.06; Fri, 01 Jun 2018 09:03:28 -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 S1753033AbeFAQCR (ORCPT + 99 others); Fri, 1 Jun 2018 12:02:17 -0400 Received: from smtp2.provo.novell.com ([137.65.250.81]:55185 "EHLO smtp2.provo.novell.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1752990AbeFAQCM (ORCPT ); Fri, 1 Jun 2018 12:02:12 -0400 Received: from localhost.localdomain (prv-ext-foundry1int.gns.novell.com [137.65.251.240]) by smtp2.provo.novell.com with ESMTP (TLS encrypted); Fri, 01 Jun 2018 10:02:02 -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, mhocko@kernel.org, guillaume.knispel@supersonicimagine.com, linux-api@vger.kernel.org, linux-kernel@vger.kernel.org, Davidlohr Bueso , Davidlohr Bueso Subject: [PATCH 3/5] ipc: get rid of ids->tables_initialized hack Date: Fri, 1 Jun 2018 09:01:23 -0700 Message-Id: <20180601160125.30031-4-dave@stgolabs.net> X-Mailer: git-send-email 2.16.3 In-Reply-To: <20180601160125.30031-1-dave@stgolabs.net> References: <20180601160125.30031-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.16.3