From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from mail-yx1-f44.google.com (mail-yx1-f44.google.com [74.125.224.44]) (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 2A8C64DB56F for ; Fri, 15 May 2026 17:08:54 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=74.125.224.44 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1778864936; cv=none; b=WJv0YyyCiUb7+symjzq4eJoSbrxluZ4TlKbSnB8ZbCFEJhnPQ3iX5u8veL0M4sE/sHFRAhcC3MCuuwsnHH/xh2Ob5wNp6j7byoiRFme/r9oBziyqoI1Lxzo79thRhbTFdv5OZAzIoM+crEJTZwqULDQB9BCbiCQmbq6HbvrPeKQ= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1778864936; c=relaxed/simple; bh=eTAu6ZzvjxS+1EPKMnCFyFy8OhsqgGgyJVexQkk0yMo=; h=From:Date:Subject:MIME-Version:Content-Type:Message-Id:To:Cc; b=LeoKmUDKftkKsekihN0/QQ9YBPn/Zbp+C8TwIKq0SxR4u6hwWLNKAmOPBDama3wgFzgFQENE+D49GiUJgXzfFK7YrPz6M4MNlj7I6Axa2bsqaa8N8/YC951Q6GBSK+Scz6nm4C8L80Pe9Hh4/8h9WQ5pyGLaTnodvqsx0d5fzv8= 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=quaNqs2y; arc=none smtp.client-ip=74.125.224.44 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="quaNqs2y" Received: by mail-yx1-f44.google.com with SMTP id 956f58d0204a3-651b4d09141so2817115d50.1 for ; Fri, 15 May 2026 10:08:54 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20251104; t=1778864934; x=1779469734; darn=vger.kernel.org; h=cc:to:message-id:content-transfer-encoding:mime-version:subject :date:from:from:to:cc:subject:date:message-id:reply-to; bh=r5Dodp1SgGEX8BPNfOmTYAJETBWomYkmsJ9yO/jTFgc=; b=quaNqs2ytRrBYam1t5KpyZrzoOiDF8TnPI3wv5Og0A/wvDXj+Ok4iJswmVPkFqSOsS i8SY2fWxaZN1CEp4wSzA6e0ZbgKiF+HZS3AqRvc+DAEWTh8p12SLVWfzhzEndcfOwoX2 HeICh4siaGijAOGS31nQtCtw02fC66+qbGgH/vVFo9KciF8M9S1aZyX65u2JhcF4v2vp tGX9rZnh+evawSe3w/xvxAiMg/BbJRoTraKfWVM2axkuCx8/1QWO8ozGfTsfuB+XB7Sh wAgUr3cJd8JgLxeY4l2s9WOZI7qFleFYS4PoS9zGoUwbhgs+5Be48o8Wrw666AWbgL0h Bq3g== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20251104; t=1778864934; x=1779469734; h=cc:to:message-id:content-transfer-encoding:mime-version:subject :date:from:x-gm-gg:x-gm-message-state:from:to:cc:subject:date :message-id:reply-to; bh=r5Dodp1SgGEX8BPNfOmTYAJETBWomYkmsJ9yO/jTFgc=; b=k0tGAUjTnae63SG0D5XHn2L4XbsjN2+ZxSihWVX9llEX9PhW1m4+SSohqJHPYDP1ER EVt8AcalPFL3BnGd7ugT4GaTDy1kjFrEyiBlGPEG19K+ve2tHYgfJvtySq5GMKpJjGyY 9KOqK5gs9C4msIDliZ1gakEPUCIFXZ1wg5lTsKDKUyNvn23vdP/6BjXr/WywIOhyjSJF F22pNjZ7LBfor6uQg7QGxjORFpCMuVu1FsWhqA+i5s8OCMzBRLmnEhPdUUxPweMd6GCj xIsEIqWZRpQ5+Y+hg2F5lB0ptky/rBSBISqrLfrhsYeStXjLyF29oAAaGgnHJDCZaODG iRcw== X-Forwarded-Encrypted: i=1; AFNElJ/8vgAF7QBDmf9609pxJvSRJTEIqgfeIQc3UJirFq6reDKI4YlnyNx5v/3ED7XxqRA7YwUS8cye8F/Nurw=@vger.kernel.org X-Gm-Message-State: AOJu0YxQ2P7Z8NgAnf6P5YgIS39xKyv3R/iXGmCwUCrzw2fYhVATZB2+ AbDPI8Ap+NkKy4NGRkNC3XyzpfCp/RWg8eW5WuC5gtdkWzsGFYG3YGuO X-Gm-Gg: Acq92OFyfELy1BM+1sjN+oszFDkPhNlebPByn+hSr2YnM9sEaQgFK6twYMZpbJewUaU 29DwYwSXa5LH8a8eBSYHve2I4kSMucXe2cjhZB4P+TI0ZMg79Hh+oDliYzAyLcsjQ9ULB8TX3Lz yF9DJ/YABYv1ZoUMZl5NYOToJ78CJkCyO2IMuNeKHVh91EWZ4SV4+yefqEQlr2rpg7FFrwkujeX Qqb6IGnYJo5zx+ZjRKXUwQKML1sV/Oa5MYsxWq/eSrNHHN0tedgZZ1CW2VF3IUpDwbW1harsuPZ m4NaSSxapMBEUWbUIm8VuxHmVMrCEYIcFdz+U9iBbMSZxILJ2NgMcRVkpURnFVWb6kmIofSwicU 7ChOhASIMRCMutv4C+Jzv1uPMwsQOP5AwXYf45f1EpKiD4eFC+HDaf+aMtCQVdafWa69EheX2IN 7Vq3Q9kVPA8Ck5lrmEg2A= X-Received: by 2002:a05:690e:c4c:b0:650:327f:4ff0 with SMTP id 956f58d0204a3-65e0b04afc2mr7539634d50.12.1778864933773; Fri, 15 May 2026 10:08:53 -0700 (PDT) Received: from localhost ([2a03:2880:f806:8::]) by smtp.gmail.com with ESMTPSA id 956f58d0204a3-65e0db0b134sm2804059d50.13.2026.05.15.10.08.53 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 15 May 2026 10:08:53 -0700 (PDT) From: Daniel Zahka Date: Fri, 15 May 2026 10:08:52 -0700 Subject: [PATCH] netdevsim: psp: reset spi on key rotation and check for exhaustion on alloc Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: 7bit Message-Id: <20260515-spi-handle-v1-1-debf8cb467cb@gmail.com> X-B4-Tracking: v=1; b=H4sIACNTB2oC/6tWKk4tykwtVrJSqFYqSi3LLM7MzwNyDHUUlJIzE vPSU3UzU4B8JSMDIzMDU0NT3eKCTF2gREpOqq5FUqplapKFiZGZmbkSUENBUWpaZgXYsOjY2lo AXSI4OFwAAAA= To: Jakub Kicinski , Andrew Lunn , "David S. Miller" , Eric Dumazet , Paolo Abeni , Willem de Bruijn Cc: netdev@vger.kernel.org, linux-kernel@vger.kernel.org X-Mailer: b4 0.13.0 The PSP spec states that the lower 31b of the SPI need to be non-zero. Though not in the spec, I think it is reasonable to reset the lower 31b of the spi space after a key rotation, and to also decline to generate session keys when the lower 31b saturate. Assisted-by: Claude:claude-opus-4.7 Signed-off-by: Daniel Zahka --- This commit was originally part of the series: https://lore.kernel.org/netdev/20260508-nsim-psp-crypto-v1-0-4b50ed09b794@gmail.com/ But it stands alone, so I am submitting individually first. --- drivers/net/netdevsim/psp.c | 21 ++++++++++++++++----- 1 file changed, 16 insertions(+), 5 deletions(-) diff --git a/drivers/net/netdevsim/psp.c b/drivers/net/netdevsim/psp.c index 6936ecb8173e..c6000ebc6bc8 100644 --- a/drivers/net/netdevsim/psp.c +++ b/drivers/net/netdevsim/psp.c @@ -132,14 +132,15 @@ nsim_rx_spi_alloc(struct psp_dev *psd, u32 version, struct netlink_ext_ack *extack) { struct netdevsim *ns = psd->drv_priv; - unsigned int new; int i; - new = ++ns->psp.spi & PSP_SPI_KEY_ID; - if (psd->generation & 1) - new |= PSP_SPI_KEY_PHASE; + /* Check if incrementing the spi would change the phase bit */ + if ((ns->psp.spi & PSP_SPI_KEY_ID) == PSP_SPI_KEY_ID) { + NL_SET_ERR_MSG(extack, "SPI space exhausted"); + return -ENOSPC; + } - assoc->spi = cpu_to_be32(new); + assoc->spi = cpu_to_be32(++ns->psp.spi); assoc->key[0] = psd->generation; for (i = 1; i < PSP_MAX_KEY; i++) assoc->key[i] = ns->psp.spi + i; @@ -162,6 +163,16 @@ static int nsim_assoc_add(struct psp_dev *psd, struct psp_assoc *pas, static int nsim_key_rotate(struct psp_dev *psd, struct netlink_ext_ack *extack) { + struct netdevsim *ns = psd->drv_priv; + + /* Flip key phase and reset SPI to 0 within that space + * (will be pre-incremented, as 0 is an invalid SPI). + */ + if (ns->psp.spi & PSP_SPI_KEY_PHASE) + ns->psp.spi = 0; + else + ns->psp.spi = PSP_SPI_KEY_PHASE; + return 0; } --- base-commit: 822d4a8e390a08ccfaf2abb347ae670b230b196f change-id: 20260515-spi-handle-8be9eb842667 Best regards, -- Daniel Zahka