Received: by 2002:ac0:a5a7:0:0:0:0:0 with SMTP id m36-v6csp989994imm; Fri, 17 Aug 2018 09:57:03 -0700 (PDT) X-Google-Smtp-Source: AA+uWPwS7VX0MDLWrRLNb/paHumeClTzyIeb1uMtWzCxz7FnQDEcaisA64pceoGX/JWl1gvoAaHG X-Received: by 2002:a17:902:8601:: with SMTP id f1-v6mr34715217plo.61.1534525023893; Fri, 17 Aug 2018 09:57:03 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1534525023; cv=none; d=google.com; s=arc-20160816; b=I620pF+I92T0HK0Q99QS2ETM3KwU/NMwDZwTtQN7HXBs3mM47VzG1zmHEKlB21xiR3 NAmxE2wRE11U/nVumTeDq5dT0Jvy1v9GFp5SukXpbJdHcEQ9CktKaaKqYqy1dB4VNFeU 7LohFug6y832ku0FkBHNXrBZo4KGqCDWgi3bk6Tnn3eHky2uBICdUQxxQYrCbLVxPTID +TA4NHYvOEV9Cm4ffesNvqgmKQ5vjI1fn1rpc26H1ftHknr3l5Tp62SpemFWbwUcUxTf UyGP+bo8GizTQvC3EgA6ZOHOToxyNchdA5pVwGbAOsSNpIl/2tfjgRaRjQ6cgWo89Uaz 3wOw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:user-agent:in-reply-to :content-disposition:mime-version:references:message-id:subject:cc :to:from:date:arc-authentication-results; bh=jWYd3MtZLg4cnyoPood/P81PIe+kV/z09+VdnI+3vLQ=; b=auKPvlJvvzo2pbnDs6ae4mXJAJl4ixc3uGBT5C64r670uUJJGCUYxoSVTifY3TGt5q SuMEKTMiE4Dij1xd3pR6lM2KvBSFreEb3AmhLbnGwB2QR6H3tT2Q+Q61IsLSrNqQBFqW WsC1uNLK7rL0SmPzGMg1EUez4w2lJrIVlDyf6gZ5RJkIE1RmeIA3CxTS3shpBn/voU5S DLCgC2qQwBYvn6ksUdvc18NiTf0B/1Yr0NytXY2GFZSoxXd1a0t7Q5FMTpbjKqQC6Saj eQsPG7klI/tYAIiavoLg+D2Whxt5R57RCiCHNFu4Kwk5eiG6Pt9hf4rabsTmQT43Wtmo Rv4A== 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 h3-v6si2683486plh.28.2018.08.17.09.56.25; Fri, 17 Aug 2018 09:57:03 -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 S1727880AbeHQT5w (ORCPT + 99 others); Fri, 17 Aug 2018 15:57:52 -0400 Received: from mx2.suse.de ([195.135.220.15]:50974 "EHLO mx1.suse.de" rhost-flags-OK-OK-OK-FAIL) by vger.kernel.org with ESMTP id S1727218AbeHQT5w (ORCPT ); Fri, 17 Aug 2018 15:57:52 -0400 X-Virus-Scanned: by amavisd-new at test-mx.suse.de Received: from relay1.suse.de (unknown [195.135.220.254]) by mx1.suse.de (Postfix) with ESMTP id D3545AD48; Fri, 17 Aug 2018 16:53:44 +0000 (UTC) Date: Fri, 17 Aug 2018 09:53:34 -0700 From: Davidlohr Bueso To: Waiman Long Cc: "Luis R. Rodriguez" , Kees Cook , Andrew Morton , Jonathan Corbet , linux-kernel@vger.kernel.org, linux-fsdevel@vger.kernel.org, linux-doc@vger.kernel.org, Al Viro , Matthew Wilcox , "Eric W. Biederman" , Takashi Iwai , Davidlohr Bueso , manfred@colorfullife.com Subject: Re: [PATCH v8 2/5] ipc: IPCMNI limit check for semmni Message-ID: <20180817165334.GA3677@linux-r8p5> References: <1529317698-16575-1-git-send-email-longman@redhat.com> <1529317698-16575-3-git-send-email-longman@redhat.com> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii; format=flowed Content-Disposition: inline In-Reply-To: <1529317698-16575-3-git-send-email-longman@redhat.com> User-Agent: Mutt/1.10.1 (2018-07-13) Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Mon, 18 Jun 2018, Waiman Long wrote: >For SysV semaphores, the semmni value is the last part of the 4-element >sem number array. To make semmni behave in a similar way to msgmni and >shmmni, we can't directly use the _minmax handler. Instead, a special >sem specific handler is added to check the last argument to make sure >that it is limited to the [0, IPCMNI] range. An error will be returned >if this is not the case. > >Signed-off-by: Waiman Long Reviewed-by: Davidlohr Bueso >--- > ipc/ipc_sysctl.c | 23 ++++++++++++++++++++++- > ipc/util.h | 9 +++++++++ > 2 files changed, 31 insertions(+), 1 deletion(-) > >diff --git a/ipc/ipc_sysctl.c b/ipc/ipc_sysctl.c >index f87cb29..49f9bf4 100644 >--- a/ipc/ipc_sysctl.c >+++ b/ipc/ipc_sysctl.c >@@ -88,12 +88,33 @@ static int proc_ipc_auto_msgmni(struct ctl_table *table, int write, > return proc_dointvec_minmax(&ipc_table, write, buffer, lenp, ppos); > } > >+static int proc_ipc_sem_dointvec(struct ctl_table *table, int write, >+ void __user *buffer, size_t *lenp, loff_t *ppos) >+{ >+ int ret, semmni; >+ struct ipc_namespace *ns = current->nsproxy->ipc_ns; >+ >+ semmni = ns->sem_ctls[3]; >+ ret = proc_ipc_dointvec(table, write, buffer, lenp, ppos); >+ >+ if (!ret) >+ ret = sem_check_semmni(current->nsproxy->ipc_ns); >+ >+ /* >+ * Reset the semmni value if an error happens. >+ */ >+ if (ret) >+ ns->sem_ctls[3] = semmni; >+ return ret; >+} >+ > #else > #define proc_ipc_doulongvec_minmax NULL > #define proc_ipc_dointvec NULL > #define proc_ipc_dointvec_minmax NULL > #define proc_ipc_dointvec_minmax_orphans NULL > #define proc_ipc_auto_msgmni NULL >+#define proc_ipc_sem_dointvec NULL > #endif > > static int zero; >@@ -175,7 +196,7 @@ static int proc_ipc_auto_msgmni(struct ctl_table *table, int write, > .data = &init_ipc_ns.sem_ctls, > .maxlen = 4*sizeof(int), > .mode = 0644, >- .proc_handler = proc_ipc_dointvec, >+ .proc_handler = proc_ipc_sem_dointvec, > }, > #ifdef CONFIG_CHECKPOINT_RESTORE > { >diff --git a/ipc/util.h b/ipc/util.h >index 0aba323..8e9c52c 100644 >--- a/ipc/util.h >+++ b/ipc/util.h >@@ -218,6 +218,15 @@ int ipcget(struct ipc_namespace *ns, struct ipc_ids *ids, > void free_ipcs(struct ipc_namespace *ns, struct ipc_ids *ids, > void (*free)(struct ipc_namespace *, struct kern_ipc_perm *)); > >+static inline int sem_check_semmni(struct ipc_namespace *ns) { >+ /* >+ * Check semmni range [0, IPCMNI] >+ * semmni is the last element of sem_ctls[4] array >+ */ >+ return ((ns->sem_ctls[3] < 0) || (ns->sem_ctls[3] > IPCMNI)) >+ ? -ERANGE : 0; >+} >+ > #ifdef CONFIG_COMPAT > #include > struct compat_ipc_perm { >-- >1.8.3.1 >