Received: by 2002:a05:6a10:6744:0:0:0:0 with SMTP id w4csp3997365pxu; Mon, 12 Oct 2020 07:00:46 -0700 (PDT) X-Google-Smtp-Source: ABdhPJxfZKDKKi78+rR+AXDYlWlV7EuSNwxiXXulrvjH8mkbw4w1w8X8mqC9hlofof+dmwOlXOjG X-Received: by 2002:a67:8802:: with SMTP id k2mr13758068vsd.42.1602511245843; Mon, 12 Oct 2020 07:00:45 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1602511245; cv=none; d=google.com; s=arc-20160816; b=rj7gndgZVLbkx3mY15+6q+Dxu5DvmT5FVG+5wck5IhAKx/dX1LqlPDeasduYQOvZzf sRf1s+p2tJndRWLTcTuBxiEcJZXhS3JEDLRdpxmqaWnJ7dex+tspin8H6xlhGiftRY8+ TW8MiVGflXvhgttHY1Zhz6f3Zof4AJ6XApgk3qp8VF8cBLfxkHgQIiogU/FUFdnnzQR0 M8FA0ns5x1YaFiw7sSfIgCzCUSbUdmLQGO5kaSXU0sph+kh0zG6IdSmzirTh4mWdUJIW sQGreaewieSOTxUYk5fZUyEeQ5YRXPM0vzvH3GORDIRhDpfvm/ta99I8KoOznn4CZMEy RyRw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :user-agent:references:in-reply-to:message-id:date:subject:cc:to :from:dkim-signature; bh=NMPBnaA01ZWRV1NvF9qHdq44nmMjgRMHwWh3gD9FnKM=; b=0JST95tVu6kxykp2k78Qn3Z7sPP39/mlqhjBYYouicZMzUes6gQH2ugFdDMYl3Hy6t koqRlPrGP47d6rsAjYVRqDCQkyXEOeGjttxNmTFug3X8+vl1jsPNhkLLXju9WX1P1t6j TU15vMvMvp5Ntg/NyMcphAsZvCv2eb+h+Dag2wneVuKOEYsZwZeGNllaQQ3p8cAuoCE5 G53hGBRIwjeWs7up0jsZK9FUDy9OIUOPei/GIMSuraI9Up5r6pOL4othfTSas/s38tkH 37pFZ8K6WVGCR1MH7GtCpk40bKIftGdYRiBiWGZjLHGEkFkVFn6DPv0/Hfb/HV8FAG3G nFGg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=default header.b=wpzHvXZK; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=linuxfoundation.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id m22si12142142eds.570.2020.10.12.07.00.22; Mon, 12 Oct 2020 07:00:45 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) client-ip=23.128.96.18; Authentication-Results: mx.google.com; dkim=pass header.i=@kernel.org header.s=default header.b=wpzHvXZK; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=linuxfoundation.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S2390214AbgJLN41 (ORCPT + 99 others); Mon, 12 Oct 2020 09:56:27 -0400 Received: from mail.kernel.org ([198.145.29.99]:48538 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S2389574AbgJLNo6 (ORCPT ); Mon, 12 Oct 2020 09:44:58 -0400 Received: from localhost (83-86-74-64.cable.dynamic.v4.ziggo.nl [83.86.74.64]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPSA id AB43C22227; Mon, 12 Oct 2020 13:44:00 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1602510241; bh=kj6sxvvaay1N0knIRsy0kDpNRDM8VKzidKLrpRkenaw=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=wpzHvXZKjvQgs/qsrjftfpSLr6NpeqeODmspYuodjnl8zfE/qrsb1FB4Ta/ODwAb8 77dp74LrJND+XBdY7SuD4QWm648Wl/cQAaOu1SeIKeQuWcPzAG9Tpdd+Uh050GJivG U24D6mL24oeYfTTyhPzbftwaXzyNNeiwYcQfIWVI= From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , stable@vger.kernel.org, Vegard Nossum , Al Viro , "Eric W. Biederman" , Linus Torvalds Subject: [PATCH 5.8 015/124] usermodehelper: reset umask to default before executing user process Date: Mon, 12 Oct 2020 15:30:19 +0200 Message-Id: <20201012133147.592477672@linuxfoundation.org> X-Mailer: git-send-email 2.28.0 In-Reply-To: <20201012133146.834528783@linuxfoundation.org> References: <20201012133146.834528783@linuxfoundation.org> User-Agent: quilt/0.66 MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org From: Linus Torvalds commit 4013c1496c49615d90d36b9d513eee8e369778e9 upstream. Kernel threads intentionally do CLONE_FS in order to follow any changes that 'init' does to set up the root directory (or cwd). It is admittedly a bit odd, but it avoids the situation where 'init' does some extensive setup to initialize the system environment, and then we execute a usermode helper program, and it uses the original FS setup from boot time that may be very limited and incomplete. [ Both Al Viro and Eric Biederman point out that 'pivot_root()' will follow the root regardless, since it fixes up other users of root (see chroot_fs_refs() for details), but overmounting root and doing a chroot() would not. ] However, Vegard Nossum noticed that the CLONE_FS not only means that we follow the root and current working directories, it also means we share umask with whatever init changed it to. That wasn't intentional. Just reset umask to the original default (0022) before actually starting the usermode helper program. Reported-by: Vegard Nossum Cc: Al Viro Acked-by: Eric W. Biederman Signed-off-by: Linus Torvalds Signed-off-by: Greg Kroah-Hartman --- kernel/umh.c | 9 +++++++++ 1 file changed, 9 insertions(+) --- a/kernel/umh.c +++ b/kernel/umh.c @@ -14,6 +14,7 @@ #include #include #include +#include #include #include #include @@ -76,6 +77,14 @@ static int call_usermodehelper_exec_asyn spin_unlock_irq(¤t->sighand->siglock); /* + * Initial kernel threads share ther FS with init, in order to + * get the init root directory. But we've now created a new + * thread that is going to execve a user process and has its own + * 'struct fs_struct'. Reset umask to the default. + */ + current->fs->umask = 0022; + + /* * Our parent (unbound workqueue) runs with elevated scheduling * priority. Avoid propagating that into the userspace child. */