Received: by 2002:ac0:a594:0:0:0:0:0 with SMTP id m20-v6csp1127318imm; Wed, 23 May 2018 10:41:54 -0700 (PDT) X-Google-Smtp-Source: AB8JxZr9a2mg9LTY2LO3cawWsfe3wumRII45gfMhoPpCQrey/Vh00hhyLtstyjwXWWIp+PvVgEsw X-Received: by 2002:a17:902:7283:: with SMTP id d3-v6mr3944277pll.192.1527097314415; Wed, 23 May 2018 10:41:54 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1527097314; cv=none; d=google.com; s=arc-20160816; b=im5JILBty1R33jqxhC8FQjaG5kmDmaEexyGecsR33Vzy0KHoFJXKw6rGuKrRPj1vjk RUL6Ln5/44MmcMk/iQvFnRRSG1e67VKNMaHcMn5/qKlrsICVUiBHdYXjpChISOdAJn2h wPacp0js3H0GC8HhKk4/zG5HWAvFDJ9CtsnEwH2ciPElYWAxCiU+HHaXHWbNcSw4Jtnp p8zbIz+oNTFGIbeRNOzpUrCCN6VYBtsyv3W8Xc50oQFqxuyKpTjLEl2t+uqwsAoPuq/T AK+krmSBjO6y7cWT2paUbBgOfyrm0Q/xJi3GdU/Cm8u9DF28tpT75nT12XIQpvfYNNT+ v6xw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:user-agent:content-disposition :mime-version:message-id:subject:cc:to:from:date :arc-authentication-results; bh=Clmoch/FmozK+0MkhB8DlI7YH1NWK64/s6on0yPTWuY=; b=hZ/HpGN8vem/NTSFDI46qvU3afRjQWxk2jRxttBhIEJHZIAEzbAnX4xmz6uChrsOtN 2Jkuo3FIjtErYOGTq16JgIusJ3Tw68hsIGaALDCyqrSCpyahwSluG0fowEGUcZcyJ9EZ uYJZjum/iGfX+CWmzHZbzK/30xSJXgPm7V+xOsizAiNiJmWhlD9sejOs5lgmdLufdBgD Lkb/HhIKeM/WZCJuMvVK/Pac/wlUTpqYxN2yjcGlx6EzBhVQJAVRXdg471FQ8ddPwdUW OIu150u1ZFqrIMb0wQXrVfozkIoHC2kmdZ/0dc5GqaWusb59Kf6UxrjwZRxIkbqzc6CE ulRA== 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 1-v6si18392477plr.483.2018.05.23.10.41.39; Wed, 23 May 2018 10:41:54 -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 S933880AbeEWRl1 (ORCPT + 99 others); Wed, 23 May 2018 13:41:27 -0400 Received: from mx2.suse.de ([195.135.220.15]:49311 "EHLO mx2.suse.de" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S932667AbeEWRl0 (ORCPT ); Wed, 23 May 2018 13:41:26 -0400 X-Virus-Scanned: by amavisd-new at test-mx.suse.de Received: from relay2.suse.de (charybdis-ext.suse.de [195.135.220.254]) by mx2.suse.de (Postfix) with ESMTP id 2192CAB3E; Wed, 23 May 2018 17:41:25 +0000 (UTC) Date: Wed, 23 May 2018 10:25:00 -0700 From: Davidlohr Bueso To: akpm@linux-foundation.org, torvalds@linux-foundation.org Cc: manfred@colorfullife.com, guillaume.knispel@supersonicimagine.com, linux-api@vger.kernel.org, linux-kernel@vger.kernel.org Subject: semantics of rhashtable and sysvipc Message-ID: <20180523172500.anfvmjtumww65ief@linux-n805> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii; format=flowed Content-Disposition: inline User-Agent: NeoMutt/20170421 (1.8.2) Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Hi, 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. I see two possible fixes. The first is to return the proper error code if !tables_initialized, however, I'm not sure how we want to deal with the EINVAL cases when rhashtable_init() fails. Userspace has no reason to know about this. The ENOMEM case I guess makes sense ok. The second alternative would be to add a BUG_ON() if the initialization fails and we get rid of all the tables_initialized hack. I know Linus isn't fond of this, and in the past ipc has gotten rid of BUG_ON usage in ipc because of this. However I mention it because there are other core areas that do this (or call panic() straightaway). Ie in networking: sock_diag_init() and netlink_proto_init(). Thoughts? Thanks, Davidlohr