From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from mail-oi1-f202.google.com (mail-oi1-f202.google.com [209.85.167.202]) (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 1DF023B100A for ; Mon, 15 Jun 2026 19:37:36 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.167.202 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1781552257; cv=none; b=IKvK2PdrpjcuSRdHFNstYPMbGMiA4ou9cToR39TKOsLOKYaLOujCmo7sg8OWmY4sGWwgSmAkYPmstjKpOyPzkeIWzB8moM3xsZ7fNK/oBMHFMLgrp7EG9RWGh/eoTwtAHeNtwE+ZKBtCf0j1u/tQfLfcpGJrA0BLGzs2u+WcL14= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1781552257; c=relaxed/simple; bh=LroGjFbOcXZkvxakXudDJ8eQsKutj0s5+zQfOiyOpbI=; h=Date:In-Reply-To:Mime-Version:References:Message-ID:Subject:From: To:Cc:Content-Type; b=j2WFWSVZJ/uJfOpxFzf3TgqtYb1QY9PSH+lmvDqOEAtM+ei/oipy519H9Xlz+7/bocx4RSJPxHT0jzfEbwy6PbkHp+7BvShpoxh52wLAkH6D2NQcG3iH7ssLAjJFA9JT0G0odVpRLNRS/poSACq0x2Yyz6NV0I1d2GMgcLKA6/Q= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=google.com; spf=pass smtp.mailfrom=flex--avagin.bounces.google.com; dkim=pass (2048-bit key) header.d=google.com header.i=@google.com header.b=CCYDk7Q7; arc=none smtp.client-ip=209.85.167.202 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=google.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=flex--avagin.bounces.google.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=google.com header.i=@google.com header.b="CCYDk7Q7" Received: by mail-oi1-f202.google.com with SMTP id 5614622812f47-486a299a1b4so12255306b6e.1 for ; Mon, 15 Jun 2026 12:37:36 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20251104; t=1781552255; x=1782157055; darn=lists.linux.dev; h=cc:to:from:subject:message-id:references:mime-version:in-reply-to :date:from:to:cc:subject:date:message-id:reply-to; bh=fP4hlc+Lp5NgaEqwr+Sx0bLv+++cHMU8/Y1YWFsBPuU=; b=CCYDk7Q7Zd98ichqvvC/oh9L2RdO/Z7B99iHbagLK5l6LhscLFr6jVGloWiEkpVW1G 5j+JRKuCNZ5tq1BPXKwrws9dNGsCdRGKUBr+viH7cII/wvBY/5H73wLMc2xzRpD/a7vq PYwjqcmZzU2W/wwSfTuxgmYdgUqaMefPEGT+wfC4W5hdS+VdiL/is2ASIXJqn7svT9PE o0VilALlA/pS8FZSo2si3gjWodQtYFFqZmEaIF6Ld1mnWza8S3Ilf3ehtvvhILeFftJ/ O72EoArFx1jIZaNlSgQdujjSc93+4BGiczc+Sj+CDhECePc04uBaydYVeUgz5plFYz+i LSzA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20251104; t=1781552255; x=1782157055; h=cc:to:from:subject:message-id:references:mime-version:in-reply-to :date:x-gm-message-state:from:to:cc:subject:date:message-id:reply-to; bh=fP4hlc+Lp5NgaEqwr+Sx0bLv+++cHMU8/Y1YWFsBPuU=; b=C8s69xxyWCBX22Whrw79kab6bMsrAMlXH6xIHePKO969NQTiEhwDxL9anNWZgdiRw0 AemNe7ykxp95xWej00Nd2Ssqr3ygi0BpFIAGlocxoY/ITZJA2+n7pZFe1y4SrD8FbbOL j+p6oeinxT0tWkTZCRLfFmj0Ywejcvtx08iC+ACBzx2L84GHu0rkAdQBVZjdws08KoCR RI2h4H8nOm1Y9nqtdgC6MaUJDKJbABa4s3UAOLqdtOordwnp55v8AEnSl41UIvMB4LE+ YxbQABQMU7IkTg8pUa78rMnWGv6w/K8byj3XxR1pQi4bY5uS4YGX04j/nmipJFMzfkwO Jqrg== X-Forwarded-Encrypted: i=1; AFNElJ+PwyegWzuWitQziDq+RSbY04Un6eDWWDXzuNnu36p8fnA99Jsk1IDhMRCubXxXZGkdg4mU@lists.linux.dev X-Gm-Message-State: AOJu0Yw4x2yhYjSEsqq4ObeulOZkAfiqXrZpEl/A7Oz3Yg9Amt3J48q+ ehYtJXvt11wbKFYL8ga1ha/nYNf77rE0W5VHD7GI5mPp0HMStD8W4I/YKRSQht2m4ha36S0LP26 StAEwJA== X-Received: from iohf19-n2.prod.google.com ([2002:a05:6602:a5d3:20b0:978:ad30:f0da]) (user=avagin job=prod-delivery.src-stubby-dispatcher) by 2002:a05:6808:1799:b0:486:3537:2199 with SMTP id 5614622812f47-4884c0ea7admr404412b6e.17.1781552254932; Mon, 15 Jun 2026 12:37:34 -0700 (PDT) Date: Mon, 15 Jun 2026 19:37:14 +0000 In-Reply-To: <20260615193716.1843340-1-avagin@google.com> Precedence: bulk X-Mailing-List: criu@lists.linux.dev List-Id: List-Subscribe: List-Unsubscribe: Mime-Version: 1.0 References: <20260615193716.1843340-1-avagin@google.com> X-Mailer: git-send-email 2.54.0.1189.g8c84645362-goog Message-ID: <20260615193716.1843340-9-avagin@google.com> Subject: [PATCH 08/10] selftests/x86: Add a sigframe insufficient xstate_size test From: Andrei Vagin To: Thomas Gleixner , Ingo Molnar , Borislav Petkov , "Chang S. Bae" Cc: linux-kernel@vger.kernel.org, criu@lists.linux.dev, Dave Hansen , x86@kernel.org, Andrei Vagin , "H. Peter Anvin" Content-Type: text/plain; charset="UTF-8" Extend sigframe_fpu_portability to include an insufficient xstate_size check (test_insufficient_xstate_size). Verify that the kernel correctly rejects signal frames where the xstate_size is too small for the enabled features in the xfeatures mask. Signed-off-by: Andrei Vagin --- .../selftests/x86/sigframe_fpu_portability.c | 68 +++++++++++++++++-- 1 file changed, 62 insertions(+), 6 deletions(-) diff --git a/tools/testing/selftests/x86/sigframe_fpu_portability.c b/tools/testing/selftests/x86/sigframe_fpu_portability.c index 169548892f92..462219905303 100644 --- a/tools/testing/selftests/x86/sigframe_fpu_portability.c +++ b/tools/testing/selftests/x86/sigframe_fpu_portability.c @@ -12,19 +12,24 @@ #include #include #include +#include #include "helpers.h" #include "xstate.h" /* - * This test verifies the FPU portability of the signal frame. - * It verifies that the kernel correctly restores the xstate context even - * if the frame size has been manually reduced (shrunk), as long as the - * FP_XSTATE_MAGIC2 marker is correctly placed. + * This test verifies the FPU portability and consistency of the signal frame. + * + * - test_shrunk_xstate_size: + * Verifies that the kernel restores state from a frame with xstate_size + * shrunk to only include active features. + * + * - test_insufficient_xstate_size: + * Verifies that the kernel rejects a frame if xstate_size is too small for + * the features enabled in xfeatures. */ #define SIGFRAME_XSTATE_HDR_OFFSET 512 - #define XSTATE_SSE_ONLY_SIZE (SIGFRAME_XSTATE_HDR_OFFSET + XSAVE_HDR_SIZE) #define XFEATURE_MASK_FPSSE ((1 << XFEATURE_FP) | (1 << XFEATURE_SSE)) @@ -148,15 +153,66 @@ static void test_shrunk_xstate_size(void) clearhandler(SIGUSR1); } +static sigjmp_buf segv_jmpbuf; + +static void handle_segv(int sig, siginfo_t *si, void *ucp) +{ + siglongjmp(segv_jmpbuf, 1); +} + +static void handle_insufficient_xstate_size(int sig, siginfo_t *si, void *ucp) +{ + ucontext_t *uc = ucp; + void *fp = uc->uc_mcontext.fpregs; + struct _fpx_sw_bytes *sw = get_fpx_sw_bytes(fp); + + /* The origin frame contains an AVX state. */ + sw->xstate_size = XSTATE_SSE_ONLY_SIZE; + + *(uint32_t *)(fp + sw->xstate_size) = FP_XSTATE_MAGIC2; +} + +static void test_insufficient_xstate_size(void) +{ + uint64_t v[4] = {0, 0, 0, 0}; + + sig_err_buf[0] = 0; + sethandler(SIGUSR1, handle_insufficient_xstate_size, 0); + sethandler(SIGSEGV, handle_segv, 0); + + v[0] = 0x1111111111111111ULL; + v[1] = 0x2222222222222222ULL; + v[2] = 0x3333333333333333ULL; + v[3] = 0x4444444444444444ULL; + write_ymm0(v); + + if (sigsetjmp(segv_jmpbuf, 1) == 0) { + raise(SIGUSR1); + sig_print("Inconsistent size was NOT rejected\n"); + } + + clearhandler(SIGUSR1); + clearhandler(SIGSEGV); + + if (sig_err_buf[0]) + ksft_test_result_fail("%s\n", sig_err_buf); + else + ksft_test_result_pass("Inconsistent size correctly rejected\n"); + + clearhandler(SIGUSR1); + clearhandler(SIGSEGV); +} int main(void) { ksft_print_header(); - ksft_set_plan(1); + ksft_set_plan(2); check_avx_support(); test_shrunk_xstate_size(); + test_insufficient_xstate_size(); + ksft_finished(); return 0; } -- 2.54.0.1189.g8c84645362-goog