All of lore.kernel.org
 help / color / mirror / Atom feed
From: Sasha Levin <sashal@kernel.org>
To: patches@lists.linux.dev, stable@vger.kernel.org
Cc: Mikhail Malyshev <mike.malyshev@gmail.com>,
	Nathan Chancellor <nathan@kernel.org>,
	Nicolas Schier <nsc@kernel.org>, Sasha Levin <sashal@kernel.org>,
	masahiroy@kernel.org, torsten.hilbrich@secunet.com,
	linux-kbuild@vger.kernel.org
Subject: [PATCH AUTOSEL 6.18-6.1] kbuild: Use objtree for module signing key path
Date: Mon,  8 Dec 2025 19:15:11 -0500	[thread overview]
Message-ID: <20251209001610.611575-19-sashal@kernel.org> (raw)
In-Reply-To: <20251209001610.611575-1-sashal@kernel.org>

From: Mikhail Malyshev <mike.malyshev@gmail.com>

[ Upstream commit af61da281f52aba0c5b090bafb3a31c5739850ff ]

When building out-of-tree modules with CONFIG_MODULE_SIG_FORCE=y,
module signing fails because the private key path uses $(srctree)
while the public key path uses $(objtree). Since signing keys are
generated in the build directory during kernel compilation, both
paths should use $(objtree) for consistency.

This causes SSL errors like:
  SSL error:02001002:system library:fopen:No such file or directory
  sign-file: /kernel-src/certs/signing_key.pem

The issue occurs because:
- sig-key uses: $(srctree)/certs/signing_key.pem (source tree)
- cmd_sign uses: $(objtree)/certs/signing_key.x509 (build tree)

But both keys are generated in $(objtree) during the build.

