Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from bombadil.infradead.org (bombadil.infradead.org [198.137.202.133]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.lore.kernel.org (Postfix) with ESMTPS id 8E5E6E7719F for ; Fri, 10 Jan 2025 16:23:57 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=bombadil.20210309; h=Sender:List-Subscribe:List-Help :List-Post:List-Archive:List-Unsubscribe:List-Id:Content-Transfer-Encoding: MIME-Version:Message-ID:Date:Subject:Cc:To:From:Reply-To:Content-Type: Content-ID:Content-Description:Resent-Date:Resent-From:Resent-Sender: Resent-To:Resent-Cc:Resent-Message-ID:In-Reply-To:References:List-Owner; bh=gOllue6l5sNOAYiCW+Cp5tTwc+re6WiezM8i21g+rsA=; b=0OuPy21ejVEIlvccs/Wr0GhEUM h/PfJPPCzEbyQ2SMbPexM+mH1g7ccdoEWSoq+7hkuv2diQQk8ni7wPepexa++XNZbWUI2QBKkRnwA i6/tCRner6+RKw7+9gcU1H6+t5UXn9eDkeJMO01dPm/7vkznH1/0a8rnLGG+54NtTLXHf6FnGiw2M f3yBmJa7A2KZCkrMnOhkIwk6JqLWNUj7bIoggLmvoeeDc+AN5ApS1PoOIuXlqAeRuGZY0anQ2eb8u M6G6DuByUkzXa/7zkDNvyyxmpyr7Ay6t0pNJy5mzy+/s24TQsgYharJmOFYDbCw8/RcXIc0o9fxst KsDct4Dg==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.98 #2 (Red Hat Linux)) id 1tWHnh-0000000GEA3-1N2q; Fri, 10 Jan 2025 16:23:57 +0000 Received: from s3.sipsolutions.net ([2a01:4f8:242:246e::2] helo=sipsolutions.net) by bombadil.infradead.org with esmtps (Exim 4.98 #2 (Red Hat Linux)) id 1tWHdf-0000000GAn4-1PIk for linux-um@lists.infradead.org; Fri, 10 Jan 2025 16:13:36 +0000 DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=sipsolutions.net; s=mail; h=Content-Transfer-Encoding:MIME-Version: Message-ID:Date:Subject:Cc:To:From:Content-Type:Sender:Reply-To:Content-ID: Content-Description:Resent-Date:Resent-From:Resent-To:Resent-Cc: Resent-Message-ID:In-Reply-To:References; bh=gOllue6l5sNOAYiCW+Cp5tTwc+re6WiezM8i21g+rsA=; t=1736525615; x=1737735215; b=Uqi7QepM5ggqj8GVats2q1e9RQd5w+8Es0HadY0vtcbsHv2iaL/70Um/vaIoX/qeuKWD+LOoKPf 4i2Td59Soq/llPJyQsAl/m/LgbzcTRzPlHf8rCpHczV5rjGGtZs8i1O8saWN4mWjUr5MXuWkiD09o ii2P/LAOlyGucYofBUVNedAtJlq+dxltgh/putfBlrp66EWa4jCg9XH+ZSY8e9hv9n1kHbwldWza6 edoagzOab9c2dXsSUFOBYNeiGNe64iJuzq/zT9lNshbpGrn9nLXW+IG/EpMpGTrO42j8Ojas3u2QL nzhtObxycafo9nPw5pgcR8jmJGpz3bCfgLVQ==; Received: by sipsolutions.net with esmtpsa (TLS1.3:ECDHE_X25519__RSA_PSS_RSAE_SHA256__AES_256_GCM:256) (Exim 4.98) (envelope-from ) id 1tWHdc-0000000AhcU-3RuC; Fri, 10 Jan 2025 17:13:33 +0100 From: Benjamin Berg To: linux-um@lists.infradead.org Cc: Benjamin Berg , Glenn Washburn Subject: [PATCH] um: fix execve stub execution on old host OSs Date: Fri, 10 Jan 2025 17:13:05 +0100 Message-ID: <20250110161305.558223-1-benjamin@sipsolutions.net> X-Mailer: git-send-email 2.47.1 MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20250110_081335_380401_1C33D682 X-CRM114-Status: UNSURE ( 9.94 ) X-CRM114-Notice: Please train this message. X-BeenThere: linux-um@lists.infradead.org X-Mailman-Version: 2.1.34 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Sender: "linux-um" Errors-To: linux-um-bounces+linux-um=archiver.kernel.org@lists.infradead.org From: Benjamin Berg The stub execution uses the somewhat new close_range and execveat syscalls. Of these two, the execveat call is essential, but the close_range call is more about stub process hygiene rather than safety (and its result is ignored). Replace both calls with a raw syscall as older machines might not have a recent enough kernel for close_range (with CLOSE_RANGE_CLOEXEC) or a libc that does not yet expose both of the syscalls. Fixes: 32e8eaf263d9 ("um: use execveat to create userspace MMs") Reported-by: Glenn Washburn Closes: https://lore.kernel.org/20250108022404.05e0de1e@crass-HP-ZBook-15-G2 Signed-off-by: Benjamin Berg --- arch/um/os-Linux/skas/process.c | 16 +++++++++++++--- 1 file changed, 13 insertions(+), 3 deletions(-) diff --git a/arch/um/os-Linux/skas/process.c b/arch/um/os-Linux/skas/process.c index f683cfc9e51a..64e89921bc7f 100644 --- a/arch/um/os-Linux/skas/process.c +++ b/arch/um/os-Linux/skas/process.c @@ -181,6 +181,10 @@ extern char __syscall_stub_start[]; static int stub_exe_fd; +#ifndef CLOSE_RANGE_CLOEXEC +#define CLOSE_RANGE_CLOEXEC (1U << 2) +#endif + static int userspace_tramp(void *stack) { char *const argv[] = { "uml-userspace", NULL }; @@ -202,8 +206,12 @@ static int userspace_tramp(void *stack) init_data.stub_data_fd = phys_mapping(uml_to_phys(stack), &offset); init_data.stub_data_offset = MMAP_OFFSET(offset); - /* Set CLOEXEC on all FDs and then unset on all memory related FDs */ - close_range(0, ~0U, CLOSE_RANGE_CLOEXEC); + /* + * Avoid leaking unneeded FDs to the stub by setting CLOEXEC on all FDs + * and then unsetting it on all memory related FDs. + * This is not strictly necessary from a safety perspective. + */ + syscall(__NR_close_range, 1, ~0U, CLOSE_RANGE_CLOEXEC); fcntl(init_data.stub_data_fd, F_SETFD, 0); for (iomem = iomem_regions; iomem; iomem = iomem->next) @@ -224,7 +232,9 @@ static int userspace_tramp(void *stack) if (ret != sizeof(init_data)) exit(4); - execveat(stub_exe_fd, "", argv, NULL, AT_EMPTY_PATH); + /* Raw execveat for compatibility with older libc versions */ + syscall(__NR_execveat, stub_exe_fd, (unsigned long)"", + (unsigned long)argv, NULL, AT_EMPTY_PATH); exit(5); } -- 2.47.1