get:
Show a patch.

patch:
Update a patch.

put:
Update a patch.

GET /api/patches/1707752/?format=api
HTTP 200 OK
Allow: GET, PUT, PATCH, HEAD, OPTIONS
Content-Type: application/json
Vary: Accept

{
    "id": 1707752,
    "url": "http://patchwork.ozlabs.org/api/patches/1707752/?format=api",
    "web_url": "http://patchwork.ozlabs.org/project/linux-um/patch/20221122100759.208290-26-benjamin@sipsolutions.net/",
    "project": {
        "id": 60,
        "url": "http://patchwork.ozlabs.org/api/projects/60/?format=api",
        "name": "User-mode Linux Development",
        "link_name": "linux-um",
        "list_id": "linux-um.lists.infradead.org",
        "list_email": "linux-um@lists.infradead.org",
        "web_url": "",
        "scm_url": "",
        "webscm_url": "",
        "list_archive_url": "",
        "list_archive_url_format": "",
        "commit_url_format": ""
    },
    "msgid": "<20221122100759.208290-26-benjamin@sipsolutions.net>",
    "list_archive_url": null,
    "date": "2022-11-22T10:07:56",
    "name": "[v2,25/28] um: Add SECCOMP support detection and initialization",
    "commit_ref": null,
    "pull_url": null,
    "state": "not-applicable",
    "archived": false,
    "hash": "3c8ee6a4759cdd93b0fc11c932d204d070e4bac1",
    "submitter": {
        "id": 67525,
        "url": "http://patchwork.ozlabs.org/api/people/67525/?format=api",
        "name": "Benjamin Berg",
        "email": "benjamin@sipsolutions.net"
    },
    "delegate": {
        "id": 54851,
        "url": "http://patchwork.ozlabs.org/api/users/54851/?format=api",
        "username": "rw",
        "first_name": "Richard",
        "last_name": "Weinberger",
        "email": "richard@nod.at"
    },
    "mbox": "http://patchwork.ozlabs.org/project/linux-um/patch/20221122100759.208290-26-benjamin@sipsolutions.net/mbox/",
    "series": [
        {
            "id": 329466,
            "url": "http://patchwork.ozlabs.org/api/series/329466/?format=api",
            "web_url": "http://patchwork.ozlabs.org/project/linux-um/list/?series=329466",
            "date": "2022-11-22T10:07:37",
            "name": "Implement SECCOMP based userland",
            "version": 2,
            "mbox": "http://patchwork.ozlabs.org/series/329466/mbox/"
        }
    ],
    "comments": "http://patchwork.ozlabs.org/api/patches/1707752/comments/",
    "check": "pending",
    "checks": "http://patchwork.ozlabs.org/api/patches/1707752/checks/",
    "tags": {},
    "related": [],
    "headers": {
        "Return-Path": "\n <linux-um-bounces+incoming=patchwork.ozlabs.org@lists.infradead.org>",
        "X-Original-To": "incoming@patchwork.ozlabs.org",
        "Delivered-To": "patchwork-incoming@legolas.ozlabs.org",
        "Authentication-Results": [
            "legolas.ozlabs.org;\n spf=none (no SPF record) smtp.mailfrom=lists.infradead.org\n (client-ip=2607:7c80:54:3::133; helo=bombadil.infradead.org;\n envelope-from=linux-um-bounces+incoming=patchwork.ozlabs.org@lists.infradead.org;\n receiver=<UNKNOWN>)",
            "legolas.ozlabs.org;\n\tdkim=pass (2048-bit key;\n secure) header.d=lists.infradead.org header.i=@lists.infradead.org\n header.a=rsa-sha256 header.s=bombadil.20210309 header.b=xp06sENd;\n\tdkim=fail reason=\"signature verification failed\" (2048-bit key;\n secure) header.d=sipsolutions.net header.i=@sipsolutions.net\n header.a=rsa-sha256 header.s=mail header.b=dLRPXAdF;\n\tdkim-atps=neutral"
        ],
        "Received": [
            "from bombadil.infradead.org (bombadil.infradead.org\n [IPv6:2607:7c80:54:3::133])\n\t(using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits)\n\t key-exchange X25519 server-signature ECDSA (P-384) server-digest SHA384)\n\t(No client certificate requested)\n\tby legolas.ozlabs.org (Postfix) with ESMTPS id 4NGg5l1Yrvz23nm\n\tfor <incoming@patchwork.ozlabs.org>; Tue, 22 Nov 2022 21:11:39 +1100 (AEDT)",
            "from localhost ([::1] helo=bombadil.infradead.org)\n\tby bombadil.infradead.org with esmtp (Exim 4.94.2 #2 (Red Hat Linux))\n\tid 1oxQFT-007g7p-TN; Tue, 22 Nov 2022 10:11:27 +0000",
            "from s3.sipsolutions.net ([2a01:4f8:191:4433::2]\n helo=sipsolutions.net)\n\tby bombadil.infradead.org with esmtps (Exim 4.94.2 #2 (Red Hat Linux))\n\tid 1oxQF2-007fee-U0\n\tfor linux-um@lists.infradead.org; Tue, 22 Nov 2022 10:11:10 +0000",
            "by sipsolutions.net with esmtpsa\n (TLS1.3:ECDHE_X25519__RSA_PSS_RSAE_SHA256__AES_256_GCM:256)\n\t(Exim 4.96)\n\t(envelope-from <benjamin@sipsolutions.net>)\n\tid 1oxQEu-006IGn-1L;\n\tTue, 22 Nov 2022 11:10:52 +0100"
        ],
        "DKIM-Signature": [
            "v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed;\n\td=lists.infradead.org; s=bombadil.20210309; h=Sender:\n\tContent-Transfer-Encoding:Content-Type:List-Subscribe:List-Help:List-Post:\n\tList-Archive:List-Unsubscribe:List-Id:MIME-Version:References:In-Reply-To:\n\tMessage-Id:Date:Subject:Cc:To:From:Reply-To:Content-ID:Content-Description:\n\tResent-Date:Resent-From:Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID:\n\tList-Owner; bh=2rhSc5wDBU79DEn8E04pU/Bss+i/ENtiGb4Dv4IETAI=; b=xp06sENdh8a277\n\toSD9gus3rvibTr2ej1giHzdjLtcYVVp5Xv9/hHmGmI+8H/ZbZxwJ33m1ccP1JUh0/wEQrJxdHAnDK\n\tjSbRkj054W4EiMJNSw+AW/xpfHwZxENX3xFCxRdZGoUy78+8fipmPikdNn0fZxX4qRh7r3zQmcYet\n\tuPNZK1TeJzAkzsOxgoXM+PIW+Inawdf1AREtkf2599bEwmi/s5tV67F74tkNj2C/hBt2UwSB8PPOz\n\tLDudt2eeuu7i/GuYf9kUIm1L+797Gjx1wC64/9jNsFqsr/skKadyE+KkRf+pE1zFF2Hd+Gri3IMM+\n\ts8tymWOoSgzrGcvSBB9A==;",
            "v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed;\n\td=sipsolutions.net; s=mail; h=Content-Transfer-Encoding:MIME-Version:\n\tReferences:In-Reply-To:Message-Id:Date:Subject:Cc:To:From:Content-Type:Sender\n\t:Reply-To:Content-ID:Content-Description:Resent-Date:Resent-From:Resent-To:\n\tResent-Cc:Resent-Message-ID; bh=84kn9+/iVI02EtcyRQnFNVnoxVe0yKlrS5ZZyVCDKDQ=;\n\tt=1669111860; x=1670321460; b=dLRPXAdFL9YUooU1+nOWuzYr6vQkXjqCztYH5Jd5u7e0CB9\n\tcrx3DcFn4wjb0ZYwIJCVO/Bv3wKJ6leTNhKyzKj3ez/WwGks7z6Udgcw//r48d3u2PJxqJDJCJoJi\n\toQ9rJFrKqaCm7dd8LE1Atv1n+attKUKOUdhdda0AJupmVEEDmu7kxn2ADSp6kSZE78iw3O3rXe2mg\n\t507oM1eYPQrtcG6swwJfwraLqjT/qIe5vNhEqrgQOX55jdVqerpjyViASC712sz4FrfCAJinTF1oT\n\tA182KBetB6yy2pxHWnipPU/2Uu86ebzsDo4rCbY4sbUkRdOfU5cl4oPM0zuijVDg==;"
        ],
        "From": "benjamin@sipsolutions.net",
        "To": "linux-um@lists.infradead.org",
        "Cc": "Benjamin Berg <benjamin@sipsolutions.net>",
        "Subject": "[PATCH v2 25/28] um: Add SECCOMP support detection and initialization",
        "Date": "Tue, 22 Nov 2022 11:07:56 +0100",
        "Message-Id": "<20221122100759.208290-26-benjamin@sipsolutions.net>",
        "X-Mailer": "git-send-email 2.38.1",
        "In-Reply-To": "<20221122100759.208290-1-benjamin@sipsolutions.net>",
        "References": "<20221122100759.208290-1-benjamin@sipsolutions.net>",
        "MIME-Version": "1.0",
        "X-CRM114-Version": "20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 ",
        "X-CRM114-CacheID": "sfid-20221122_021101_098213_0ACD1BF7 ",
        "X-CRM114-Status": "GOOD (  22.28  )",
        "X-Spam-Score": "-0.2 (/)",
        "X-Spam-Report": "Spam detection software,\n running on the system \"bombadil.infradead.org\",\n has NOT identified this incoming email as spam.  The original\n message has been attached to this so you can view it or label\n similar future email.  If you have any questions, see\n the administrator of that system for details.\n Content preview:  From: Benjamin Berg <benjamin@sipsolutions.net> This\n detects\n    seccomp support, sets the global using_seccomp variable and initilizes the\n    exec registers. For now,\n the implementation simply falls through to the ptrace\n    startup code, meaning that it is [...]\n Content analysis details:   (-0.2 points, 5.0 required)\n  pts rule name              description\n ---- ----------------------\n --------------------------------------------------\n -0.0 SPF_PASS               SPF: sender matches SPF record\n -0.0 SPF_HELO_PASS          SPF: HELO matches SPF record\n -0.1 DKIM_VALID_AU          Message has a valid DKIM or DK signature from\n                             author's domain\n -0.1 DKIM_VALID             Message has at least one valid DKIM or DK\n signature\n  0.1 DKIM_SIGNED            Message has a DKIM or DK signature,\n not necessarily\n                             valid\n -0.1 DKIM_VALID_EF          Message has a valid DKIM or DK signature from\n                             envelope-from domain",
        "X-BeenThere": "linux-um@lists.infradead.org",
        "X-Mailman-Version": "2.1.34",
        "Precedence": "list",
        "List-Id": "<linux-um.lists.infradead.org>",
        "List-Unsubscribe": "<http://lists.infradead.org/mailman/options/linux-um>,\n <mailto:linux-um-request@lists.infradead.org?subject=unsubscribe>",
        "List-Archive": "<http://lists.infradead.org/pipermail/linux-um/>",
        "List-Post": "<mailto:linux-um@lists.infradead.org>",
        "List-Help": "<mailto:linux-um-request@lists.infradead.org?subject=help>",
        "List-Subscribe": "<http://lists.infradead.org/mailman/listinfo/linux-um>,\n <mailto:linux-um-request@lists.infradead.org?subject=subscribe>",
        "Content-Type": "text/plain; charset=\"us-ascii\"",
        "Content-Transfer-Encoding": "7bit",
        "Sender": "\"linux-um\" <linux-um-bounces@lists.infradead.org>",
        "Errors-To": "linux-um-bounces+incoming=patchwork.ozlabs.org@lists.infradead.org"
    },
    "content": "From: Benjamin Berg <benjamin@sipsolutions.net>\n\nThis detects seccomp support, sets the global using_seccomp variable and\ninitilizes the exec registers. For now, the implementation simply falls\nthrough to the ptrace startup code, meaning that it is unused.\n\nSigned-off-by: Benjamin Berg <benjamin@sipsolutions.net>\n---\n arch/um/include/shared/skas/skas.h |   6 ++\n arch/um/os-Linux/registers.c       |   4 +-\n arch/um/os-Linux/skas/process.c    |   3 +\n arch/um/os-Linux/start_up.c        | 136 ++++++++++++++++++++++++++++-\n 4 files changed, 145 insertions(+), 4 deletions(-)",
    "diff": "diff --git a/arch/um/include/shared/skas/skas.h b/arch/um/include/shared/skas/skas.h\nindex c93d2cbc8f32..f10599995d4d 100644\n--- a/arch/um/include/shared/skas/skas.h\n+++ b/arch/um/include/shared/skas/skas.h\n@@ -6,8 +6,14 @@\n #ifndef __SKAS_H\n #define __SKAS_H\n \n+#include <linux/kconfig.h>\n #include <sysdep/ptrace.h>\n \n+#ifdef CONFIG_UML_SECCOMP\n+extern int using_seccomp;\n+#else\n+#define using_seccomp 0\n+#endif\n extern int userspace_pid[];\n \n extern int user_thread(unsigned long stack, int flags);\ndiff --git a/arch/um/os-Linux/registers.c b/arch/um/os-Linux/registers.c\nindex bd80b921add0..528381496aa7 100644\n--- a/arch/um/os-Linux/registers.c\n+++ b/arch/um/os-Linux/registers.c\n@@ -13,8 +13,8 @@\n \n /* This is set once at boot time and not changed thereafter */\n \n-static unsigned long exec_regs[MAX_REG_NR];\n-static unsigned long exec_fp_regs[FP_SIZE];\n+unsigned long exec_regs[MAX_REG_NR];\n+unsigned long exec_fp_regs[FP_SIZE];\n \n int init_pid_registers(int pid)\n {\ndiff --git a/arch/um/os-Linux/skas/process.c b/arch/um/os-Linux/skas/process.c\nindex cdbab5a864e4..44a7d49538ce 100644\n--- a/arch/um/os-Linux/skas/process.c\n+++ b/arch/um/os-Linux/skas/process.c\n@@ -247,6 +247,9 @@ static int userspace_tramp(void *stack)\n \treturn 0;\n }\n \n+#ifdef CONFIG_UML_SECCOMP\n+int using_seccomp;\n+#endif\n int userspace_pid[NR_CPUS];\n int kill_userspace_mm[NR_CPUS];\n \ndiff --git a/arch/um/os-Linux/start_up.c b/arch/um/os-Linux/start_up.c\nindex 8b0e98ab842c..f84eb13a0b98 100644\n--- a/arch/um/os-Linux/start_up.c\n+++ b/arch/um/os-Linux/start_up.c\n@@ -1,8 +1,10 @@\n // SPDX-License-Identifier: GPL-2.0\n /*\n+ * Copyright (C) 2021 Benjamin Berg <benjamin@sipsolutions.net>\n  * Copyright (C) 2000 - 2007 Jeff Dike (jdike@{addtoit,linux.intel}.com)\n  */\n \n+#include <linux/kconfig.h>\n #include <stdio.h>\n #include <stdlib.h>\n #include <stdarg.h>\n@@ -22,8 +24,17 @@\n #include <os.h>\n #include <mem_user.h>\n #include <ptrace_user.h>\n+#ifdef CONFIG_UML_SECCOMP\n+#include <stdbool.h>\n+#include <stub-data.h>\n+#include <sys/prctl.h>\n+#include <linux/seccomp.h>\n+#include <linux/filter.h>\n+#include <sysdep/mcontext.h>\n+#endif\n #include <registers.h>\n #include <skas.h>\n+#include <sysdep/stub.h>\n \n static void ptrace_child(void)\n {\n@@ -221,6 +232,114 @@ static void __init check_ptrace(void)\n \tcheck_sysemu();\n }\n \n+#ifdef CONFIG_UML_SECCOMP\n+extern unsigned long exec_regs[MAX_REG_NR];\n+extern unsigned long exec_fp_regs[FP_SIZE];\n+\n+static void __init sigsys_handler(int sig, siginfo_t *info, void *p)\n+{\n+\tstruct stub_data *data = get_stub_page();\n+\tucontext_t *uc = p;\n+\n+\t/* Stow away the location of the mcontext in the stack */\n+\tdata->mctx_offset = (unsigned long)&uc->uc_mcontext -\n+\t\t\t    (unsigned long)&data->sigstack[0];\n+\texit(0);\n+}\n+\n+static bool __init init_seccomp(void)\n+{\n+\tstruct stub_data *data;\n+\tint pid;\n+\tint status;\n+\tint n;\n+\n+\t/* We check that we can install a seccomp filter and then exit(0)\n+\t * from a trapped syscall.\n+\t *\n+\t * Note that we cannot verify that no seccomp filter already exists\n+\t * for a syscall that results in the process/thread to be killed.\n+\t */\n+\n+\tos_info(\"Checking that seccomp filters can be installed...\");\n+\n+\tdata = mmap(0, sizeof(*data),\n+\t\t    PROT_READ | PROT_WRITE, MAP_SHARED | MAP_ANON, 0, 0);\n+\n+\tpid = fork();\n+\tif (pid == 0) {\n+\t\tstatic struct sock_filter filter[] = {\n+\t\t\tBPF_STMT(BPF_LD | BPF_W | BPF_ABS,\n+\t\t\t\toffsetof(struct seccomp_data, nr)),\n+\t\t\tBPF_JUMP(BPF_JMP | BPF_JEQ | BPF_K, __NR_clock_nanosleep, 1, 0),\n+\t\t\tBPF_STMT(BPF_RET | BPF_K, SECCOMP_RET_ALLOW),\n+\t\t\tBPF_STMT(BPF_RET | BPF_K, SECCOMP_RET_TRAP),\n+\t\t};\n+\t\tstatic struct sock_fprog prog = {\n+\t\t\t.len = ARRAY_SIZE(filter),\n+\t\t\t.filter = filter,\n+\t\t};\n+\t\tstruct sigaction sa;\n+\n+\t\tset_sigstack(data->sigstack, sizeof(data->sigstack));\n+\n+\t\tsa.sa_flags = SA_ONSTACK | SA_NODEFER | SA_SIGINFO;\n+\t\tsa.sa_sigaction = (void *) sigsys_handler;\n+\t\tsa.sa_restorer = NULL;\n+\t\tif (sigaction(SIGSYS, &sa, NULL) < 0)\n+\t\t\texit(1);\n+\n+\t\tprctl(PR_SET_NO_NEW_PRIVS, 1, 0, 0, 0);\n+\t\tif (syscall(__NR_seccomp, SECCOMP_SET_MODE_FILTER,\n+\t\t\t    SECCOMP_FILTER_FLAG_TSYNC, &prog) != 0)\n+\t\t\texit(2);\n+\n+\t\tsleep(0);\n+\n+\t\t/* Never reached. */\n+\t\texit(3);\n+\t}\n+\n+\tif (pid < 0)\n+\t\tfatal_perror(\"check_seccomp : fork failed\");\n+\n+\tCATCH_EINTR(n = waitpid(pid, &status, 0));\n+\tif (n < 0)\n+\t\tfatal_perror(\"check_seccomp : waitpid failed\");\n+\n+\tif (WIFEXITED(status) && WEXITSTATUS(status) == 0) {\n+\t\tint r;\n+\t\tstruct uml_pt_regs *regs = calloc(sizeof(struct uml_pt_regs), 1);\n+\n+\t\t/* Copy registers, the init_registers function assumes ptrace. */\n+\t\tr = get_stub_state(regs, data);\n+\n+\t\tmemcpy(exec_regs, regs->gp, sizeof(exec_regs));\n+\t\tmemcpy(exec_fp_regs, regs->fp, sizeof(exec_fp_regs));\n+\n+\t\tmunmap(data, sizeof(*data));\n+\n+\t\tfree(regs);\n+\n+\t\tif (r) {\n+\t\t\tos_info(\"failed to fetch registers\\n\");\n+\t\t\treturn false;\n+\t\t}\n+\n+\t\tos_info(\"OK\\n\");\n+\t\treturn true;\n+\t}\n+\n+\tif (WIFEXITED(status) && WEXITSTATUS(status) == 2)\n+\t\tos_info(\"missing\\n\");\n+\telse\n+\t\tos_info(\"error\\n\");\n+\n+\tmunmap(data, sizeof(*data));\n+\treturn false;\n+}\n+#endif\n+\n extern void check_tmpexec(void);\n \n static void __init check_coredump_limit(void)\n@@ -285,13 +404,26 @@ void __init os_early_checks(void)\n \t/* Print out the core dump limits early */\n \tcheck_coredump_limit();\n \n-\tcheck_ptrace();\n-\n \t/* Need to check this early because mmapping happens before the\n \t * kernel is running.\n \t */\n \tcheck_tmpexec();\n \n+#ifdef CONFIG_UML_SECCOMP\n+\tusing_seccomp = 0;\n+\n+\tif (init_seccomp()) {\n+\t\t/* Not fully implemented */\n+#if 0\n+\t\tusing_seccomp = 1;\n+\n+\t\treturn;\n+#endif\n+\t}\n+#endif\n+\n+\tcheck_ptrace();\n+\n \tpid = start_ptraced_child();\n \tif (init_pid_registers(pid))\n \t\tfatal(\"Failed to initialize default registers\");\n",
    "prefixes": [
        "v2",
        "25/28"
    ]
}