From patchwork Thu Apr 21 23:29:39 2016 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: NeilBrown X-Patchwork-Id: 8904951 Return-Path: X-Original-To: patchwork-linux-nfs@patchwork.kernel.org Delivered-To: patchwork-parsemail@patchwork1.web.kernel.org Received: from mail.kernel.org (mail.kernel.org [198.145.29.136]) by patchwork1.web.kernel.org (Postfix) with ESMTP id C598D9F39A for ; Thu, 21 Apr 2016 23:29:51 +0000 (UTC) Received: from mail.kernel.org (localhost [127.0.0.1]) by mail.kernel.org (Postfix) with ESMTP id F25542021B for ; Thu, 21 Apr 2016 23:29:50 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id 29406201F5 for ; Thu, 21 Apr 2016 23:29:49 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1751931AbcDUX3s (ORCPT ); Thu, 21 Apr 2016 19:29:48 -0400 Received: from mx2.suse.de ([195.135.220.15]:49302 "EHLO mx2.suse.de" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1751760AbcDUX3r (ORCPT ); Thu, 21 Apr 2016 19:29:47 -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 F3FBFABA6; Thu, 21 Apr 2016 23:29:43 +0000 (UTC) From: NeilBrown To: Steve Dickson Date: Fri, 22 Apr 2016 09:29:39 +1000 Subject: [PATCH/nfs-utils] mount: run START_STATD fully as root User-Agent: Notmuch/0.20.2 (http://notmuchmail.org) Emacs/24.5.1 (x86_64-suse-linux-gnu) cc: NFS List Message-ID: <87shyey1zw.fsf@notabene.neil.brown.name> MIME-Version: 1.0 Sender: linux-nfs-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-nfs@vger.kernel.org X-Spam-Status: No, score=-7.9 required=5.0 tests=BAYES_00, RCVD_IN_DNSWL_HI, RP_MATCHES_RCVD, T_TVD_MIME_EPI, UNPARSEABLE_RELAY autolearn=ham version=3.3.1 X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on mail.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP If a "user" mount is the first NFSv3 mount, mount.nfs will be running setuid to root (with non-root as the real-uid) when it executes START_STATD. start-statd is a shell script and many shells refuse to run setuid, dropping privileges immediately. This results in start-statd running as an unprivileged user and so statd fails to start. To fix this, call "setuid(0)" to set real uid to zero. Also call "setgid(0)" for consistency. The behaviour of a shell can often be affected by the environment, such as the "shell functions" that bash includes from the environment. To avoid the user being able to pass such environment to the shell, explicitly pass an empty environment. The start-statd script explicitly sets the PATH which is all it really needs. Signed-off-by: NeilBrown diff --git a/utils/mount/network.c b/utils/mount/network.c index 7240ca7bcdc4..0d12613e86a4 100644 --- a/utils/mount/network.c +++ b/utils/mount/network.c @@ -795,6 +795,7 @@ int start_statd(void) if (S_ISREG(stb.st_mode) && (stb.st_mode & S_IXUSR)) { int cnt = STATD_TIMEOUT * 10; int status = 0; + char * const envp[1] = { NULL }; const struct timespec ts = { .tv_sec = 0, .tv_nsec = 100000000, @@ -802,7 +803,9 @@ int start_statd(void) pid_t pid = fork(); switch (pid) { case 0: /* child */ - execl(START_STATD, START_STATD, NULL); + setgid(0); + setuid(0); + execle(START_STATD, START_STATD, NULL, envp); exit(1); case -1: /* error */ nfs_error(_("%s: fork failed: %s"),