Received: by 2002:a4a:301c:0:0:0:0:0 with SMTP id q28-v6csp802665oof; Tue, 25 Sep 2018 05:00:44 -0700 (PDT) X-Google-Smtp-Source: ACcGV603SqZhYfZRlZdjdB/FknIMIGxuBRrwb1/TqhhXAePqRN21Xyd2jph4oD9HZjxp7Kco+Ztg X-Received: by 2002:a63:7b09:: with SMTP id w9-v6mr742402pgc.385.1537876844339; Tue, 25 Sep 2018 05:00:44 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1537876844; cv=none; d=google.com; s=arc-20160816; b=CIGGLM/l3kfIP52kkGW9Y2HMdpRtQzi7TTdoi2D0kTJUYobkF++YFhMtp8gWVXYHAC +4aD3qytxQl9poNGdLKycBJZu0elDBJ5WLfIPaB0m3XiitZTUkFkWleMXyyIXG9x0GFN x1H5jeltEXkS6xpEET7c9K2Poyio0gY2+gsaqit6BU2l++kUse8xLnWdxdW5Nh403E91 JMuggSP1ptfuM9SwHuYRhkwGruztsamqEzxPOtB9UPTw7IRt1wwhXeiPvQ3YneqpWCFa Dq+cyV3cDDQolpL2VRH3SBnnus3agXEQ/GgjRLkJBl9yDq2duDH95MS6Lfop0dy8B3Yn 79Fg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:cc:to:subject:message-id:date:from :in-reply-to:references:mime-version; bh=0mkvli9SxU87U7/v9xrlIcAk2jawKRHDYgJeiFV41Y4=; b=rN0tTJgerAIOM3ANOY0Me1NdS0x8zXM6kH7gz+GkMkLn4S7FVpVuzgYSg/S0GWSN6Y IdsvZvCQajUnYiPHN7+xP2VRYvl1IZdnA/YFXxoM+Tc+USbhSkppHyqSrNPyYNWJOYFw JtWNPRHiVxL6oiQmtutBIWlogfuekd/keQ9xq6AiBRlK/lxHKOcQduM+Whq0kIchLUfi IH630yF9FQstFl1pg6hMSp6ZCk4z9VPogKovaLy1qS+jLhIhrqdUE8Cot2J8aMWcirCd +edBQXolgLHDIpAvMJdJb12oNxSfoWK39M0aDmIGnly7FT29dv6EqVdlHkCYwD34DnFY 7f4Q== 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 cb8-v6si1905906plb.178.2018.09.25.05.00.27; Tue, 25 Sep 2018 05:00:44 -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 S1728199AbeIYSHe (ORCPT + 99 others); Tue, 25 Sep 2018 14:07:34 -0400 Received: from mail-qk1-f196.google.com ([209.85.222.196]:45593 "EHLO mail-qk1-f196.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1727114AbeIYSHd (ORCPT ); Tue, 25 Sep 2018 14:07:33 -0400 Received: by mail-qk1-f196.google.com with SMTP id q20-v6so8930384qkc.12 for ; Tue, 25 Sep 2018 05:00:21 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:mime-version:references:in-reply-to:from:date :message-id:subject:to:cc; bh=0mkvli9SxU87U7/v9xrlIcAk2jawKRHDYgJeiFV41Y4=; b=EA8I0OLnm6YpRg+DXEfXi+Cu87kPpeCDjuN+85aB2Eno3IGJRRtHpUG80bmLLC7Z8T f82QRbxsqv4Fwox+LCsUirDZ7sqzBYw/3fTxzTK8GK+tEN3O5gCmosjLNBLh7/ZT0tIQ i8geBcpu8VUjtFeI4tCsLODW/0s15Q4X9oQ1mob52bTs587z93pj+LrZkYZ1YEY2IRb/ FagEHwJxPlNauC86H84MkNTcmZsbHmWZ2cuXXG9/u10b0Qwg6bLSjt+0wwmhYBtkA9cz ScKQnjxlz+Xy48h2xUtr4wTEzTM0Qau4pT7tRLpjHhWbSmd2Usdns0Df32Njh9RLSe6L 4g+A== X-Gm-Message-State: ABuFfogFvIvaC83QWNDmv+6cRV0Bx9VEhSFtObJ9lzA2kPlSpga7+Sk2 LXHD52v08SZIwDk5/hPKAx9r2WgLQOl/hVFhfdI= X-Received: by 2002:a37:c542:: with SMTP id p63-v6mr432855qki.330.1537876820426; Tue, 25 Sep 2018 05:00:20 -0700 (PDT) MIME-Version: 1.0 References: <20180823024051.GC13343@shao2-debian> <20180823041434.GC3677@linux-r8p5> <20180824030920.GD3677@linux-r8p5> In-Reply-To: <20180824030920.GD3677@linux-r8p5> From: Arnd Bergmann Date: Tue, 25 Sep 2018 14:00:03 +0200 Message-ID: Subject: Re: [PATCH] ipc/shm: properly return EIDRM in shm_lock() To: Davidlohr Bueso Cc: rong.a.chen@intel.com, Stephen Rothwell , dbueso@suse.de, manfred@colorfullife.com, Dmitry Vyukov , Herbert Xu , Kees Cook , Michael Kerrisk , Michal Hocko , Andrew Morton , Linux Kernel Mailing List , LKP , ltp@lists.linux.it Content-Type: text/plain; charset="UTF-8" Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Fri, Aug 24, 2018 at 5:09 AM Davidlohr Bueso wrote: > > When getting rid of the general ipc_lock(), this was missed > furthermore, making the comment around the ipc object validity > check bogus. Under EIDRM conditions, callers will in turn not > see the error and continue with the operation. > > Fixes: 82061c57ce9 (ipc: drop ipc_lock()) > Signed-off-by: Davidlohr Bueso > --- Oddly, this change introduces a gcc warning in some configurations (i.e. with randstruct enabled): ipc/shm.c: In function 'shm_lock': ipc/shm.c:209:9: note: randstruct: casting between randomized structure pointer types (ssa): 'struct shmid_kernel' and 'struct kern_ipc_perm' return (void *)ipcp; ^~~~~~~~~~~~ Not sure why we didn't see that warning before, probably it ended up making its own thing when the return code was uninitialized. The change below gets rid of the warning, but is a bit ugly. Arnd diff --git a/ipc/shm.c b/ipc/shm.c index fe3c42e66a48..922012a745e5 100644 --- a/ipc/shm.c +++ b/ipc/shm.c @@ -180,10 +180,12 @@ static inline struct shmid_kernel *shm_obtain_object_check(struct ipc_namespace static inline struct shmid_kernel *shm_lock(struct ipc_namespace *ns, int id) { struct kern_ipc_perm *ipcp; + int ret; rcu_read_lock(); ipcp = ipc_obtain_object_idr(&shm_ids(ns), id); - if (IS_ERR(ipcp)) + ret = PTR_ERR_OR_ZERO(ipcp); + if (ret) goto err; ipc_lock_object(ipcp); @@ -199,14 +201,14 @@ static inline struct shmid_kernel *shm_lock(struct ipc_namespace *ns, int id) } ipc_unlock_object(ipcp); - ipcp = ERR_PTR(-EIDRM); + ret = -EIDRM; err: rcu_read_unlock(); /* * Callers of shm_lock() must validate the status of the returned ipc * object pointer and error out as appropriate. */ - return (void *)ipcp; + return ERR_PTR(ret); } static inline void shm_lock_by_ptr(struct shmid_kernel *ipcp)