Received: by 2002:ac0:a581:0:0:0:0:0 with SMTP id m1-v6csp97303imm; Thu, 21 Jun 2018 14:38:14 -0700 (PDT) X-Google-Smtp-Source: ADUXVKJkUN1K//bI5nMBEjtNDAKmD4ScLf7iaqMQiv7Rdn9GiQ3eMAb+lJSf/DOCMIJHPlY04RrL X-Received: by 2002:a62:1146:: with SMTP id z67-v6mr28839956pfi.135.1529617094009; Thu, 21 Jun 2018 14:38:14 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1529617093; cv=none; d=google.com; s=arc-20160816; b=gaIs51RI9WKJRfgg8fZBi2RndQJdgDJLBLHGvURV0rWMMLqR9n0Hy/MfM+alPKK2Zm P7FxrlWW38pW4F2bel0FTZ5DcPBnYTn3E14FjrDHnCfAF4Jz6Iwc/zfOwisBw7hwDGxh GqoVonqmy/gr1wIVS9v75I5JrZV1if/uJrtYZ6Tv6Ri1kSX/TsqxKsiKnGh0CoFWl6EK U4PcXfxfMCcVIWE3kmNHmOtcsMTPKQ2gBr3uQbjZkkTOE89TF6bD14hU3Abii/6f+KwR uEfhSpnJE6kHXUQC0sxZd3LaZMBvpqkhAd7JeEy6+1NupWpRUYTtb+D4CFTiCEQJQxnY 2X2g== 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=2I4F5V1nSjzzgVIcZOdpeSgjpv38B+iRx/pxoovEwEU=; b=BeJkOmWBM5yn5RM52s0Swrlc/uJ7LXndxvBKaHZXbtW/bMqCf0PZqG+5FetSavqZVa gBWxMBI5wW4psGo2Ip/72nDogUkTXotL2RbZ7i2r/Qtr7eh94j3doLj8hXdExcxPbUc8 yh9jWaRqQHAoW57t8pRCqxbI0vmaQSx1B9541UuHcqRZ/v7572DwoRd/jJpS1gieAqSE 1O3ZUtZTc89qeKZBtQwgwJlL+akdh05S223aAMU1UlEFPPidSr2gv6iU/qxe5O99Cusm 7M+uLqijY2iPHIPXyejGamUQGPeYeR3V78c3imWsbOcISIPKWuNR6lVkBxTy//WuQX8C J9rg== 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 p29-v6si4661641pgd.546.2018.06.21.14.37.59; Thu, 21 Jun 2018 14:38:13 -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 S934046AbeFUVgX (ORCPT + 99 others); Thu, 21 Jun 2018 17:36:23 -0400 Received: from smtp2.provo.novell.com ([137.65.250.81]:59130 "EHLO smtp2.provo.novell.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S933884AbeFUV3A (ORCPT ); Thu, 21 Jun 2018 17:29:00 -0400 Received: from linux-r8p5.suse.cz (prv-ext-foundry1int.gns.novell.com [137.65.251.240]) by smtp2.provo.novell.com with ESMTP (TLS encrypted); Thu, 21 Jun 2018 15:28:51 -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, dave@stgolabs.net, Davidlohr Bueso Subject: [PATCH 3/4] ipc: get rid of ids->tables_initialized hack Date: Thu, 21 Jun 2018 14:28:24 -0700 Message-Id: <20180621212825.3059-4-dave@stgolabs.net> X-Mailer: git-send-email 2.16.4 In-Reply-To: <20180621212825.3059-1-dave@stgolabs.net> References: <20180621212825.3059-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.4