From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on starla X-Spam-Level: X-Spam-Status: No, score=0.1 required=3.0 tests=DKIM_SIGNED,DKIM_VALID, DKIM_VALID_AU,MAILING_LIST_MULTI,RCVD_IN_BL_SPAMCOP_NET,SPF_HELO_PASS, SPF_PASS autolearn=no autolearn_force=no version=3.4.6 Received: from nue.mailmanlists.eu (nue.mailmanlists.eu [94.130.110.93]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits)) (No client certificate requested) by dcvr.yhbt.net (Postfix) with ESMTPS id 650871F5CB for ; Thu, 3 Oct 2024 09:10:44 +0000 (UTC) Authentication-Results: dcvr.yhbt.net; dkim=pass (1024-bit key; unprotected) header.d=ml.ruby-lang.org header.i=@ml.ruby-lang.org header.a=rsa-sha256 header.s=mail header.b=o1XzGTc+; dkim=fail reason="signature verification failed" (2048-bit key; unprotected) header.d=ruby-lang.org header.i=@ruby-lang.org header.a=rsa-sha256 header.s=s1 header.b=GKnD/HVp; dkim-atps=neutral DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=ml.ruby-lang.org; s=mail; t=1727946642; bh=+J/tsGZck3W8463dWExdCVcyQPIh83VvtA4iYlvNVjU=; h=Date:References:To:Reply-To:Subject:List-Id:List-Archive: List-Help:List-Owner:List-Post:List-Subscribe:List-Unsubscribe: From:Cc:From; b=o1XzGTc+1guoThCTBoEAW9p8eq827TIyqodjuQ+DqbodxbqAtGMPpa7akplsoUKoD akkAPiOJX/UckKnFtQbMov1cbG5RUZU2FCTy3Vs9iJTl+M75OXPx8HKV6JJa3Pwuvf 7YVdcuql7gIlD1IFIRWXgbz5aqDZRs1xTkkE4Z4s= Received: from nue.mailmanlists.eu (localhost [IPv6:::1]) by nue.mailmanlists.eu (Postfix) with ESMTP id 4A67644017 for ; Thu, 3 Oct 2024 09:10:42 +0000 (UTC) Authentication-Results: nue.mailmanlists.eu; dkim=pass (2048-bit key; unprotected) header.d=ruby-lang.org header.i=@ruby-lang.org header.a=rsa-sha256 header.s=s1 header.b=GKnD/HVp; dkim-atps=neutral Received: from s.wrqvtbkv.outbound-mail.sendgrid.net (s.wrqvtbkv.outbound-mail.sendgrid.net [149.72.123.24]) by nue.mailmanlists.eu (Postfix) with ESMTPS id D8D3D43F0F for ; Thu, 3 Oct 2024 09:10:30 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=ruby-lang.org; h=from:references:subject:mime-version:content-type: content-transfer-encoding:list-id:to:cc:content-type:from:subject:to; s=s1; bh=iqTGse86L6ZkbhCk1qdNv5ibqXazbRRRq68+WEgU3gs=; b=GKnD/HVp+FFIUMKpfHcPt74Lw7bDmTN5dYfs4CnVZlIatGkLW4buBX7Ve5zLSCiYaH1U MMeLeoKtn92bT9IN7EDGdUR3K7ehyh5A/9ZpwUCdHZE2Fjpaq51let2zAY/bkEue7jDkPD JFhubbB2FyDO/LbhGFg1XQyE1nUeXnW0wK41a/yP8u1k4jjevHs0yZKuDp+vHMsnZdXpTM +BZM7RkhSc5jKNruTzpXLa+FCcaOE5ZiHZvzs/Qe7kRbdnzT9Gf3awbB67lWjd0aO/aF2P en+DsKlLIrGKi4TUOenpJKzepP6loSnXWVpOzSxZ9XNhRPXrShIxu/wNSfJxN7ng== Received: by recvd-5577bcb48c-pd8nc with SMTP id recvd-5577bcb48c-pd8nc-1-66FE5F84-1A 2024-10-03 09:10:28.968488205 +0000 UTC m=+1782872.945775845 Received: from herokuapp.com (unknown) by geopod-ismtpd-9 (SG) with ESMTP id Jb9DIEIrSEC6OTkloB7V_w for ; Thu, 03 Oct 2024 09:10:28.939 +0000 (UTC) Date: Thu, 03 Oct 2024 09:10:29 +0000 (UTC) Message-ID: References: Mime-Version: 1.0 X-Redmine-Project: ruby-master X-Redmine-Issue-Tracker: Bug X-Redmine-Issue-Id: 20693 X-Redmine-Issue-Author: kjtsanaktsidis X-Redmine-Issue-Assignee: akr X-Redmine-Issue-Priority: Normal X-Redmine-Sender: akr X-Mailer: Redmine X-Redmine-Host: bugs.ruby-lang.org X-Redmine-Site: Ruby Issue Tracking System X-Auto-Response-Suppress: All Auto-Submitted: auto-generated X-Redmine-MailingListIntegration-Message-Ids: 96064 X-SG-EID: =?us-ascii?Q?u001=2EjUYdomjR8qg=2FmRRJiw9jcD8=2F=2Fg2V+YCwM42AbEffAz+piO1ivD2ssVdIf?= =?us-ascii?Q?UsAvXwsSNeFNBeVO12+lrvx7XL=2FC2o8D=2FcpGjTr?= =?us-ascii?Q?UV9lVFWcbWjGwDPRM8mSzYlzCKORt+IOBOzpB8y?= =?us-ascii?Q?hTVhTmYoQOpcZ7RX3T866mXS3RmvmMdEqsBxf0s?= =?us-ascii?Q?DtyKewhLd2enjMq5ajFtKQrsBDmE=2FqI8JnBCEE9?= =?us-ascii?Q?=2FCO1eqm6Cv=2FEcS97nAWPpHqtmDhIFcI2gX6R8+5?= =?us-ascii?Q?sW1W?= To: ruby-core@ml.ruby-lang.org X-Entity-ID: u001.I8uzylDtAfgbeCOeLBYDww== Message-ID-Hash: Z43FFR3W4RC5CYFXGBXAIOUCRDQLR7I2 X-Message-ID-Hash: Z43FFR3W4RC5CYFXGBXAIOUCRDQLR7I2 X-MailFrom: bounces+313651-b711-ruby-core=ml.ruby-lang.org@em5188.ruby-lang.org X-Mailman-Rule-Misses: dmarc-mitigation; no-senders; approved; emergency; loop; banned-address; member-moderation; nonmember-moderation; administrivia; implicit-dest; max-recipients; max-size; news-moderation; no-subject; digests; suspicious-header X-Mailman-Version: 3.3.9 Precedence: list Reply-To: Ruby developers Subject: [ruby-core:119428] [Ruby master Bug#20693] Dir.tmpdir should perform a real access check before warning about writability List-Id: Ruby developers Archived-At: List-Archive: List-Help: List-Owner: List-Post: List-Subscribe: List-Unsubscribe: From: "akr (Akira Tanaka) via ruby-core" Cc: "akr (Akira Tanaka)" Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: 7bit Issue #20693 has been updated by akr (Akira Tanaka). I think the reason why `File.writable?` is used should be described in the source. ---------------------------------------- Bug #20693: Dir.tmpdir should perform a real access check before warning about writability https://bugs.ruby-lang.org/issues/20693#change-110043 * Author: kjtsanaktsidis (KJ Tsanaktsidis) * Status: Open * Assignee: akr (Akira Tanaka) * Backport: 3.1: UNKNOWN, 3.2: UNKNOWN, 3.3: UNKNOWN ---------------------------------------- The code in `Dir.tmpdir` attempts to warn the user if their temp directory is deficient for some reason: ```ruby case when !stat.directory? warn "#{name} is not a directory: #{dir}" when !stat.writable? warn "#{name} is not writable: #{dir}" when stat.world_writable? && !stat.sticky? warn "#{name} is world-writable: #{dir}" else break dir end ``` This check for writability is looking at the user/group/world access bits on the stat output, and determining if the user running Ruby is allowed to write to the temp directory based on that. However, modern operating systems contain other mechanisms apart from the user/group/world bits which can grant access to a directory that would otherwise be denied, or vice versa. Things like: * Posix ACL's * Linux's capabilities like CAP_DAC_OVERRIDE * Linux Security Modules like SELinux or AppArmor * Syscall filters like Linux's seccomp * Granular capability systems like FreeBSD's Capsicum * OpenBSD's pledge and unveil * Windows too has a rich ACL system for controlling filesystem access To address this, we should call `File.writable?` instead of `stat.writable?`, which asks the system whether the file is writable using the `euidaccess()` function if available. On Linux/glibc, at least, this will issue an `access(2)` syscall, and the Kernel can take all of the above into account. n.b. if Ruby is running as suid, then glibc currently will NOT ask the kernel to perform the access check in `euidaccess()`, and instead does a similar thing to what `Stat#writable?` does (https://github.com/bminor/glibc/blob/7f04bb4e49413bd57ac3215f3480b09ae7131968/sysdeps/posix/euidaccess.c#L159-L162). This is because of the relatively new `faccessat2(2)` syscall is required to do this properly, and there is some ecosystem issues with leveraging this by default (e.g. https://bugzilla.redhat.com/show_bug.cgi?id=1900021). Since running Ruby as suid is probably a very bad idea anyway, and the glibc implementation isn't any worse than the `Stat#writable?` one, this seems OK though. -- https://bugs.ruby-lang.org/ ______________________________________________ ruby-core mailing list -- ruby-core@ml.ruby-lang.org To unsubscribe send an email to ruby-core-leave@ml.ruby-lang.org ruby-core info -- https://ml.ruby-lang.org/mailman3/lists/ruby-core.ml.ruby-lang.org/