From patchwork Mon Oct 5 14:12:18 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: =?utf-8?q?Peter_M=C3=BCller?= X-Patchwork-Id: 3506 Return-Path: Received: from mail01.ipfire.org (mail01.haj.ipfire.org [172.28.1.202]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (P-384) client-signature ECDSA (P-384)) (Client CN "mail01.haj.ipfire.org", Issuer "Let's Encrypt Authority X3" (verified OK)) by web04.haj.ipfire.org (Postfix) with ESMTPS id 4C4jGn0RhRz3x0j for ; Mon, 5 Oct 2020 14:12:33 +0000 (UTC) Received: from mail02.haj.ipfire.org (mail02.haj.ipfire.org [172.28.1.201]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (P-384) client-signature ECDSA (P-384)) (Client CN "mail02.haj.ipfire.org", Issuer "Let's Encrypt Authority X3" (verified OK)) by mail01.ipfire.org (Postfix) with ESMTPS id 4C4jGl41LczkR; Mon, 5 Oct 2020 14:12:31 +0000 (UTC) Received: from mail02.haj.ipfire.org (localhost [127.0.0.1]) by mail02.haj.ipfire.org (Postfix) with ESMTP id 4C4jGl2NyPz2y5K; Mon, 5 Oct 2020 14:12:31 +0000 (UTC) Received: from mail01.ipfire.org (mail01.haj.ipfire.org [172.28.1.202]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (P-384) client-signature ECDSA (P-384)) (Client CN "mail01.haj.ipfire.org", Issuer "Let's Encrypt Authority X3" (verified OK)) by mail02.haj.ipfire.org (Postfix) with ESMTPS id 4C4jGk5SqCz2xd0 for ; Mon, 5 Oct 2020 14:12:30 +0000 (UTC) Received: from [127.0.0.1] (localhost [127.0.0.1]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (P-384) server-digest SHA384) (Client did not present a certificate) by mail01.ipfire.org (Postfix) with ESMTPSA id 4C4jGg0QChzkR for ; Mon, 5 Oct 2020 14:12:26 +0000 (UTC) DKIM-Signature: v=1; a=ed25519-sha256; c=relaxed/relaxed; d=ipfire.org; s=202003ed25519; t=1601907149; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding; bh=gkaD2s3+ddKQS2Y5z5sct+c7hO3ODhDFGWX1Tva/ZTk=; b=k+Vxm5lvquMInPSgMWwPLyGbWhEZKv6QQshMLpqD7eqkVTnv9wbyHCwP87C+X904bAVa2b OScLBTEAmWvAAdBQ== DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=ipfire.org; s=202003rsa; t=1601907149; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding; bh=gkaD2s3+ddKQS2Y5z5sct+c7hO3ODhDFGWX1Tva/ZTk=; b=nyIFWXueUEJXAXoakqoID4cYbd6T5DEs2knY/1l/NZCFBzbZXkDee01GIcgURDj2RfNgb2 RGdjwk8E3eXLT+sE4RfBJXuuNKzRJFWv5WkNOuBGRQ0YFkJ95ZBtBw01HXdKzZVw7RlRrR LhVjP8Ya4DBYDx57MKqXe7e8kkAjUFTpT0OXQfel1A7CfOKXPix2t8gwfcZZLaofrBczxp dOEoa8ML5gy8kfvwktZFFIwz1k94+Dh3IAtPu7Y43A+nBaTurBg8RsPj55cmAKo1EWdEo9 sCLCLc2Pi1p3aLmOPcSc3Ib8HMAx3k9VXV/lR3aamTfqkg1EnPm4L4FWTqjzcw== To: development@lists.ipfire.org From: =?utf-8?q?Peter_M=C3=BCller?= Subject: [PATCH] sysctl.conf: prevent unintentional writes into attacker-controlled files and FIFOs Message-ID: <141827bd-a1b8-e551-9bf5-93f529af485e@ipfire.org> Date: Mon, 5 Oct 2020 14:12:18 +0000 MIME-Version: 1.0 Content-Language: en-US Authentication-Results: mail01.ipfire.org; auth=pass smtp.mailfrom=peter.mueller@ipfire.org X-BeenThere: development@lists.ipfire.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: IPFire development talk List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: development-bounces@lists.ipfire.org Sender: "Development" Similar to hard- and symlink protection introduced a while ago, this patch enables protections against unintentional writes into attacker-controlled regular files or FIFOs, where a program expected to create new ones. This makes exploiting TOCTOU flaws harder. See also: https://www.kernel.org/doc/Documentation/sysctl/fs.txt Signed-off-by: Peter Müller --- config/etc/sysctl.conf | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/config/etc/sysctl.conf b/config/etc/sysctl.conf index d48c7734e..be7c07c85 100644 --- a/config/etc/sysctl.conf +++ b/config/etc/sysctl.conf @@ -49,6 +49,11 @@ kernel.dmesg_restrict = 1 fs.protected_symlinks = 1 fs.protected_hardlinks = 1 +# Don't allow writes to files and FIFOs that we don't own in world writable sticky +# directories, unless they are owned by the owner of the directory. +fs.protected_fifos = 2 +fs.protected_regular = 2 + # Minimal preemption granularity for CPU-bound tasks: # (default: 1 msec# (1 + ilog(ncpus)), units: nanoseconds) kernel.sched_min_granularity_ns = 10000000