Received: by 10.223.185.116 with SMTP id b49csp6402204wrg; Wed, 28 Feb 2018 08:49:48 -0800 (PST) X-Google-Smtp-Source: AH8x2275VY5bqUPmUTCMRFR2v9HMlVjaIHH2h/3IJBIplBpw7MGBUFVnkB78PiojWKy1Uvcn/67n X-Received: by 2002:a17:902:e83:: with SMTP id 3-v6mr18536066plx.158.1519836588453; Wed, 28 Feb 2018 08:49:48 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1519836588; cv=none; d=google.com; s=arc-20160816; b=hHrFY2MHxEohagM1Dh3vvrX+AcC//63xRZPQORnp7PXXKtB22kFbkD/zpRwWpbbCOs P/racmM4SEoaOTYvBdAn56GIX3pM4CMwPFQrRIwJJR1jTkS88ashevUh3fdPBgEx70fG EWxk792AYW4ZP4aoeUH5Y7c3GugBVG3SLwu4GmRp6ZfDhzg3XbB4AVhZAuVEenb5aWeR OWHKkQQt2umHhUgegfxPCLN0Dp22BtGb4vDM/krOnJOS2bjrbidKTvDElB7FJGAbLemk T2U4LZXFMetZVoD22Q5O241s2uj5sHLK2M07B+iTWXRbYH/I09xCXb+6Ah4eDW5tun9w oZCg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:in-reply-to:subject:message-id:date:cc:to :from:mime-version:content-transfer-encoding:content-disposition :arc-authentication-results; bh=30/lAAojNiu7P1h876qVMz5Pog0rOR3fOjAHQ3r++oY=; b=YH1oRtlnTQURWZ7mbSPl7hp050WaLuLkznraADGFmnX+4Xfjv/uSIvfALAPURoAdYY JMixraCSO5X3tgp57erH+EXMt5wK2IoLHDrabsmoUpbVB6LFfB+zWCO4BvNB6fsFWl69 62kSWyOMAtvK3BP05kBJkxoWydAhBIv+WE8L6u99Z1t2u3Qwn1k2yxOdz+9uyOY/Ljd1 CcsokDD59dYsjtXYJ4t3L8Qn2RhdBmUHZinwrCaWbG9YfqG9AikXV9AYy55Wbe26pRsa BAERrgZvuFPZKzjXG+CRfjJuSyedlWa/gGHik90CoDBSXSnDZzF3NIRW5s9neDMQNCAu YYwQ== 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 3-v6si1516663plr.440.2018.02.28.08.49.33; Wed, 28 Feb 2018 08:49:48 -0800 (PST) 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 S934306AbeB1P6u (ORCPT + 99 others); Wed, 28 Feb 2018 10:58:50 -0500 Received: from shadbolt.e.decadent.org.uk ([88.96.1.126]:34578 "EHLO shadbolt.e.decadent.org.uk" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S934293AbeB1P6r (ORCPT ); Wed, 28 Feb 2018 10:58:47 -0500 Received: from [2a02:8011:400e:2:6f00:88c8:c921:d332] (helo=deadeye) by shadbolt.decadent.org.uk with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.84_2) (envelope-from ) id 1er3Ys-0006Xk-HC; Wed, 28 Feb 2018 15:22:30 +0000 Received: from ben by deadeye with local (Exim 4.90_1) (envelope-from ) id 1er3Yg-000068-O0; Wed, 28 Feb 2018 15:22:18 +0000 Content-Type: text/plain; charset="UTF-8" Content-Disposition: inline Content-Transfer-Encoding: 8bit MIME-Version: 1.0 From: Ben Hutchings To: linux-kernel@vger.kernel.org, stable@vger.kernel.org CC: akpm@linux-foundation.org, "Linus Torvalds" , "Ben Hutchings" , "J. Bruce Fields" Date: Wed, 28 Feb 2018 15:20:18 +0000 Message-ID: X-Mailer: LinuxStableQueue (scripts by bwh) Subject: [PATCH 3.16 115/254] nfsd: auth: Fix gid sorting when rootsquash enabled In-Reply-To: X-SA-Exim-Connect-IP: 2a02:8011:400e:2:6f00:88c8:c921:d332 X-SA-Exim-Mail-From: ben@decadent.org.uk X-SA-Exim-Scanned: No (on shadbolt.decadent.org.uk); SAEximRunCond expanded to false Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org 3.16.55-rc1 review patch. If anyone has any objections, please let me know. ------------------ From: Ben Hutchings commit 1995266727fa8143897e89b55f5d3c79aa828420 upstream. Commit bdcf0a423ea1 ("kernel: make groups_sort calling a responsibility group_info allocators") appears to break nfsd rootsquash in a pretty major way. It adds a call to groups_sort() inside the loop that copies/squashes gids, which means the valid gids are sorted along with the following garbage. The net result is that the highest numbered valid gids are replaced with any lower-valued garbage gids, possibly including 0. We should sort only once, after filling in all the gids. Fixes: bdcf0a423ea1 ("kernel: make groups_sort calling a responsibility ...") Signed-off-by: Ben Hutchings Acked-by: J. Bruce Fields Signed-off-by: Linus Torvalds [bwh: Backported to 3.16: adjust context] Signed-off-by: Ben Hutchings --- fs/nfsd/auth.c | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) --- a/fs/nfsd/auth.c +++ b/fs/nfsd/auth.c @@ -59,10 +59,10 @@ int nfsd_setuser(struct svc_rqst *rqstp, GROUP_AT(gi, i) = exp->ex_anon_gid; else GROUP_AT(gi, i) = GROUP_AT(rqgi, i); - - /* Each thread allocates its own gi, no race */ - groups_sort(gi); } + + /* Each thread allocates its own gi, no race */ + groups_sort(gi); } else { gi = get_group_info(rqgi); }