From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from mail-dy1-f175.google.com (mail-dy1-f175.google.com [74.125.82.175]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 3BB311E1DE5 for ; Sat, 27 Jun 2026 01:22:47 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=74.125.82.175 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1782523369; cv=none; b=NnTiE+L9iJQxvRFfFBiHixTmKloSxtMuiA6s+Y8uUUe3yyziGdwFIy+n7ccabo8F8Q3lL8qhgzEyUm917I82f/zrFh0viEvYgpD8qnf1tiuVtwNiNQP/D7jyRoR8boo1dnPZDoy4WJygVQ7l3U1r4s72J0ubeBft6l3TEvn4JC0= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1782523369; c=relaxed/simple; bh=yErg7DL+gilyg7HvbxAYgT+VNLPNqN+fYVUYSpa/szw=; h=From:To:Cc:Subject:Date:Message-ID:MIME-Version; b=JpK+N+mQa62AJE1G1F84t1IujaXrcGE+czhkY4GSq84eTwkoPCy/eU1FIz+9stv0TC5igSQclbi9HVURTCuadPdwazoLULswlGkBKp7Nh8QUWLz5GRQwC05KcO5x3dZ0Cw0qyAqquGRKyD5MJOkor/LH5F3vPNRTJwQScTC6Mcc= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com; spf=pass smtp.mailfrom=gmail.com; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b=KKNrqELO; arc=none smtp.client-ip=74.125.82.175 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=gmail.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b="KKNrqELO" Received: by mail-dy1-f175.google.com with SMTP id 5a478bee46e88-30bf8b2bd20so3397037eec.0 for ; Fri, 26 Jun 2026 18:22:47 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20251104; t=1782523367; x=1783128167; darn=vger.kernel.org; h=content-transfer-encoding:mime-version:message-id:date:subject:cc :to:from:from:to:cc:subject:date:message-id:reply-to; bh=yswF87AdudNlkEgsV8oWfEZga/XYLwGngCoYmrqp+BI=; b=KKNrqELOz5SXfneDhLujXeLA02XJIP0srqnb6M9ReYzs0zHXvV/eIM/qCL/6UqpK41 uzXIAd7mCYUKiAMrWwVtPB3fLaLABhSCkDknXgaJy2gGEBvCdHX5/Y5IozN8SjYCgKO7 yuJ0dRau9q6R0haInVCFpu9T03L3FTkQMyeyEYqRvjO05Lu8nn3W0EceuPG1DdpjmiBu HvCSJv2Q/F8mbEywUs5RhiD4hrvR++Lm370S6Qw/bjeXOLL6dH8vpzW+QHMnfLdNpMOn iJVNsejiUy0vYrW11Kz+e+/V0zeQa0Z3Z4e+Z117/1X6/+FkMxj60pqQiLRQZRj87Deb KJDg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20251104; t=1782523367; x=1783128167; h=content-transfer-encoding:mime-version:message-id:date:subject:cc :to:from:x-gm-gg:x-gm-message-state:from:to:cc:subject:date :message-id:reply-to; bh=yswF87AdudNlkEgsV8oWfEZga/XYLwGngCoYmrqp+BI=; b=irG6Eq64JW68DatVzGTDLbTiM9PjawG/JgO3yVMVZhND2IpGCXNv+v6BPlwCB9GUEI 2bQn0DgmtAtwR+GU0ggyhiGSyLWKxEC/+HuegsKpylJnofy262ZT+/SYCljSB4IXeucI BaOazEeMq5Ck8lhHlrnY/gMprtszjpWPoPvF0/nRtX8V2wkpl24nht6e3yQzK53T8Cka U0eLqtUV+qEzLSCBA6PeK2hoykjiF8xwBVEB2cGYn3GhlLPa8q3vhOo5+kS5iySqFxZe 708s1d+L9G4CBENW0AqygECP+XuH7PaMsNeFAz1S1xT/4ae3HFIVVpSx4U8X7lRMk6/k oATg== X-Forwarded-Encrypted: i=1; AHgh+RpgYuK4OGYB26xOToYij9MIKXe17Qgwu5szGvw1BMUUWOoIiovRYBAFZJorX/2ibz/SwjVTbMNl2uzBIUs=@vger.kernel.org X-Gm-Message-State: AOJu0YznUcpaXQsa5Q1UPpyvHFLVM0AKU+Z0Myq3+1R700YFcnCoFmfP FpMd9CJQEwBUBwhcGGpJki/7K6H0L0y1R3qPAy7JzMRoA/6/JL1+HUWY X-Gm-Gg: AfdE7cnMox9ZguGdJVDL8EQLPOlhrhTUI4ESI053hOe1vdMPnaaJPPofARlZZHTmyvY 7AaW85zGTXcJomHf2P8VVQZn+sfVHEXS0vNJHJ3OQ5aJYZgqzZ1Oh57iGc+mKdftB8vYqJ2TvHB iyC0ECFj2U2OTi3B9GQEsYxeqWraewa1NV77gT+Ol2fQeJ5Ur4mi14Gb4CiNmr9RiLj5I1mI4fG CdNm3GImYBzkl5Q8fSePzS0IY4s5YCSpl2wmoz+pGYCMS1JjKdI+gVcnm8FJl4hHouazhU13G8p NZLKCS5rDBvucS9ZZBTA6oQ+9+k7snR5m3bgrVm3GSvF/92YlMAiG6Bye1bhSGz0OWMUom3VK80 IVY5vZBMLePk5V4E8AJ/0gVtE9BB6OySel4sWRn9cx7DNvaVZVjERI9m2GOn4nFJFkJVP7f2DIO sVKDOX7lwHJeMihYhd5Xngareet8Sfu+q9YdQCRQibaZUp5ABY X-Received: by 2002:a05:7301:5f03:b0:306:f474:7389 with SMTP id 5a478bee46e88-30cab36ed99mr2110787eec.25.1782523367053; Fri, 26 Jun 2026 18:22:47 -0700 (PDT) Received: from pop-os.. ([2601:647:6802:dbc0:fe0d:366d:f00:1840]) by smtp.gmail.com with ESMTPSA id 5a478bee46e88-30c7c9e9214sm22883437eec.20.2026.06.26.18.22.45 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 26 Jun 2026 18:22:45 -0700 (PDT) From: Cong Wang To: Andy Lutomirski Cc: Kees Cook , linux-kernel@vger.kernel.org, Will Drewry , Christian Brauner , Andrew Morton , linux-mm@kvack.org, Cong Wang Subject: [PATCH v4 0/6] seccomp: non-cooperative pinned-memfd argument redirect Date: Fri, 26 Jun 2026 18:22:13 -0700 Message-ID: <20260627012219.1079851-1-xiyou.wangcong@gmail.com> X-Mailer: git-send-email 2.43.0 Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: 8bit The seccomp user-notification SECCOMP_USER_NOTIF_FLAG_CONTINUE response carries an inherent TOCTOU: once the supervisor decides to let a syscall continue, the target (or a CLONE_VM peer) can rewrite the memory behind a pointer argument before the kernel reads it. This is documented in the UAPI header and is why the notifier "cannot be used to implement a security policy" today. The cooperative way around this is for the target to map a shared memfd and mseal() it during a trusted setup window, so the supervisor can hand the kernel an immutable buffer. That window does not exist for the common fork()+execve() sandbox model, where the supervisor wants to confine an uncooperative (or legacy) binary it did not write. This series lets the supervisor close the TOCTOU without any target-side cooperation: - The kernel installs a sealed, read-only, MAP_SHARED mapping of a supervisor-owned memfd directly into the trapped task's mm (SECCOMP_IOCTL_NOTIF_PIN_INSTALL). The mapping is VM_SEALED at creation, so neither the target nor a CLONE_VM peer can unmap, remap, mprotect or MAP_FIXED-stomp it. The backing memfd must be write-sealed (F_SEAL_WRITE / F_SEAL_FUTURE_WRITE), so its bytes cannot be rewritten through any other reference either; the supervisor stages the argument data through its own pre-seal mapping. - The supervisor then resumes the syscall with selected argument registers rewritten (SECCOMP_IOCTL_NOTIF_SEND_REDIRECT), the pointer ones aimed into a pin. Each pointer substitution is validated so the whole access [ptr, ptr+len) lies inside a sealed, read-only pin of the supervisor's memfd that still lives in the target's current mm; original registers are restored at syscall exit for ABI compliance. Because the data the kernel acts on lives in an immutable pin, the target can no longer win the race. execve() is handled as a first-class case: its pathname is copied from the pin before the old mm is torn down, and the register-restore is skipped once the program image has been replaced (detected via self_exec_id). A redirected syscall is re-validated against the outer filters in the target's filter chain, so an inner notifier cannot use a redirect to smuggle a syscall past a policy an outer filter enforces (e.g. redirect to a blocked unshare()); see patch 4. sandlock [1], a non-cooperative seccomp sandbox supervisor, will use this to enforce argument-level policy on uncooperative targets. [1] https://github.com/multikernel/sandlock Patch 1 adds the mm plumbing: __do_mmap(), a variant of do_mmap() that targets a caller-supplied mm (do_mmap() stays a current->mm wrapper, so no existing caller changes), and vm_mmap_seal_remote(), a high-level helper for installing the sealed pin. Patch 2 adds PIN_INSTALL, patch 3 adds SEND_REDIRECT, patch 4 adds the outer-filter re-validation, patch 5 adds selftests, and patch 6 documents the ABI. Changes since v3: - Split the single seccomp patch into PIN_INSTALL (patch 2) and SEND_REDIRECT (patch 3) for reviewability. - New patch 4: re-validate a redirected syscall against the outer filters in the stack, closing the bypass Andy described (an inner notifier redirecting to a syscall an outer filter blocks, e.g. unshare()). - Signals: the argument restore now runs before signal/restart processing. It is queued as task_work with TWA_RESUME -- not the TWA_SIGNAL discussed on-list, which makes signal_pending() true for the whole redirected syscall and livelocks an interruptible one. TWA_RESUME still runs the restore at the top of get_signal(), before the signal frame is built and before any -ERESTART* rewind; on a restart the syscall re-traps seccomp and the supervisor is notified again. rt_sigreturn is refused (-EOPNOTSUPP). - At most one redirect-capable notifier may exist in a filter chain (-EBUSY); ordinary notifiers are unconstrained. Syscalls with complex signal/restart behaviour (nanosleep, futex(FUTEX_WAIT), ...) are out of scope and should not have their arguments redirected. - PIN_INSTALL: target_addr == 0 lets the kernel pick a free address in the target mm (avoids a racy userspace /proc//maps scan), and a new offset field lets one memfd back several disjoint pins. - New patch 6: Documentation/userspace-api/seccomp_filter.rst. - Selftests expanded: install into a fresh post-execve mm, stateless churn, outer-filter re-validation, ABI/versioning, and a signal-ordering regression test. Changes since v2: v3 was a redesign that dropped the v2 SECCOMP_IOCTL_NOTIF_INJECT approach (an in-kernel reimplementation of a syscall whitelist) in favour of redirecting the real syscall into a sealed pin, as suggested by Andy. Changes since v1: v2 was a redesign that dropped the v1 SECCOMP_IOCTL_NOTIF_PIN_ARGS All pinned-memfd and redirect selftests pass. --- Cong Wang (6): mm: add __do_mmap() and vm_mmap_seal_remote() seccomp: introduce SECCOMP_IOCTL_NOTIF_PIN_INSTALL seccomp: add kernel-installed pinned-memfd redirect seccomp: re-validate a redirected syscall against outer filters selftests/seccomp: cover non-cooperative pinned-memfd install docs/seccomp: document pinned-memfd redirect ioctls .../userspace-api/seccomp_filter.rst | 108 ++ include/linux/mm.h | 3 + include/linux/seccomp.h | 12 +- include/uapi/linux/seccomp.h | 126 ++ kernel/seccomp.c | 446 ++++++- mm/internal.h | 8 + mm/mmap.c | 63 +- mm/nommu.c | 12 +- mm/util.c | 62 + mm/vma.c | 35 +- mm/vma.h | 6 +- tools/testing/selftests/seccomp/seccomp_bpf.c | 1027 +++++++++++++++++ 12 files changed, 1874 insertions(+), 34 deletions(-) base-commit: ab9de95c9cf952332ab79453b4b5d1bfca8e514f -- 2.43.0