From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from mp0.migadu.com ([2001:41d0:303:e16b::]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits)) by ms13.migadu.com with LMTPS id uBKnHx03aGchWQAAqHPOHw:P1 (envelope-from ) for ; Sun, 22 Dec 2024 15:58:21 +0000 Received: from aspmx1.migadu.com ([2001:41d0:303:e16b::]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits)) by mp0.migadu.com with LMTPS id uBKnHx03aGchWQAAqHPOHw (envelope-from ) for ; Sun, 22 Dec 2024 16:58:21 +0100 X-Envelope-To: larch@yhetil.org Authentication-Results: aspmx1.migadu.com; dkim=pass header.d=debbugs.gnu.org header.s=debbugs-gnu-org header.b=kFSZFlQv; dkim=fail ("headers rsa verify failed") header.d=gnu.org header.s=fencepost-gnu-org header.b=qc8j6eM2; spf=pass (aspmx1.migadu.com: domain of "guix-patches-bounces+larch=yhetil.org@gnu.org" designates 209.51.188.17 as permitted sender) smtp.mailfrom="guix-patches-bounces+larch=yhetil.org@gnu.org"; dmarc=pass (policy=none) header.from=gnu.org ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=yhetil.org; s=key1; t=1734883101; h=from:from:sender:sender:reply-to:subject:subject:date:date: message-id:message-id:to:to:cc:cc:mime-version:mime-version: content-type:content-type: content-transfer-encoding:content-transfer-encoding:resent-cc: resent-from:resent-sender:resent-message-id:in-reply-to:in-reply-to: references:references:list-id:list-help:list-unsubscribe: list-subscribe:list-post:dkim-signature; bh=8dB9aneqq2u0HbdQgTXXCSFROg4vcrZsHF/IjkWDlVI=; b=SCpXDB/npxRNricNwfoxfk02/JHQ3th67GNuHnKwrIFu+WHxNoXrczOfA+b6xO9jAkl8PK 62WkaHqVUv9lRpK/qowRXRkU+NgsCn/9lTvaGoyjxQd6faRFN9V5uuFvIRiiFssBFRWTex FR52xXsImzVJXYdBC4r3WZ7vmHtH+zIrTjDMgntaBQWQRrQkRdw49dbrOjlfWmtjznKFjb 5u0JZSc8WQORXspsKQRUeIoMcCv4T9aRU8Wp1T2OSz/WYiasnsh5bps3kxbzkDEL/3zS// jKm+LhuToL2wA3PX+hOdAKwUnz9ljeyuCoCSSzhhRDtcFdBeL5lDMmyEnCeJQw== ARC-Authentication-Results: i=1; aspmx1.migadu.com; dkim=pass header.d=debbugs.gnu.org header.s=debbugs-gnu-org header.b=kFSZFlQv; dkim=fail ("headers rsa verify failed") header.d=gnu.org header.s=fencepost-gnu-org header.b=qc8j6eM2; spf=pass (aspmx1.migadu.com: domain of "guix-patches-bounces+larch=yhetil.org@gnu.org" designates 209.51.188.17 as permitted sender) smtp.mailfrom="guix-patches-bounces+larch=yhetil.org@gnu.org"; dmarc=pass (policy=none) header.from=gnu.org ARC-Seal: i=1; s=key1; d=yhetil.org; t=1734883101; a=rsa-sha256; cv=none; b=HsIkysZ6beB+Q3qok4BMYdqN5PhCBKwvL7j+At+M5ZKSIWGTozaFnmp4M26MaxnMq4wD9R S309TSCmx8c6+WaUNLvVmoKgLwMyf8YMKmTT5dXt3ZHVhy4yx5kmuiz9yOtWazOH6MwWGh gDo5UUjfEDC5d6gO8/zL6SyH9ppGSUvN0WJjtNG6eBlOjGU5yH6c3cj8BzWo7lRTGZuFix nccumEIdH6fRlqnp6iTH9WPhqnUJAlukWwZQlFkHBovyZ2dSVRb8yhVu7y7O4J9jbl19PB KhsJIgEDJmUO2Zz7ywZIWxFg7d1kiOPhwZM51t6xkDw3MhtlI+Bag993Ui07Ng== Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by aspmx1.migadu.com (Postfix) with ESMTPS id 36E295C250 for ; Sun, 22 Dec 2024 16:58:21 +0100 (CET) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1tPOLG-0004r4-M4; Sun, 22 Dec 2024 10:58:06 -0500 Received: from eggs.gnu.org ([2001:470:142:3::10]) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1tPOLD-0004qm-EW for guix-patches@gnu.org; Sun, 22 Dec 2024 10:58:04 -0500 Received: from debbugs.gnu.org ([2001:470:142:5::43]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1tPOLD-00082W-0X for guix-patches@gnu.org; Sun, 22 Dec 2024 10:58:03 -0500 DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=debbugs.gnu.org; s=debbugs-gnu-org; h=MIME-Version:References:In-Reply-To:Date:From:To:Subject; bh=8dB9aneqq2u0HbdQgTXXCSFROg4vcrZsHF/IjkWDlVI=; b=kFSZFlQv+rjH+UO2f1gLXYYFWBorenHZoYBYXZ2QLpk3iDE8HqA34//GRr/CmLmJVMyRB9SgZrjx7KxYVQQnVjUGFFk62Ac1gW1nrJOAjSQNsQEceRsKE+vHZqvTxwQDE7VLNh0xWJhLZpo193jdyzn4aRtD0DvAquGQZxJvXfjmqYTP6SLVq4FYek493jDgomo+vnXigl/FJdK+0alDECiD1NOGoqtitSYqeqofE+WRx6Nc2zZJRY9FR9ku3bJK6HISWAUMKNDPAXgwcvYVf6v1rJX7pfrTBPJp5KWs6aHC20msV1FG1emSfCHbLKOxmu8m0ZsKe7gmPaBzTEq2oQ==; Received: from Debian-debbugs by debbugs.gnu.org with local (Exim 4.84_2) (envelope-from ) id 1tPOLC-0003Mw-PX for guix-patches@gnu.org; Sun, 22 Dec 2024 10:58:02 -0500 X-Loop: help-debbugs@gnu.org Subject: [bug#75027] [PATCH 1/3] syscalls: Add =?UTF-8?Q?=E2=80=98kexec-load-file=E2=80=99.?= Resent-From: Ludovic =?UTF-8?Q?Court=C3=A8s?= Original-Sender: "Debbugs-submit" Resent-CC: guix-patches@gnu.org Resent-Date: Sun, 22 Dec 2024 15:58:02 +0000 Resent-Message-ID: Resent-Sender: help-debbugs@gnu.org X-GNU-PR-Message: followup 75027 X-GNU-PR-Package: guix-patches X-GNU-PR-Keywords: patch To: 75027@debbugs.gnu.org Cc: Ludovic =?UTF-8?Q?Court=C3=A8s?= Received: via spool by 75027-submit@debbugs.gnu.org id=B75027.173488308212946 (code B ref 75027); Sun, 22 Dec 2024 15:58:02 +0000 Received: (at 75027) by debbugs.gnu.org; 22 Dec 2024 15:58:02 +0000 Received: from localhost ([127.0.0.1]:51542 helo=debbugs.gnu.org) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1tPOLB-0003Mg-H9 for submit@debbugs.gnu.org; Sun, 22 Dec 2024 10:58:01 -0500 Received: from eggs.gnu.org ([209.51.188.92]:48500) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1tPOL9-0003MS-BE for 75027@debbugs.gnu.org; Sun, 22 Dec 2024 10:57:59 -0500 Received: from fencepost.gnu.org ([2001:470:142:3::e]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1tPOL3-000810-8O; Sun, 22 Dec 2024 10:57:53 -0500 DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=gnu.org; s=fencepost-gnu-org; h=MIME-Version:References:In-Reply-To:Date:Subject:To: From; bh=8dB9aneqq2u0HbdQgTXXCSFROg4vcrZsHF/IjkWDlVI=; b=qc8j6eM2KkQnxZoDDVwR td1i7NMf35t+3T/Sil0wbHC/6908t0gyq0FF/OrdW5GqRZAREwa1hymZ2uMehEdvZmpsemCMU2oGb 969Ujmciv3sDEjTZzDOTDtAFntJvYhJpIHy6akqUecQJQFsbAZ+2UEw42OD8GHUUmg5r4KbFpYYbA +z4MaSDvqPYiwsNI1Z+33YtaeCmM1YF3501AId3+APNiBRm+TsvtqPfkK2fRW1j218s4hiQwcTWM7 bSHBftiXqQWPqOPHspdMgpPDMhMBUTwy/yQJhp2wWI6T/0FF1w6HwRzXlQwWF475JzzsECKh84mQk c+CtmWsow1EctA==; From: Ludovic =?UTF-8?Q?Court=C3=A8s?= Date: Sun, 22 Dec 2024 16:57:41 +0100 Message-ID: <29936b7f16e53ab11b958ceea04376dfa5b32d69.1734882676.git.ludo@gnu.org> X-Mailer: git-send-email 2.46.0 In-Reply-To: References: MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit X-BeenThere: debbugs-submit@debbugs.gnu.org X-Mailman-Version: 2.1.18 Precedence: list X-BeenThere: guix-patches@gnu.org List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: guix-patches-bounces+larch=yhetil.org@gnu.org Sender: guix-patches-bounces+larch=yhetil.org@gnu.org X-Migadu-Country: US X-Migadu-Flow: FLOW_IN X-Migadu-Queue-Id: 36E295C250 X-Migadu-Scanner: mx13.migadu.com X-Migadu-Spam-Score: -3.40 X-Spam-Score: -3.40 X-TUID: TRQcU0g7Yuf6 * guix/build/syscalls.scm (string->utf-8/nul-terminated) (kexec-load-file): New procedures. * tests/syscalls.scm ("kexec-load-file"): New test. Change-Id: I3724226a14ecc07f346e77519fb5b0591096c7f6 --- guix/build/syscalls.scm | 54 +++++++++++++++++++++++++++++++++++++++++ tests/syscalls.scm | 13 ++++++++++ 2 files changed, 67 insertions(+) diff --git a/guix/build/syscalls.scm b/guix/build/syscalls.scm index 2c20edf058..f8c9937f54 100644 --- a/guix/build/syscalls.scm +++ b/guix/build/syscalls.scm @@ -146,6 +146,12 @@ (define-module (guix build syscalls) clone setns + kexec-load-file + KEXEC_FILE_UNLOAD + KEXEC_FILE_ON_CRASH + KEXEC_FILE_NO_INITRAMFS + KEXEC_FILE_DEBUG + PF_PACKET AF_PACKET all-network-interface-names @@ -765,6 +771,54 @@ (define-as-needed load-linux-module (list (strerror err)) (list err))))))) +(define (string->utf-8/nul-terminated str) + "Serialize STR to UTF-8; return the resulting bytevector, including +terminating nul character." + (let* ((source (string->utf8 str)) + (bv (make-bytevector (+ (bytevector-length source) 1) 0))) + (bytevector-copy! source 0 bv 0 (bytevector-length source)) + bv)) + +;; Constants from . +(define KEXEC_FILE_UNLOAD #x00000001) +(define KEXEC_FILE_ON_CRASH #x00000002) +(define KEXEC_FILE_NO_INITRAMFS #x00000004) +(define KEXEC_FILE_DEBUG #x00000008) + +(define kexec-load-file + (let* ((proc (syscall->procedure int "syscall" + (list long ;sysno + int ;kernel fd + int ;initrd fd + unsigned-long ;cmdline length + '* ;cmdline + unsigned-long))) ;flags + ;; TODO: Don't do this. + (syscall-id (match (utsname:machine (uname)) + ("i686" 320) + ("x86_64" 320) + ("armv7l" 401) + ("aarch64" 401) + ;; XXX: There's apparently no support for ppc64le and + ;; riscv64. + (_ #f)))) + (lambda* (kernel-fd initrd-fd command-line #:optional (flags 0)) + "Load for eventual use of kexec(8) the Linux kernel from +@var{kernel-fd}, its initial RAM disk from @var{initrd-fd}, with the given +@var{command-line} (a string). Optionally, @var{flags} can be a bitwise or of +the KEXEC_FILE_* constants." + (let*-values (((command-line) + (string->utf-8/nul-terminated command-line)) + ((ret err) + (proc syscall-id kernel-fd initrd-fd + (bytevector-length command-line) + (bytevector->pointer command-line) + flags))) + (when (= ret -1) + (throw 'system-error "kexec-load-file" "~A" + (list (strerror err)) + (list err))))))) + (define (linux-process-flags pid) ;copied from the Shepherd "Return the process flags of @var{pid} (or'd @code{PF_} constants), assuming the Linux /proc file system is mounted; raise a @code{system-error} exception diff --git a/tests/syscalls.scm b/tests/syscalls.scm index 13f4f11721..eef864d097 100644 --- a/tests/syscalls.scm +++ b/tests/syscalls.scm @@ -679,6 +679,19 @@ (define perform-container-tests? (lambda args (system-error-errno args)))))) +(when (or (zero? (getuid)) + (not (string-contains %host-type "linux"))) + (test-skip 1)) +(test-equal "kexec-load-file" + EPERM + (catch 'system-error + (lambda () + (let ((fd1 (open-fdes "/dev/null" O_RDONLY)) + (fd2 (open-fdes "/dev/null" O_RDONLY))) + (kexec-load-file fd1 fd2 "gnu.repl=yes"))) + (lambda args + (system-error-errno args)))) + (test-end) (false-if-exception (delete-file temp-file)) -- 2.46.0