From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-9.8 required=3.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,HEADER_FROM_DIFFERENT_DOMAINS,MAILING_LIST_MULTI, SIGNED_OFF_BY,SPF_HELO_NONE,SPF_PASS,URIBL_BLOCKED,USER_AGENT_GIT autolearn=unavailable autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id AB8F7C433E7 for ; Mon, 12 Oct 2020 13:42:13 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 6D108208B8 for ; Mon, 12 Oct 2020 13:42:13 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1602510133; bh=kj6sxvvaay1N0knIRsy0kDpNRDM8VKzidKLrpRkenaw=; h=From:To:Cc:Subject:Date:In-Reply-To:References:List-ID:From; b=lNFDxS6fOoBcOytFesU/av/GlroMAQqcCs0205XDzbyU0tU/X1/1BRdyPpyWFfXit JEEqqG9g0EqoPl4hny88z9/h4O7iIdCvgRfO4ztnDOhzm8VQZABPMcLZkw4tIMZw9L 6GWEv3vihLF9EpxrS70Tf0/GLUNCJy1gXM3T2TkU= Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1731540AbgJLNmM (ORCPT ); Mon, 12 Oct 2020 09:42:12 -0400 Received: from mail.kernel.org ([198.145.29.99]:46750 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1731507AbgJLNmD (ORCPT ); Mon, 12 Oct 2020 09:42:03 -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 1FF1220838; Mon, 12 Oct 2020 13:41:47 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1602510108; bh=kj6sxvvaay1N0knIRsy0kDpNRDM8VKzidKLrpRkenaw=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=MYdMJTbhEW6hjtwl8ST4MYURUnY4ZywVfv0A+79O2fxupH5S3knqZVuMttJcAUFsu tWQ4xUdtzkbwz+6iCwqyb2WjohasieibdwcLL7IR8VYJ7fzcIbWtiXltmKN8OFc7jj dZ0tjcXYR574LvrO1CD0oTUogxoDg2XIrTc/DNdQ= 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.4 13/85] usermodehelper: reset umask to default before executing user process Date: Mon, 12 Oct 2020 15:26:36 +0200 Message-Id: <20201012132633.506236900@linuxfoundation.org> X-Mailer: git-send-email 2.28.0 In-Reply-To: <20201012132632.846779148@linuxfoundation.org> References: <20201012132632.846779148@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. */