From 5db4077e9f5166033637d2af9532ec6144b85646 Mon Sep 17 00:00:00 2001 From: Maxime Devos Date: Thu, 30 Jun 2022 14:21:47 +0000 Subject: [PATCH 1/2] Fix behaviour of 'epoll-wake!' after 'run-fibers'. This avoids the "epoll instance is dead" error noticed in GNUnet-Scheme's test suite, as reported at . A test is added in the next commit. This patch has been applied upstream, but there hasn't been a new release yet at time of writing. * fibers/epoll.scm (epoll-wake!)[dead]: Instead of throwing an error, just return #t. --- fibers/epoll.scm | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/fibers/epoll.scm b/fibers/epoll.scm index d26db4d..eb63242 100644 --- a/fibers/epoll.scm +++ b/fibers/epoll.scm @@ -1,6 +1,7 @@ ;; epoll ;;;; Copyright (C) 2016 Andy Wingo +;;;; Copyright (C) 2022 Maxime Devos ;;;; ;;;; This library is free software; you can redistribute it and/or ;;;; modify it under the terms of the GNU Lesser General Public @@ -135,7 +136,12 @@ epoll wait (if appropriate)." ('waiting (primitive-epoll-wake (fileno (epoll-wake-write-pipe epoll)))) ('not-waiting #t) - ('dead (error "epoll instance is dead")))) + ;; This can happen if a fiber was waiting on a condition and + ;; run-fibers completes before the fiber completes and afterwards + ;; the condition is signalled. In that case, we don't have to + ;; resurrect the fiber or something, we can just do nothing. + ;; (Bug report: https://github.com/wingo/fibers/issues/61) + ('dead #t))) (define (epoll-default-folder fd events seed) (acons fd events seed)) From c01d3853eb56ea4adacc31f51f6e917f8c0abe1c Mon Sep 17 00:00:00 2001 From: Maxime Devos Date: Thu, 30 Jun 2022 14:18:36 +0000 Subject: [PATCH 2/2] Test for issue #61. * tests/conditions.scm: Add a test. --- tests/conditions.scm | 20 ++++++++++++++++++++ 1 file changed, 20 insertions(+) diff --git a/tests/conditions.scm b/tests/conditions.scm index 505c42a..179605a 100644 --- a/tests/conditions.scm +++ b/tests/conditions.scm @@ -1,6 +1,7 @@ ;; Fibers: cooperative, event-driven user-space threads. ;;;; Copyright (C) 2016 Free Software Foundation, Inc. +;;;; Copyright (C) 2022 Maxime Devos ;;;; ;;;; This library is free software; you can redistribute it and/or ;;;; modify it under the terms of the GNU Lesser General Public @@ -21,6 +22,7 @@ #:use-module (fibers) #:use-module (fibers conditions) #:use-module (fibers operations) + #:use-module (fibers scheduler) #:use-module (fibers timers)) (define failed? #f) @@ -78,4 +80,22 @@ (wait cv) #t)) +;; Make a condition, wait for it inside a fiber, let the fiber abruptly +;; terminate and signal the condition afterwards. This tests for the bug +;; noticed at . +(assert-equal #t + (let ((cv (make-condition))) + (run-fibers + (lambda () + (spawn-fiber (lambda () (wait cv))) + (yield-current-task)) ; let the other fiber wait forever + ;; This test relies on not draining -- this is the default, + ;; but let's make this explicit. + #:drain? #false ; + ;; For simplicity, disable concurrency and preemption. + ;; That way, we can use 'yield-current-task' instead of an + ;; arbitrary sleep time. + #:hz 0 #:parallelism 1) + (signal-condition! cv))) + (exit (if failed? 1 0)) b592cbef156 Ludovic Courtès 2024-03-11daemon: Protect against FD escape when building fixed-output derivations (CVE......This fixes a security issue (CVE-2024-27297) whereby a fixed-output derivation build process could open a writable file descriptor to its output, send it to some outside process for instance over an abstract AF_UNIX socket, which would then allow said process to modify the file in the store after it has been marked as “valid”. Vulnerability discovered by puck <https://github.com/puckipedia>. Nix security advisory: https://github.com/NixOS/nix/security/advisories/GHSA-2ffj-w4mj-pg37 Nix fix: https://github.com/NixOS/nix/commit/244f3eee0bbc7f11e9b383a15ed7368e2c4becc9 * nix/libutil/util.cc (readDirectory): Add variants that take a DIR* and a file descriptor. Rewrite the ‘Path’ variant accordingly. (copyFile, copyFileRecursively): New functions. * nix/libutil/util.hh (copyFileRecursively): New declaration. * nix/libstore/build.cc (DerivationGoal::buildDone): When ‘fixedOutput’ is true, call ‘copyFileRecursively’ followed by ‘rename’ on each output. Change-Id: I7952d41093eed26e123e38c14a4c1424be1ce1c4 Reported-by: Picnoir <picnoir@alternativebit.fr>, Théophane Hufschmitt <theophane.hufschmitt@tweag.io> Change-Id: Idb5f2757f35af86b032a9851cecb19b70227bd88 Ludovic Courtès 2023-01-09daemon: Improve error message for wrong hash sizes....* nix/libutil/hash.cc (parseHash): Show the hash algorithm name and expected size in the error message. * tests/derivations.scm ("fixed-output derivation, invalid hash size"): New test. Ludovic Courtès 2022-12-18daemon: Make "opening file" error messages distinguishable....* nix/libstore/build.cc (DerivationGoal::openLogFile): Customize "opening file" error message. * nix/libutil/hash.cc (hashFile): Likewise. * nix/libutil/util.cc (readFile, writeFile): Likewise. Ludovic Courtès 2021-11-19daemon: Micro-optimize 'deletePath'....'remove' calls 'unlink' first and falls back to 'rmdir' upon EISDIR. This change gets rid of the 'unlink' call for every directory being removed. * nix/libutil/util.cc (_deletePath): Call 'unlink' or 'rmdir' depending on 'st.st_mode', rather than call 'remove'. Ludovic Courtès