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=-13.1 required=3.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,INCLUDES_PATCH,MAILING_LIST_MULTI, SIGNED_OFF_BY,SPF_HELO_NONE,SPF_PASS,URIBL_BLOCKED,USER_AGENT_GIT autolearn=ham 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 027BDC433DF for ; Mon, 12 Oct 2020 19:07:07 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id ABD5A214DB for ; Mon, 12 Oct 2020 19:07:06 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1602529626; bh=p3pDvLemUq7qOEZDJTDyDXm0HyfeG2n1DlwU+lVlrzQ=; h=From:To:Cc:Subject:Date:In-Reply-To:References:List-ID:From; b=OrALyHL3Wb7QND1jDCu97sH12wFIuGjIMML4ipwdHlGEGiqKfnMVOidt69O5ktom6 nk6QOchezcmqiJ3v8YRYbZaVdZG/bFy5RXwlctPS7AmgL6CLm8MdtijuPt9Gs1f/AG 9xoyaj/NDoGErTJvwcn8Ldd70D5UsSWEquzBMjqk= Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S2391444AbgJLTG5 (ORCPT ); Mon, 12 Oct 2020 15:06:57 -0400 Received: from mail.kernel.org ([198.145.29.99]:53480 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S2391186AbgJLTDt (ORCPT ); Mon, 12 Oct 2020 15:03:49 -0400 Received: from sasha-vm.mshome.net (c-73-47-72-35.hsd1.nh.comcast.net [73.47.72.35]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPSA id 430932067C; Mon, 12 Oct 2020 19:03:48 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1602529429; bh=p3pDvLemUq7qOEZDJTDyDXm0HyfeG2n1DlwU+lVlrzQ=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=tr+VE/Elh70AgQBdIWjadAHunNgT8xf+nmCIb2UL5wJ6cPNY26jgHpGm0laLifFak Xek8al8Z0uxuIpBc2qDYWlECPGK2HJoDqmFVLMdzXOtzYwvjKM0clRRimKENmn/1uT xcSNDpzjZXIGpj69K+RWD8T8SAHEoveHSm72L81o= From: Sasha Levin To: linux-kernel@vger.kernel.org, stable@vger.kernel.org Cc: Linus Torvalds , Vegard Nossum , Al Viro , "Eric W . Biederman" , Sasha Levin Subject: [PATCH AUTOSEL 4.19 10/12] usermodehelper: reset umask to default before executing user process Date: Mon, 12 Oct 2020 15:03:33 -0400 Message-Id: <20201012190335.3279538-10-sashal@kernel.org> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20201012190335.3279538-1-sashal@kernel.org> References: <20201012190335.3279538-1-sashal@kernel.org> MIME-Version: 1.0 X-stable: review X-Patchwork-Hint: Ignore Content-Transfer-Encoding: 8bit Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org From: Linus Torvalds [ Upstream commit 4013c1496c49615d90d36b9d513eee8e369778e9 ] 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: Sasha Levin --- kernel/umh.c | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/kernel/umh.c b/kernel/umh.c index 52a9084f85419..16653319c8ce8 100644 --- a/kernel/umh.c +++ b/kernel/umh.c @@ -13,6 +13,7 @@ #include #include #include +#include #include #include #include @@ -72,6 +73,14 @@ static int call_usermodehelper_exec_async(void *data) flush_signal_handlers(current, 1); 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. -- 2.25.1