This complements commit 25ff08aa43e37 ("kbuild: Fix signing issue for
external modules") which fixed the scripts path and public key path,
but missed the private key path inconsistency.

Fixes out-of-tree module signing for configurations with separate
source and build directories (e.g., O=/kernel-out).

Signed-off-by: Mikhail Malyshev <mike.malyshev@gmail.com>
Reviewed-by: Nathan Chancellor <nathan@kernel.org>
Tested-by: Nicolas Schier <nsc@kernel.org>
Link: https://patch.msgid.link/20251015163452.3754286-1-mike.malyshev@gmail.com
Signed-off-by: Nicolas Schier <nsc@kernel.org>
Signed-off-by: Sasha Levin <sashal@kernel.org>
---

LLM Generated explanations, may be completely bogus:

Now I have the complete picture. All stable trees that contain commit
13b25489b6f8 (v6.13+) have the incomplete fix and need this patch. Let
me finalize my analysis:

## Complete Analysis

### 1. COMMIT MESSAGE ANALYSIS

The commit message is clear and well-documented:
- **Subject**: "kbuild: Use objtree for module signing key path" -
  clearly states what it does
- **Body**: Explains the problem with detailed error messages and root
  cause analysis
- **References**: Explicitly mentions commit 25ff08aa43e37 as the
  incomplete fix it complements
- **No Cc: stable@vger.kernel.org tag** - the maintainer did not
  explicitly request stable backport
- **No Fixes: tag** - However, logically this fixes the same issue as
  25ff08aa43e37, which has `Fixes: 13b25489b6f8`
- **Has Reviewed-by and Tested-by tags** from Nicolas Schier and Nathan
  Chancellor

### 2. CODE CHANGE ANALYSIS

The change is a **single character change** (literally changing one
word):

```makefile
# Before:
sig-key := $(if $(wildcard
$(CONFIG_MODULE_SIG_KEY)),,$(srctree)/)$(CONFIG_MODULE_SIG_KEY)

# After:
sig-key := $(if $(wildcard
$(CONFIG_MODULE_SIG_KEY)),,$(objtree)/)$(CONFIG_MODULE_SIG_KEY)
```

**Technical mechanism of the bug:**
1. When building out-of-tree modules with `CONFIG_MODULE_SIG_FORCE=y`
   and separate source/build directories (e.g., `O=/kernel-out`):
   - `$(srctree)` points to the source tree (e.g., `/kernel-src`)
   - `$(objtree)` points to the build tree (e.g., `/kernel-out`)

2. Module signing keys are **generated during kernel compilation** and
   stored in `$(objtree)/certs/`:
   - Private key: `$(objtree)/certs/signing_key.pem`
   - Public key: `$(objtree)/certs/signing_key.x509`

3. After commit 25ff08aa43e37, `cmd_sign` correctly uses
   `$(objtree)/certs/signing_key.x509` for the public key, but `sig-key`
   still uses `$(srctree)/certs/signing_key.pem` for the private key.

4. This creates an **inconsistency**: The `sign-file` tool is called
   with:
   - Private key: `/kernel-src/certs/signing_key.pem` (WRONG - file
     doesn't exist there)
   - Public key: `/kernel-out/certs/signing_key.x509` (CORRECT)

5. Result: `fopen()` fails with "No such file or directory" when trying
   to open the private key.

**Why the fix is correct:**
- Both signing keys are generated in `$(objtree)`, so both paths should
  reference `$(objtree)`
- The fix is logically consistent with what commit 25ff08aa43e37 did for
  the other paths
- The conditional `$(if $(wildcard
  $(CONFIG_MODULE_SIG_KEY)),,$(objtree)/)` only adds the prefix if the
  key path is not absolute, which is correct behavior

### 3. CLASSIFICATION

- **Type**: Bug fix (not a feature)
- **Category**: Build system fix
- **Severity**: Causes complete failure of out-of-tree module signing
  with CONFIG_MODULE_SIG_FORCE=y
- **Security relevance**: Low (doesn't fix a security vulnerability per
  se, but affects security feature - module signing)
- **Exception category**: Build fix - these are explicitly allowed in
  stable

### 4. SCOPE AND RISK ASSESSMENT

- **Lines changed**: 1 line (trivial)
- **Files touched**: 1 file (`scripts/Makefile.modinst`)
- **Complexity**: Extremely simple - just changing `srctree` to
  `objtree`
- **Subsystem**: kbuild (build system)
- **Risk level**: **VERY LOW**
  - Only affects out-of-tree module signing with separate source/build
    directories
  - Only affects configurations with `CONFIG_MODULE_SIG_FORCE=y` or
    `CONFIG_MODULE_SIG_ALL=y`
  - The change is logically correct and consistent with the rest of the
    code
  - Cannot break anything that was working before

### 5. USER IMPACT

- **Who is affected**:
  - Users building out-of-tree modules (e.g., NVIDIA drivers,
    VirtualBox, ZFS)
  - With separate source and build directories (`O=/path/to/build`)
  - With module signature enforcement enabled
- **Severity**: HIGH for affected users - module signing completely
  fails
- **User reports**: The commit message shows this was reported as a real
  user problem with specific error messages
- **Prevalence**: Common scenario for distribution builders and
  enterprise environments

### 6. STABILITY INDICATORS

- **Tested-by: Nicolas Schier** - the kbuild maintainer tested it
- **Reviewed-by: Nathan Chancellor** - well-known kernel developer
  reviewed it
- **Link to patch discussion**: Shows proper review process
- **Age in mainline**: This appears to be a recent commit (October 2025
  in the patch date)

### 7. DEPENDENCY CHECK

**Critical finding**: This commit has a dependency:
- It requires commit **25ff08aa43e37** ("kbuild: Fix signing issue for
  external modules") to be present first
- 25ff08aa43e37 requires commit **13b25489b6f8** ("kbuild: change
  working directory to external module directory with M=")

**Affected stable versions**:
- v6.13.x: Has 13b25489b6f8 (the bug) and backported 25ff08aa43e37
  (partial fix) → **NEEDS this patch**
- v6.14.x: Has both 13b25489b6f8 and 25ff08aa43e37 → **NEEDS this
  patch**
- v6.15.x: Has both → **NEEDS this patch**
- v6.16.x: Has both → **NEEDS this patch**
- v6.17.x: Has both → **NEEDS this patch**
- v6.6.x and older: Does NOT have 13b25489b6f8 → **Does NOT need this
  patch** (and would break if applied)

**Backport note**: This commit should ONLY be backported to stable trees
that already have:
1. Commit 13b25489b6f8 (the original behavior change)
2. Commit 25ff08aa43e37 (the partial fix)

This means v6.13+ stable trees only.

### SUMMARY

This commit is an **excellent candidate for stable backport** to kernel
versions v6.13+:

**Positive factors:**
1. ✅ Fixes a real bug that causes complete failure of module signing
2. ✅ Extremely small change (1 line, 1 word)
3. ✅ Zero risk of regression (only fixes broken behavior)
4. ✅ Properly reviewed and tested by kbuild maintainers
5. ✅ Complements an existing fix that was already backported to stable
6. ✅ Build fix category - explicitly allowed in stable rules
7. ✅ Clear, well-documented commit message
8. ✅ Affects users who follow best practices (separate build directory)

**Concerns:**
1. ⚠️ No explicit `Cc: stable@vger.kernel.org` tag (but the first fix
   also didn't have one and was still backported)
2. ⚠️ No explicit `Fixes:` tag (but logically fixes the same issue as
   25ff08aa43e37)
3. ⚠️ Must only be applied to v6.13+ stable trees (where 13b25489b6f8
   exists)

The commit passes all stable kernel criteria: it's obviously correct,
fixes a real user-visible bug, is small and surgical, has no new
features, and has been tested. The incomplete fix in stable trees is
currently causing module signing to fail for users with separate
source/build directories.

**YES**

 scripts/Makefile.modinst | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/scripts/Makefile.modinst b/scripts/Makefile.modinst
index 1628198f3e830..9ba45e5b32b18 100644
--- a/scripts/Makefile.modinst
+++ b/scripts/Makefile.modinst
@@ -100,7 +100,7 @@ endif
 # Don't stop modules_install even if we can't sign external modules.
 #
 ifeq ($(filter pkcs11:%, $(CONFIG_MODULE_SIG_KEY)),)
-sig-key := $(if $(wildcard $(CONFIG_MODULE_SIG_KEY)),,$(srctree)/)$(CONFIG_MODULE_SIG_KEY)
+sig-key := $(if $(wildcard $(CONFIG_MODULE_SIG_KEY)),,$(objtree)/)$(CONFIG_MODULE_SIG_KEY)
 else
 sig-key := $(CONFIG_MODULE_SIG_KEY)
 endif
-- 
2.51.0


  parent reply	other threads:[~2025-12-09  0:17 UTC|newest]

Thread overview: 47+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2025-12-09  0:14 [PATCH AUTOSEL 6.18-6.1] ksmbd: fix use-after-free in ksmbd_tree_connect_put under concurrency Sasha Levin
2025-12-09  0:14 ` [PATCH AUTOSEL 6.18-6.17] wifi: rtw89: use skb_dequeue() for queued ROC packets to prevent racing Sasha Levin
2025-12-09  0:14 ` [PATCH AUTOSEL 6.18-6.6] ipv6: clean up routes when manually removing address with a lifetime Sasha Levin
2025-12-09  0:14 ` [PATCH AUTOSEL 6.18-5.10] ext4: remove page offset calculation in ext4_block_zero_page_range() Sasha Levin
2025-12-09  0:14 ` [PATCH AUTOSEL 6.18-6.6] fs/ntfs3: fix KMSAN uninit-value in ni_create_attr_list Sasha Levin
2025-12-09  0:14 ` [PATCH AUTOSEL 6.18-6.6] btrfs: abort transaction on item count overflow in __push_leaf_left() Sasha Levin
2025-12-09  0:14 ` [PATCH AUTOSEL 6.18-6.1] smb/server: fix return value of smb2_ioctl() Sasha Levin
2025-12-09  0:15 ` [PATCH AUTOSEL 6.18-6.1] gfs2: Fix use of bio_chain Sasha Levin
2025-12-09  0:15 ` [PATCH AUTOSEL 6.18-5.10] Bluetooth: btusb: Add new VID/PID 13d3/3533 for RTL8821CE Sasha Levin
2025-12-09  0:15 ` [PATCH AUTOSEL 6.18-6.12] wifi: mac80211: reset CRC valid after CSA Sasha Levin
2025-12-09  0:15 ` [PATCH AUTOSEL 6.18-6.12] Bluetooth: btusb: Add new VID/PID 0x0489/0xE12F for RTL8852BE-VT Sasha Levin
2025-12-09  0:15 ` [PATCH AUTOSEL 6.18-5.10] wifi: mt76: mmio_*_copy fix byte order and alignment Sasha Levin
2025-12-09  0:15 ` [PATCH AUTOSEL 6.18-5.10] btrfs: scrub: always update btrfs_scrub_progress::last_physical Sasha Levin
2025-12-09  0:15 ` [PATCH AUTOSEL 6.18-6.12] bpf: Skip bounds adjustment for conditional jumps on same scalar register Sasha Levin
2025-12-09  0:15 ` [PATCH AUTOSEL 6.18-6.12] wifi: rtl8xxxu: Fix HT40 channel config for RTL8192CU, RTL8723AU Sasha Levin
2025-12-09  0:15 ` [PATCH AUTOSEL 6.18-6.12] Bluetooth: btusb: MT7920: Add VID/PID 0489/e135 Sasha Levin
2025-12-09  0:15 ` [PATCH AUTOSEL 6.18-6.12] Bluetooth: btusb: MT7922: Add VID/PID 0489/e170 Sasha Levin
2025-12-09  0:15 ` [PATCH AUTOSEL 6.18-6.12] virtio_blk: NULL out vqs to avoid double free on failed resume Sasha Levin
2025-12-09  0:15 ` Sasha Levin [this message]
2025-12-09  0:15 ` [PATCH AUTOSEL 6.18-6.17] btrfs: use kvcalloc for btrfs_bio::csum allocation Sasha Levin
2025-12-09  0:15 ` [PATCH AUTOSEL 6.18-6.12] net: sched: Don't use WARN_ON_ONCE() for -ENOMEM in tcf_classify() Sasha Levin
2025-12-09  0:15 ` [PATCH AUTOSEL 6.18-5.10] hfsplus: Verify inode mode when loading from disk Sasha Levin
2025-12-09  0:15 ` [PATCH AUTOSEL 6.18-6.6] gfs2: fix remote evict for read-only filesystems Sasha Levin
2025-12-09  0:15 ` [PATCH AUTOSEL 6.18-5.10] net: amd-xgbe: use EOPNOTSUPP instead of ENOTSUPP in xgbe_phy_mii_read_c45 Sasha Levin
2025-12-09  0:15 ` [PATCH AUTOSEL 6.18-5.10] net: init shinfo->gso_segs from qdisc_pkt_len_init() Sasha Levin
2025-12-09  0:15 ` [PATCH AUTOSEL 6.18-6.17] Bluetooth: btusb: add new custom firmwares Sasha Levin
2025-12-09  0:15 ` [PATCH AUTOSEL 6.18-5.10] hfsplus: fix missing hfs_bnode_get() in __hfs_bnode_create Sasha Levin
2025-12-09  0:15 ` [PATCH AUTOSEL 6.18-6.12] cxgb4: Rename sched_class to avoid type clash Sasha Levin
2025-12-09  0:15 ` [PATCH AUTOSEL 6.18-6.12] net: mana: Drop TX skb on post_work_request failure and unmap resources Sasha Levin
2025-12-09  0:15 ` [PATCH AUTOSEL 6.18-5.10] hfsplus: fix volume corruption issue for generic/070 Sasha Levin
2025-12-09  0:15 ` [PATCH AUTOSEL 6.18-6.17] wifi: rtw89: rtw8852bu: Added dev id for ASUS AX57 NANO USB Wifi dongle Sasha Levin
2025-12-09  0:15 ` [PATCH AUTOSEL 6.18-5.10] net: restore napi_consume_skb()'s NULL-handling Sasha Levin
2025-12-09  0:15 ` [PATCH AUTOSEL 6.18-5.15] fs/ntfs3: Support timestamps prior to epoch Sasha Levin
2025-12-09  0:15 ` [PATCH AUTOSEL 6.18-6.1] smb/server: fix return value of smb2_query_dir() Sasha Levin
2025-12-09  0:15 ` [PATCH AUTOSEL 6.18-6.17] wifi: rtw88: Add BUFFALO WI-U3-866DHP to the USB ID list Sasha Levin
2025-12-09  0:15 ` [PATCH AUTOSEL 6.18-6.6] Bluetooth: btusb: Add new VID/PID 2b89/6275 for RTL8761BUV Sasha Levin
2025-12-09  0:15 ` [PATCH AUTOSEL 6.18-6.12] bpf: Disable file_alloc_security hook Sasha Levin
2025-12-09  0:15 ` [PATCH AUTOSEL 6.18-6.1] wifi: rtw89: phy: fix out-of-bounds access in rtw89_phy_read_txpwr_limit() Sasha Levin
2025-12-09  0:15 ` [PATCH AUTOSEL 6.18-6.6] ntfs: set dummy blocksize to read boot_block when mounting Sasha Levin
2025-12-09  0:15 ` [PATCH AUTOSEL 6.18-5.10] hfsplus: fix volume corruption issue for generic/073 Sasha Levin
2025-12-09  0:15 ` [PATCH AUTOSEL 6.18-6.12] wifi: mt76: mt792x: fix wifi init fail by setting MCU_RUNNING after CLC load Sasha Levin
2025-12-09  0:15 ` [PATCH AUTOSEL 6.18-6.12] gfs2: Fix "gfs2: Switch to wait_event in gfs2_quotad" Sasha Levin
2025-12-09  0:15 ` [PATCH AUTOSEL 6.18-6.6] ksmbd: vfs: fix race on m_flags in vfs_cache Sasha Levin
2025-12-09  0:15 ` [PATCH AUTOSEL 6.18-6.1] wifi: rtw89: flush TX queue before deleting key Sasha Levin
2025-12-09  0:15 ` [Intel-wired-lan] [PATCH AUTOSEL 6.18-6.12] ice: Allow 100M speed for E825C SGMII device Sasha Levin
2025-12-09  0:15   ` Sasha Levin
  -- strict thread matches above, loose matches on Subject: below --
2025-12-06 14:02 [PATCH AUTOSEL 6.18-6.1] ksmbd: fix use-after-free in ksmbd_tree_connect_put under concurrency Sasha Levin
2025-12-06 14:02 ` [PATCH AUTOSEL 6.18-6.1] kbuild: Use objtree for module signing key path Sasha Levin

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20251209001610.611575-19-sashal@kernel.org \
    --to=sashal@kernel.org \
    --cc=linux-kbuild@vger.kernel.org \
    --cc=masahiroy@kernel.org \
    --cc=mike.malyshev@gmail.com \
    --cc=nathan@kernel.org \
    --cc=nsc@kernel.org \
    --cc=patches@lists.linux.dev \
    --cc=stable@vger.kernel.org \
    --cc=torsten.hilbrich@secunet.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.