Received: by 10.192.165.148 with SMTP id m20csp685820imm; Wed, 2 May 2018 07:13:43 -0700 (PDT) X-Google-Smtp-Source: AB8JxZrkMiaMRu5302E1UOKGL2Msp+kpBn30mxMwo/AuhUCtkauhZwLRlZS9jDCXWQdXKCdNbrI4 X-Received: by 2002:a63:6f41:: with SMTP id k62-v6mr16108128pgc.73.1525270423562; Wed, 02 May 2018 07:13:43 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1525270423; cv=none; d=google.com; s=arc-20160816; b=lKH7Ijq4/On3iZhN2hhON5mg6pXHRn5pAAY0AqRFYoE6EPRcDP2t1pnVhaiK1Sl2KD pZSHcuOZDVksJT041LwBFSTptZOZ1qZoBN/HpjLiin18eolp6oRWiRsmN+2dXepxdJ2N Czb6BVRgKpu6W5+FeUaXAOVnc6kYIglMgE/edj783LSaPMPm5WtogC+DFU8yoPzRSbil B35tq6olCh702lx7+JoLW6UClv52FjeajcvpvVsTaDcG5zSmzjco5uOBSkZKl+CAW2FB vbklWqaR/FNcBHzhonmGOyRD6E3A5x2hAi1J0CVkfYnVgnxv+09LxpK4JzJXqKeXlewx oinw== 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 :references:in-reply-to:mime-version:arc-authentication-results; bh=TUoexAddJf85B3Vq3H0MFp2n+Nav2UNKP22C6jOntpw=; b=q4qtX28HQb59mxzdbsAeM3r22esMCtjX/sRlQ21ChYCII01KkX+UMUmZ+R7MqrMlt4 8HMkhpirWbToU7YOsLZZSzgjeSHsI42c5VoW6FFeeaNIlBsKGIk/WlVOz37ApfV68wPU 2zBwuvE9LcJ66/uxN333yMqA14VSgi1npwL2jvY3T0JQZ4CURwmYSZ0IFYvwBmfoQ7M1 +6qyrw+i3z/K5puYzXUfSQsCySd9eGuDSA/iIkoE0Xk7SMa7hB/mR/NJjLIXFBgZJ9cq SsMEoqaqsh/yUG+F8lAQAnXTWQkt+DmHC65j5fdauMVwkjtJVmlre5+TQ/RvMA/EYOuo Q9QQ== 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; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=canonical.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id p11-v6si2905435pgn.348.2018.05.02.07.12.58; Wed, 02 May 2018 07:13:43 -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; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=canonical.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1751484AbeEBOMf (ORCPT + 99 others); Wed, 2 May 2018 10:12:35 -0400 Received: from youngberry.canonical.com ([91.189.89.112]:52712 "EHLO youngberry.canonical.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1750898AbeEBOMV (ORCPT ); Wed, 2 May 2018 10:12:21 -0400 Received: from mail-ua0-f200.google.com ([209.85.217.200]) by youngberry.canonical.com with esmtps (TLS1.0:RSA_AES_128_CBC_SHA1:16) (Exim 4.76) (envelope-from ) id 1fDsUW-0001nu-Vc for linux-kernel@vger.kernel.org; Wed, 02 May 2018 14:12:21 +0000 Received: by mail-ua0-f200.google.com with SMTP id i14so13325115uan.10 for ; Wed, 02 May 2018 07:12:20 -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:in-reply-to:references:from:date :message-id:subject:to:cc; bh=TUoexAddJf85B3Vq3H0MFp2n+Nav2UNKP22C6jOntpw=; b=asIz4Zoakw0mWWV3e0qrH+i0p/AYuksNIg5YqFgA1IEfdNghEUlJ84iYECZlN5fOys xC2ezFjtbh6z1jhRaYcnH0AwSIOlcKOGrd0baWD3fuj4oxjZBmVrACLlQ1kUpg407VBo kZMSos7+wySzw6uBLdBMnhULlg4v1bTnh+FzYIgdYJURgnqrooXe18bdCra/IIucrBd2 FuxkI3ZjfThK/PiB5cNAC8FyEXYTFsRotjAassmzhlj5W1dfotQ9j1zTTStjMa2MpWD0 cA6KmRiGqRXgDK2wOfk1NcqBGcPEJeXIDvygCvBdiL9mRKO4CbaXhDWLIiJJkhq8Oqtu Wspg== X-Gm-Message-State: ALQs6tA/DEWa/NB+iEy/m0oKPHhVGGFdADg2wFHXZSp2euaZJ9gSwVlI moJQPoJzcytH/dUYV1+q/SO9B8KIJUFOmFJjtJac149as5seRYxjjD/okeawyCsuNto0b6MIvOZ Y8hNOiRmMm94Y8rwDhSwBJC+KzSIvAwRdq+5RbGimocG0Vgo9r22Ct7mkaw== X-Received: by 10.176.80.161 with SMTP id c30mr439734uaa.201.1525270340015; Wed, 02 May 2018 07:12:20 -0700 (PDT) X-Received: by 10.176.80.161 with SMTP id c30mr439701uaa.201.1525270339649; Wed, 02 May 2018 07:12:19 -0700 (PDT) MIME-Version: 1.0 Received: by 10.103.171.1 with HTTP; Wed, 2 May 2018 07:12:18 -0700 (PDT) In-Reply-To: <20180419024641.24213-1-marcos.souza.org@gmail.com> References: <20180419024641.24213-1-marcos.souza.org@gmail.com> From: Christian Brauner Date: Wed, 2 May 2018 16:12:18 +0200 Message-ID: Subject: Re: [PATCH -next] user_namespace: Replace gotos with return statements To: Marcos Paulo de Souza Cc: linux-next@vger.kernel.org, "Eric W. Biederman" , Mark Rutland , Ingo Molnar , Serge Hallyn , Seth Forshee , Linux Kernel Mailing List 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 Wed, Apr 18, 2018 at 11:46:38PM -0300, Marcos Paulo de Souza wrote: > Found while inspecting the code that handles the setgroups procfs file. This is not really improving anything so I unfortunately don't really see why we should take this. Christian > > Signed-off-by: Marcos Paulo de Souza > --- > Tested locally setting up a new userns, and setting setgroups as deny and allow, > worked as before. > > kernel/user_namespace.c | 20 +++++++------------- > 1 file changed, 7 insertions(+), 13 deletions(-) > > diff --git a/kernel/user_namespace.c b/kernel/user_namespace.c > index 246d4d4ce5c7..64a01254ac6b 100644 > --- a/kernel/user_namespace.c > +++ b/kernel/user_namespace.c > @@ -1142,22 +1142,18 @@ ssize_t proc_setgroups_write(struct file *file, const char __user *buf, > struct user_namespace *ns = seq->private; > char kbuf[8], *pos; > bool setgroups_allowed; > - ssize_t ret; > > /* Only allow a very narrow range of strings to be written */ > - ret = -EINVAL; > if ((*ppos != 0) || (count >= sizeof(kbuf))) > - goto out; > + return -EINVAL; > > /* What was written? */ > - ret = -EFAULT; > if (copy_from_user(kbuf, buf, count)) > - goto out; > + return -EFAULT; > kbuf[count] = '\0'; > pos = kbuf; > > /* What is being requested? */ > - ret = -EINVAL; > if (strncmp(pos, "allow", 5) == 0) { > pos += 5; > setgroups_allowed = true; > @@ -1167,14 +1163,13 @@ ssize_t proc_setgroups_write(struct file *file, const char __user *buf, > setgroups_allowed = false; > } > else > - goto out; > + return -EINVAL; > > /* Verify there is not trailing junk on the line */ > pos = skip_spaces(pos); > if (*pos != '\0') > - goto out; > + return -EINVAL; > > - ret = -EPERM; > mutex_lock(&userns_state_mutex); > if (setgroups_allowed) { > /* Enabling setgroups after setgroups has been disabled > @@ -1194,12 +1189,11 @@ ssize_t proc_setgroups_write(struct file *file, const char __user *buf, > > /* Report a successful write */ > *ppos = count; > - ret = count; > -out: > - return ret; > + return count; > + > out_unlock: > mutex_unlock(&userns_state_mutex); > - goto out; > + return -EPERM; > } > > bool userns_may_setgroups(const struct user_namespace *ns) > -- > 2.14.3 >