get:
Show a patch.

patch:
Update a patch.

put:
Update a patch.

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

{
    "id": 1707753,
    "url": "http://patchwork.ozlabs.org/api/patches/1707753/?format=api",
    "web_url": "http://patchwork.ozlabs.org/project/linux-um/patch/20221122100759.208290-25-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-25-benjamin@sipsolutions.net>",
    "list_archive_url": null,
    "date": "2022-11-22T10:07:55",
    "name": "[v2,24/28] um: Add helper functions to get/set state for SECCOMP",
    "commit_ref": null,
    "pull_url": null,
    "state": "not-applicable",
    "archived": false,
    "hash": "c1ced619b2872a7e9abac8a446d65cb9cea50c64",
    "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-25-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/1707753/comments/",
    "check": "pending",
    "checks": "http://patchwork.ozlabs.org/api/patches/1707753/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=hhNRvaFf;\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=WM4vWLuO;\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 4NGg5l18lvz23nl\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-007g6x-Dc; 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-007feb-Rd\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-0G;\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=c4aFHu+l9Wzui/A/3IwKzlV1K0FpZfeLKVkNUBOOIUg=; b=hhNRvaFfvr4mgR\n\t/MLgQvgK1fXgKpmxL5Iwg8NsSNG9sa93g26dr+7uVXKxzVqHNOOQrJV8JtGgAys08cLP5jsGWfdjh\n\tMQbCKMkFnYit+NylG6plAwgiV/uqAGVjbLgPBKZ+VJRXmsIWeFZaQdkzgYiq/IfCWcFPyAOXP+a4U\n\tH2RqDTkQ1+KcZ4EpkOfqjl2db8H9EW9yPZGh/0DbG9xJ4RhT1RecVX0giVNROqqBAJQMgsqfpYohM\n\te1LZ9KvPZaaK0idGDXrS9cwO2UWth3VhkEm6wk4zgzmUiND+LbKsoYd5LgNdZJev5JdHWA7vqNwdJ\n\t6nMiQBsRmQ8oIdr52TQQ==;",
            "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=VcX66A7Z04I/ktDonzlZ4VvTIrbkSekpfhT9X9v0axM=;\n\tt=1669111860; x=1670321460; b=WM4vWLuOslp2dcMdLcoC7PXNQDrQUX0g3ErIMuDzm7IpoJ9\n\tRyDPf2wqv7Ni4CItfTNwEbAzVPLMOSCpFfpmk6ZOsdfM9DFEtDeqkd3qDA3mEqxJ3na1lCCJNpKUJ\n\tlK1bwqf5p++LsvQsGtRmoseNSt/LL0bhzzt0MTyPlOcUrUBhnCt3DDi9sDiWh2w5hKASgYWw1BQbH\n\t5fFFkMffOywnfZ8QWD6JcqPaIbIQd9llNs7A49G0SAVdpzVaxoZYofJQQBZUwjX4ZWSBHKfNZ65c2\n\tAjWWPlzjtwTNiqE4CB5vGrz4DoN9ECHdyvMAEJWzf3EWfza7cw0czNlO1iE3Oubg==;"
        ],
        "From": "benjamin@sipsolutions.net",
        "To": "linux-um@lists.infradead.org",
        "Cc": "Benjamin Berg <benjamin@sipsolutions.net>",
        "Subject": "[PATCH v2 24/28] um: Add helper functions to get/set state for\n SECCOMP",
        "Date": "Tue, 22 Nov 2022 11:07:55 +0100",
        "Message-Id": "<20221122100759.208290-25-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_140935_29504016 ",
        "X-CRM114-Status": "GOOD (  16.98  )",
        "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> When not\n using\n    ptrace, we need to both save and restore registers through the mcontext as\n    provided by the host kernel to our signal handlers. Add corresponding\n functions\n    to store the state to an mcontext and helpers to access the mcontext of\n the\n    subprocess through the stub data.\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\nWhen not using ptrace, we need to both save and restore registers\nthrough the mcontext as provided by the host kernel to our signal\nhandlers.\n\nAdd corresponding functions to store the state to an mcontext and\nhelpers to access the mcontext of the subprocess through the stub data.\n\nSigned-off-by: Benjamin Berg <benjamin@sipsolutions.net>\n---\n arch/um/include/shared/common-offsets.h |   9 +-\n arch/x86/um/os-Linux/mcontext.c         | 150 +++++++++++++++++++++++-\n arch/x86/um/shared/sysdep/mcontext.h    |   9 ++\n 3 files changed, 166 insertions(+), 2 deletions(-)",
    "diff": "diff --git a/arch/um/include/shared/common-offsets.h b/arch/um/include/shared/common-offsets.h\nindex 579ed946a3a9..307dba626001 100644\n--- a/arch/um/include/shared/common-offsets.h\n+++ b/arch/um/include/shared/common-offsets.h\n@@ -28,4 +28,11 @@ DEFINE(UML_CONFIG_64BIT, CONFIG_64BIT);\n #ifdef CONFIG_UML_TIME_TRAVEL_SUPPORT\n DEFINE(UML_CONFIG_UML_TIME_TRAVEL_SUPPORT, CONFIG_UML_TIME_TRAVEL_SUPPORT);\n #endif\n-\n+#ifdef CONFIG_UML_SECCOMP\n+DEFINE(UM_FPSTATE_EXTENDED_SIZE,\n+       offsetof(struct _fpstate, sw_reserved)\n+       + offsetof(struct _fpx_sw_bytes, extended_size));\n+DEFINE(UM_FPSTATE_XSTATE_SIZE,\n+       offsetof(struct _fpstate, sw_reserved)\n+       + offsetof(struct _fpx_sw_bytes, xstate_size));\n+#endif\ndiff --git a/arch/x86/um/os-Linux/mcontext.c b/arch/x86/um/os-Linux/mcontext.c\nindex 81b9d1f9f4e6..aabebe58fb25 100644\n--- a/arch/x86/um/os-Linux/mcontext.c\n+++ b/arch/x86/um/os-Linux/mcontext.c\n@@ -1,8 +1,12 @@\n // SPDX-License-Identifier: GPL-2.0\n-#include <sys/ucontext.h>\n #define __FRAME_OFFSETS\n #include <asm/ptrace.h>\n #include <sysdep/ptrace.h>\n+#include <string.h>\n+#include <signal.h>\n+#include <sysdep/mcontext.h>\n+#include <linux/errno.h>\n+#include <generated/asm-offsets.h>\n \n void get_regs_from_mc(struct uml_pt_regs *regs, mcontext_t *mc)\n {\n@@ -16,6 +20,10 @@ void get_regs_from_mc(struct uml_pt_regs *regs, mcontext_t *mc)\n \tCOPY2(UESP, ESP); /* sic */\n \tCOPY(EBX); COPY(EDX); COPY(ECX); COPY(EAX);\n \tCOPY(EIP); COPY_SEG_CPL3(CS); COPY(EFL); COPY_SEG_CPL3(SS);\n+#undef COPY2\n+#undef COPY\n+#undef COPY_SEG\n+#undef COPY_SEG_CPL3\n #else\n #define COPY2(X,Y) regs->gp[X/sizeof(unsigned long)] = mc->gregs[REG_##Y]\n #define COPY(X) regs->gp[X/sizeof(unsigned long)] = mc->gregs[REG_##X]\n@@ -27,5 +35,145 @@ void get_regs_from_mc(struct uml_pt_regs *regs, mcontext_t *mc)\n \tCOPY2(EFLAGS, EFL);\n \tCOPY2(CS, CSGSFS);\n \tregs->gp[SS / sizeof(unsigned long)] = mc->gregs[REG_CSGSFS] >> 48;\n+#undef COPY2\n+#undef COPY\n #endif\n }\n+\n+#ifdef CONFIG_UML_SECCOMP\n+/* Same thing, but the copy macros are turned around. */\n+void get_mc_from_regs(struct uml_pt_regs *regs, mcontext_t *mc, int single_stepping)\n+{\n+#ifdef __i386__\n+#define COPY2(X,Y) mc->gregs[REG_##Y] = regs->gp[X]\n+#define COPY(X) mc->gregs[REG_##X] = regs->gp[X]\n+#define COPY_SEG(X) mc->gregs[REG_##X] = mc->gregs[REG_##X] & 0xffff;\n+#define COPY_SEG_CPL3(X) mc->gregs[REG_##X] = (regs->gp[X] & 0xffff) | 3;\n+\tCOPY_SEG(GS); COPY_SEG(FS); COPY_SEG(ES); COPY_SEG(DS);\n+\tCOPY(EDI); COPY(ESI); COPY(EBP);\n+\tCOPY2(UESP, ESP); /* sic */\n+\tCOPY(EBX); COPY(EDX); COPY(ECX); COPY(EAX);\n+\tCOPY(EIP); COPY_SEG_CPL3(CS); COPY(EFL); COPY_SEG_CPL3(SS);\n+#else\n+#define COPY2(X,Y) mc->gregs[REG_##Y] = regs->gp[X/sizeof(unsigned long)]\n+#define COPY(X) mc->gregs[REG_##X] = regs->gp[X/sizeof(unsigned long)]\n+\tCOPY(R8); COPY(R9); COPY(R10); COPY(R11);\n+\tCOPY(R12); COPY(R13); COPY(R14); COPY(R15);\n+\tCOPY(RDI); COPY(RSI); COPY(RBP); COPY(RBX);\n+\tCOPY(RDX); COPY(RAX); COPY(RCX); COPY(RSP);\n+\tCOPY(RIP);\n+\tCOPY2(EFLAGS, EFL);\n+\tmc->gregs[REG_CSGSFS] = mc->gregs[REG_CSGSFS] & 0xffffffffffffl;\n+\tmc->gregs[REG_CSGSFS] |= (regs->gp[SS / sizeof(unsigned long)] & 0xffff) << 48;\n+#endif\n+\n+\tif (single_stepping)\n+\t\tmc->gregs[REG_EFL] |= X86_EFLAGS_TF;\n+\telse\n+\t\tmc->gregs[REG_EFL] &= ~X86_EFLAGS_TF;\n+}\n+\n+int get_stub_state(struct uml_pt_regs *regs, struct stub_data *data)\n+{\n+\tmcontext_t *mcontext;\n+\tunsigned long fp_regs;\n+\tint fp_size;\n+\n+\t/* mctx_offset is verified by wait_stub_done_seccomp */\n+\tmcontext = (void *)&data->sigstack[data->mctx_offset];\n+\n+\tget_regs_from_mc(regs, mcontext);\n+\n+\t/* Assume floating point registers are on the same page */\n+\tfp_regs = (((unsigned long)mcontext->fpregs &\n+\t\t    (UM_KERN_PAGE_SIZE - 1)) +\n+\t\t   (unsigned long)&data->sigstack[0]);\n+\n+\t/* Use extended_size, but never touch the trailing magic\n+\t * (as it may not fit our internal storage)\n+\t */\n+\tfp_size = *(int *)(fp_regs + UM_FPSTATE_EXTENDED_SIZE)\n+\t\t  - FP_XSTATE_MAGIC2_SIZE;\n+\n+\tif (fp_size > sizeof(regs->fp))\n+\t\treturn -ENOSPC;\n+\n+\tif (fp_regs + fp_size > (unsigned long)data->sigstack +\n+\t\t\t\tsizeof(data->sigstack))\n+\t\treturn -EINVAL;\n+\n+\tmemcpy(&regs->fp, (void *)fp_regs, fp_size);\n+\n+\t/* We do not need to read the x86_64 FS_BASE/GS_BASE registers as\n+\t * we do not permit userspace to set them directly.\n+\t */\n+\n+\treturn 0;\n+}\n+\n+int set_stub_state(struct uml_pt_regs *regs, struct stub_data *data,\n+\t\t   int single_stepping)\n+{\n+\tmcontext_t *mcontext;\n+\tunsigned long fp_regs;\n+\tint fp_size;\n+\tint fp_size_stub;\n+\n+\t/* mctx_offset is verified by wait_stub_done_seccomp */\n+\tmcontext = (void *)&data->sigstack[data->mctx_offset];\n+\n+\tif ((unsigned long)mcontext < (unsigned long)data->sigstack ||\n+\t    (unsigned long)mcontext >\n+\t\t\t(unsigned long) data->sigstack +\n+\t\t\tsizeof(data->sigstack) - sizeof(*mcontext))\n+\t\treturn -EINVAL;\n+\n+\tget_mc_from_regs(regs, mcontext, single_stepping);\n+\n+\t/* Assume floating point registers are on the same page */\n+\tfp_regs = (((unsigned long)mcontext->fpregs &\n+\t\t    (UM_KERN_PAGE_SIZE - 1)) +\n+\t\t   (unsigned long)&data->sigstack[0]);\n+\n+\t/* Use extended_size, but never touch the trailing magic\n+\t * (as it may not fit our internal storage)\n+\t */\n+\tfp_size = *(int *)((unsigned long) &regs->fp +\n+\t\t\t   UM_FPSTATE_EXTENDED_SIZE) -\n+\t\t  FP_XSTATE_MAGIC2_SIZE;\n+\tfp_size_stub = *(int *)(fp_regs + UM_FPSTATE_EXTENDED_SIZE) -\n+\t\t       FP_XSTATE_MAGIC2_SIZE;\n+\n+\t/* Can we fit it, or would we need an alternative memory location? */\n+\tif (fp_size > fp_size_stub)\n+\t\treturn -ENOSPC;\n+\n+\tif (fp_regs + fp_size > (unsigned long)data->sigstack +\n+\t\t\t\tsizeof(data->sigstack))\n+\t\treturn -EINVAL;\n+\n+\tmemcpy((void *) fp_regs, &regs->fp, fp_size);\n+\n+#ifdef __i386__\n+\t/*\n+\t * On x86, we need to sync the GDT entries for the thread local storage.\n+\t */\n+\t#error \"Not implemented\"\n+#else\n+\t/*\n+\t * On x86_64, we need to sync the FS_BASE/GS_BASE registers using the\n+\t * arch specific data.\n+\t */\n+\tif (data->arch_data.fs_base != regs->gp[FS_BASE / sizeof(unsigned long)]) {\n+\t\tdata->arch_data.fs_base = regs->gp[FS_BASE / sizeof(unsigned long)];\n+\t\tdata->arch_data.sync |= STUB_SYNC_FS_BASE;\n+\t}\n+\tif (data->arch_data.gs_base != regs->gp[GS_BASE / sizeof(unsigned long)]) {\n+\t\tdata->arch_data.gs_base = regs->gp[GS_BASE / sizeof(unsigned long)];\n+\t\tdata->arch_data.sync |= STUB_SYNC_GS_BASE;\n+\t}\n+#endif\n+\n+\treturn 0;\n+}\n+#endif\ndiff --git a/arch/x86/um/shared/sysdep/mcontext.h b/arch/x86/um/shared/sysdep/mcontext.h\nindex b724c54da316..3ea6da0dbe9d 100644\n--- a/arch/x86/um/shared/sysdep/mcontext.h\n+++ b/arch/x86/um/shared/sysdep/mcontext.h\n@@ -6,7 +6,16 @@\n #ifndef __SYS_SIGCONTEXT_X86_H\n #define __SYS_SIGCONTEXT_X86_H\n \n+#include <linux/kconfig.h>\n+#include <stub-data.h>\n+\n extern void get_regs_from_mc(struct uml_pt_regs *, mcontext_t *);\n+extern void get_mc_from_regs(struct uml_pt_regs *regs, mcontext_t *mc,\n+\t\t\t     int single_stepping);\n+\n+extern int get_stub_state(struct uml_pt_regs *regs, struct stub_data *data);\n+extern int set_stub_state(struct uml_pt_regs *regs, struct stub_data *data,\n+\t\t\t  int single_stepping);\n \n #ifdef __i386__\n \n",
    "prefixes": [
        "v2",
        "24/28"
    ]
}