tangled
alpha
login
or
join now
pyrox.dev
/
nixpkgs
lol
0
fork
atom
overview
issues
pulls
pipelines
linuxPackages_latest.nvidiaPackages.{stable,latest,beta}: fix build
wxt
1 year ago
5ebc7f83
2221b837
+350
4 changed files
expand all
collapse all
unified
split
pkgs
os-specific
linux
nvidia-x11
crypto-Add-fix-for-6.13-Module-compilation.patch
default.nix
fix-for-linux-6.13.patch
nvidia-nv-Convert-symbol-namespace-to-string-literal.patch
+251
pkgs/os-specific/linux/nvidia-x11/crypto-Add-fix-for-6.13-Module-compilation.patch
···
1
1
+
diff --git a/kernel-open/conftest.sh b/kernel-open/conftest.sh
2
2
+
index fdceda72..3bfe39aa 100755
3
3
+
--- a/kernel-open/conftest.sh
4
4
+
+++ b/kernel-open/conftest.sh
5
5
+
@@ -6721,6 +6721,47 @@ compile_test() {
6
6
+
compile_check_conftest "$CODE" "NV_CRYPTO_PRESENT" "" "symbols"
7
7
+
;;
8
8
+
9
9
+
+ crypto_akcipher_verify)
10
10
+
+ #
11
11
+
+ # Determine whether the crypto_akcipher_verify API is still present.
12
12
+
+ # It was removed by commit 6b34562 ('crypto: akcipher - Drop sign/verify operations')
13
13
+
+ # in v6.13-rc1 (2024-10-04).
14
14
+
+ #
15
15
+
+ # This test is dependent on the crypto conftest to determine whether crypto should be
16
16
+
+ # enabled at all. That means that if the kernel is old enough such that crypto_akcipher_verify
17
17
+
+ #
18
18
+
+ # The test merely checks for the presence of the API, as it assumes that if the API
19
19
+
+ # is no longer present, the new API to replace it (crypto_sig_verify) must be present.
20
20
+
+ # If the kernel version is too old to have crypto_akcipher_verify, it will fail the crypto
21
21
+
+ # conftest above and all crypto code will be compiled out.
22
22
+
+ #
23
23
+
+ CODE="
24
24
+
+ #include <crypto/akcipher.h>
25
25
+
+ #include <linux/crypto.h>
26
26
+
+ void conftest_crypto_akcipher_verify(void) {
27
27
+
+ (void)crypto_akcipher_verify;
28
28
+
+ }"
29
29
+
+
30
30
+
+ compile_check_conftest "$CODE" "NV_CRYPTO_AKCIPHER_VERIFY_PRESENT" "" "symbols"
31
31
+
+ ;;
32
32
+
+
33
33
+
+ ecc_digits_from_bytes)
34
34
+
+ #
35
35
+
+ # Determine whether ecc_digits_from_bytes is present.
36
36
+
+ # It was added in commit c6ab5c915da4 ('crypto: ecc - Prevent ecc_digits_from_bytes from
37
37
+
+ # reading too many bytes') in v6.10.
38
38
+
+ #
39
39
+
+ # This functionality is needed when crypto_akcipher_verify is not present.
40
40
+
+ #
41
41
+
+ CODE="
42
42
+
+ #include <crypto/internal/ecc.h>
43
43
+
+ void conftest_ecc_digits_from_bytes(void) {
44
44
+
+ (void)ecc_digits_from_bytes;
45
45
+
+ }"
46
46
+
+
47
47
+
+ compile_check_conftest "$CODE" "NV_ECC_DIGITS_FROM_BYTES_PRESENT" "" "symbols"
48
48
+
+ ;;
49
49
+
+
50
50
+
mempolicy_has_unified_nodes)
51
51
+
#
52
52
+
# Determine if the 'mempolicy' structure has
53
53
+
diff --git a/kernel-open/nvidia/internal_crypt_lib.h b/kernel-open/nvidia/internal_crypt_lib.h
54
54
+
index 2eac7d5e..917acb26 100644
55
55
+
--- a/kernel-open/nvidia/internal_crypt_lib.h
56
56
+
+++ b/kernel-open/nvidia/internal_crypt_lib.h
57
57
+
@@ -64,7 +64,9 @@
58
58
+
* old or even just user disabled. If we should use LKCA, include headers, else
59
59
+
* define stubs to return errors.
60
60
+
*/
61
61
+
-#if defined(NV_CRYPTO_PRESENT) && defined (NV_CONFIG_CRYPTO_PRESENT)
62
62
+
+#if defined(NV_CRYPTO_PRESENT) && defined (NV_CONFIG_CRYPTO_PRESENT) && \
63
63
+
+ (defined(NV_CRYPTO_AKCIPHER_VERIFY_PRESENT) || \
64
64
+
+ (defined(NV_CRYPTO_SIG_H_PRESENT) && defined(NV_ECC_DIGITS_FROM_BYTES_PRESENT)))
65
65
+
#define USE_LKCA 1
66
66
+
#endif
67
67
+
68
68
+
diff --git a/kernel-open/nvidia/libspdm_ecc.c b/kernel-open/nvidia/libspdm_ecc.c
69
69
+
index 1f8f0100..a9eb4db5 100644
70
70
+
--- a/kernel-open/nvidia/libspdm_ecc.c
71
71
+
+++ b/kernel-open/nvidia/libspdm_ecc.c
72
72
+
@@ -30,14 +30,26 @@ MODULE_SOFTDEP("pre: ecdh_generic,ecdsa_generic");
73
73
+
#include <crypto/akcipher.h>
74
74
+
#include <crypto/ecdh.h>
75
75
+
#include <crypto/internal/ecc.h>
76
76
+
+#ifndef NV_CRYPTO_AKCIPHER_VERIFY_PRESENT
77
77
+
+#include <crypto/sig.h>
78
78
+
+
79
79
+
+struct signature
80
80
+
+{
81
81
+
+ u64 r[ECC_MAX_DIGITS];
82
82
+
+ u64 s[ECC_MAX_DIGITS];
83
83
+
+};
84
84
+
+#endif // NV_CRYPTO_AKCIPHER_VERIFY_PRESENT
85
85
+
+
86
86
+
+#define ECDSA_PUBKEY_HEADER_XY_PRESENT (0x4)
87
87
+
88
88
+
struct ecc_ctx {
89
89
+
unsigned int curve_id;
90
90
+
u64 priv_key[ECC_MAX_DIGITS]; // In big endian
91
91
+
92
92
+
struct {
93
93
+
- // ecdsa wants byte preceding pub_key to be set to '4'
94
94
+
- u64 pub_key_prefix;
95
95
+
+ // ecdsa pubkey has header indicating length of pubkey
96
96
+
+ u8 padding[7];
97
97
+
+ u8 pub_key_prefix;
98
98
+
u64 pub_key[2 * ECC_MAX_DIGITS];
99
99
+
};
100
100
+
101
101
+
@@ -221,25 +233,84 @@ bool lkca_ec_compute_key(void *ec_context, const uint8_t *peer_public,
102
102
+
#endif
103
103
+
}
104
104
+
105
105
+
-bool lkca_ecdsa_verify(void *ec_context, size_t hash_nid,
106
106
+
- const uint8_t *message_hash, size_t hash_size,
107
107
+
- const uint8_t *signature, size_t sig_size)
108
108
+
+#ifndef NV_CRYPTO_AKCIPHER_VERIFY_PRESENT
109
109
+
+static bool lkca_ecdsa_verify_crypto_sig(void *ec_context, size_t hash_nid,
110
110
+
+ const uint8_t *message_hash, size_t hash_size,
111
111
+
+ const uint8_t *signature, size_t sig_size)
112
112
+
{
113
113
+
#ifndef USE_LKCA
114
114
+
return false;
115
115
+
#else
116
116
+
struct ecc_ctx *ctx = ec_context;
117
117
+
+ u8 *pub_key;
118
118
+
+ int err;
119
119
+
+ DECLARE_CRYPTO_WAIT(wait);
120
120
+
+ struct crypto_sig * tfm = NULL;
121
121
+
+ struct signature sig;
122
122
+
+
123
123
+
+ if (sig_size != ctx->size || !ctx->pub_key_set)
124
124
+
+ {
125
125
+
+ return false;
126
126
+
+ }
127
127
+
+
128
128
+
+ tfm = crypto_alloc_sig(ctx->name, CRYPTO_ALG_TYPE_SIG, 0);
129
129
+
+ if (IS_ERR(tfm)) {
130
130
+
+ pr_info("crypto_alloc_sig failed in lkca_ecdsa_verify\n");
131
131
+
+ return false;
132
132
+
+ }
133
133
+
+
134
134
+
+ // modify header of pubkey to indicate size
135
135
+
+ pub_key = (u8 *) &(ctx->pub_key_prefix);
136
136
+
+ *pub_key = ECDSA_PUBKEY_HEADER_XY_PRESENT;
137
137
+
+ err = crypto_sig_set_pubkey(tfm, pub_key, ctx->size + 1);
138
138
+
+ if (err != 0)
139
139
+
+ {
140
140
+
+ pr_info("crypto_sig_set_pubkey failed in lkca_ecdsa_verify: %d", -err);
141
141
+
+ goto failTfm;
142
142
+
+ }
143
143
+
+
144
144
+
+ //
145
145
+
+ // Compared to the way we receive the signature, we need to:
146
146
+
+ // - swap order of all digits
147
147
+
+ // - swap endianness for each digit
148
148
+
+ //
149
149
+
+ memset(&sig, 0, sizeof(sig));
150
150
+
+ ecc_digits_from_bytes(signature, ctx->size/2, sig.r, ECC_MAX_DIGITS);
151
151
+
+ ecc_digits_from_bytes(signature + ctx->size/2, ctx->size/2, sig.s, ECC_MAX_DIGITS);
152
152
+
+
153
153
+
+ err = crypto_sig_verify(tfm, (void *)&sig, sizeof(sig), message_hash, hash_size);
154
154
+
+ if (err != 0)
155
155
+
+ {
156
156
+
+ pr_info("crypto_sig_verify failed in lkca_ecdsa_verify %d\n", -err);
157
157
+
+ }
158
158
+
+
159
159
+
+failTfm:
160
160
+
+ crypto_free_sig(tfm);
161
161
+
+
162
162
+
+ return err == 0;
163
163
+
+#endif // USE_LKCA
164
164
+
+}
165
165
+
+
166
166
+
+#else // NV_CRYPTO_AKCIPHER_VERIFY_PRESENT
167
167
+
+static bool lkca_ecdsa_verify_akcipher(void *ec_context, size_t hash_nid,
168
168
+
+ const uint8_t *message_hash, size_t hash_size,
169
169
+
+ const uint8_t *signature, size_t sig_size)
170
170
+
+{
171
171
+
+#ifndef USE_LKCA
172
172
+
+ return false;
173
173
+
+#else // USE_LKCA
174
174
+
+ struct ecc_ctx *ctx = ec_context;
175
175
+
+ u8 *pub_key;
176
176
+
+ int err;
177
177
+
+ DECLARE_CRYPTO_WAIT(wait);
178
178
+
179
179
+
// Roundabout way
180
180
+
u64 ber_max_len = 3 + 2 * (4 + (ECC_MAX_BYTES));
181
181
+
u64 ber_len = 0;
182
182
+
u8 *ber = NULL;
183
183
+
- u8 *pub_key;
184
184
+
struct akcipher_request *req = NULL;
185
185
+
struct crypto_akcipher *tfm = NULL;
186
186
+
struct scatterlist sg;
187
187
+
- DECLARE_CRYPTO_WAIT(wait);
188
188
+
- int err;
189
189
+
190
190
+
if (sig_size != ctx->size) {
191
191
+
return false;
192
192
+
@@ -251,21 +322,21 @@ bool lkca_ecdsa_verify(void *ec_context, size_t hash_nid,
193
193
+
194
194
+
tfm = crypto_alloc_akcipher(ctx->name, CRYPTO_ALG_TYPE_AKCIPHER, 0);
195
195
+
if (IS_ERR(tfm)) {
196
196
+
- pr_info("ALLOC FAILED\n");
197
197
+
+ pr_info("crypto_alloc_akcipher failed in lkca_ecdsa_verify\n");
198
198
+
return false;
199
199
+
}
200
200
+
201
201
+
- pub_key = (u8 *) ctx->pub_key;
202
202
+
- pub_key--; // Go back into byte of pub_key_prefix
203
203
+
- *pub_key = 4; // And set it to 4 to placate kernel
204
204
+
+ // modify header of pubkey to indicate size
205
205
+
+ pub_key = (u8 *) &(ctx->pub_key_prefix);
206
206
+
+ *pub_key = ECDSA_PUBKEY_HEADER_XY_PRESENT;
207
207
+
if ((err = crypto_akcipher_set_pub_key(tfm, pub_key, ctx->size + 1)) != 0) {
208
208
+
- pr_info("SET PUB KEY FAILED: %d\n", -err);
209
209
+
+ pr_info("crypto_akcipher_set_pub_key failed in lkca_ecdsa_verify: %d\n", -err);
210
210
+
goto failTfm;
211
211
+
}
212
212
+
213
213
+
req = akcipher_request_alloc(tfm, GFP_KERNEL);
214
214
+
if (IS_ERR(req)) {
215
215
+
- pr_info("REQUEST ALLOC FAILED\n");
216
216
+
+ pr_info("akcipher_request_alloc failed in lkca_ecdsa_verify\n");
217
217
+
goto failTfm;
218
218
+
}
219
219
+
220
220
+
@@ -310,9 +381,8 @@ bool lkca_ecdsa_verify(void *ec_context, size_t hash_nid,
221
221
+
CRYPTO_TFM_REQ_MAY_SLEEP, crypto_req_done, &wait);
222
222
+
akcipher_request_set_crypt(req, &sg, NULL, ber_len, hash_size);
223
223
+
err = crypto_wait_req(crypto_akcipher_verify(req), &wait);
224
224
+
-
225
225
+
if (err != 0){
226
226
+
- pr_info("Verify FAILED %d\n", -err);
227
227
+
+ pr_info("crypto_akcipher_verify failed in lkca_ecdsa_verify %d\n", -err);
228
228
+
}
229
229
+
230
230
+
kfree(ber);
231
231
+
@@ -322,5 +392,19 @@ failTfm:
232
232
+
crypto_free_akcipher(tfm);
233
233
+
234
234
+
return err == 0;
235
235
+
-#endif
236
236
+
+#endif // USE_LKCA
237
237
+
+}
238
238
+
+#endif // NV_CRYPTO_AKCIPHER_VERIFY_PRESENT
239
239
+
+
240
240
+
+bool lkca_ecdsa_verify(void *ec_context, size_t hash_nid,
241
241
+
+ const uint8_t *message_hash, size_t hash_size,
242
242
+
+ const uint8_t *signature, size_t sig_size)
243
243
+
+{
244
244
+
+#ifndef NV_CRYPTO_AKCIPHER_VERIFY_PRESENT
245
245
+
+ return lkca_ecdsa_verify_crypto_sig(ec_context, hash_nid, message_hash, hash_size,
246
246
+
+ signature, sig_size);
247
247
+
+#else // NV_CRYPTO_AKCIPHER_VERIFY_PRESENT
248
248
+
+ return lkca_ecdsa_verify_akcipher(ec_context, hash_nid, message_hash, hash_size,
249
249
+
+ signature, sig_size);
250
250
+
+#endif // NV_CRYPTO_AKCIPHER_VERIFY_PRESENT
251
251
+
}
+11
pkgs/os-specific/linux/nvidia-x11/default.nix
···
70
70
openSha256 = "sha256-hjpwTR4I0MM5dEjQn7MKM3RY1a4Mt6a61Ii9KW2KbiY=";
71
71
settingsSha256 = "sha256-Wk6IlVvs23cB4s0aMeZzSvbOQqB1RnxGMv3HkKBoIgY=";
72
72
persistencedSha256 = "sha256-yQFrVk4i2dwReN0XoplkJ++iA1WFhnIkP7ns4ORmkFA=";
73
73
+
patchesOpen = [
74
74
+
./nvidia-nv-Convert-symbol-namespace-to-string-literal.patch
75
75
+
./crypto-Add-fix-for-6.13-Module-compilation.patch
76
76
+
];
73
77
};
74
78
75
79
latest = selectHighestVersion production (generic {
···
79
83
openSha256 = "sha256-Fxo0t61KQDs71YA8u7arY+503wkAc1foaa51vi2Pl5I=";
80
84
settingsSha256 = "sha256-VUetj3LlOSz/LB+DDfMCN34uA4bNTTpjDrb6C6Iwukk=";
81
85
persistencedSha256 = "sha256-wnDjC099D8d9NJSp9D0CbsL+vfHXyJFYYgU3CwcqKww=";
86
86
+
patches = [
87
87
+
./fix-for-linux-6.13.patch
88
88
+
];
89
89
+
patchesOpen = [
90
90
+
./nvidia-nv-Convert-symbol-namespace-to-string-literal.patch
91
91
+
./crypto-Add-fix-for-6.13-Module-compilation.patch
92
92
+
];
82
93
});
83
94
84
95
beta = selectHighestVersion latest (generic {
+48
pkgs/os-specific/linux/nvidia-x11/fix-for-linux-6.13.patch
···
1
1
+
diff --git a/kernel/nvidia-modeset/nvidia-modeset.Kbuild b/kernel/nvidia-modeset/nvidia-modeset.Kbuild
2
2
+
index a7d84e0..d417c28 100644
3
3
+
--- a/kernel/nvidia-modeset/nvidia-modeset.Kbuild
4
4
+
+++ b/kernel/nvidia-modeset/nvidia-modeset.Kbuild
5
5
+
@@ -40,13 +40,15 @@ NV_KERNEL_MODULE_TARGETS += $(NVIDIA_MODESET_KO)
6
6
+
NVIDIA_MODESET_BINARY_OBJECT := $(src)/nvidia-modeset/nv-modeset-kernel.o_binary
7
7
+
NVIDIA_MODESET_BINARY_OBJECT_O := nvidia-modeset/nv-modeset-kernel.o
8
8
+
9
9
+
-quiet_cmd_symlink = SYMLINK $@
10
10
+
-cmd_symlink = ln -sf $< $@
11
11
+
+# Rel. commit 80f289101690 "kbuild: change working directory to external module directory with M=" (Masahiro Yamada, 10 Nov 2024)
12
12
+
+# Ensure `$<` is absolute, since the link target is resolved relative to its path, not from where `ln` is run from.
13
13
+
+quiet_cmd_symlinkabs = SYMLINK $@
14
14
+
+ cmd_symlinkabs = ln -sf $(abspath $<) $@
15
15
+
16
16
+
targets += $(NVIDIA_MODESET_BINARY_OBJECT_O)
17
17
+
18
18
+
$(obj)/$(NVIDIA_MODESET_BINARY_OBJECT_O): $(NVIDIA_MODESET_BINARY_OBJECT) FORCE
19
19
+
- $(call if_changed,symlink)
20
20
+
+ $(call if_changed,symlinkabs)
21
21
+
22
22
+
nvidia-modeset-y += $(NVIDIA_MODESET_BINARY_OBJECT_O)
23
23
+
24
24
+
diff --git a/kernel/nvidia/nvidia.Kbuild b/kernel/nvidia/nvidia.Kbuild
25
25
+
index 31a6f92..62689f6 100644
26
26
+
--- a/kernel/nvidia/nvidia.Kbuild
27
27
+
+++ b/kernel/nvidia/nvidia.Kbuild
28
28
+
@@ -40,13 +40,15 @@ NVIDIA_KO = nvidia/nvidia.ko
29
29
+
NVIDIA_BINARY_OBJECT := $(src)/nvidia/nv-kernel.o_binary
30
30
+
NVIDIA_BINARY_OBJECT_O := nvidia/nv-kernel.o
31
31
+
32
32
+
-quiet_cmd_symlink = SYMLINK $@
33
33
+
- cmd_symlink = ln -sf $< $@
34
34
+
+# Rel. commit 80f289101690 "kbuild: change working directory to external module directory with M=" (Masahiro Yamada, 10 Nov 2024)
35
35
+
+# Ensure `$<` is absolute, since the link target is resolved relative to its path, not from where `ln` is run from.
36
36
+
+quiet_cmd_symlinkabs = SYMLINK $@
37
37
+
+ cmd_symlinkabs = ln -sf $(abspath $<) $@
38
38
+
39
39
+
targets += $(NVIDIA_BINARY_OBJECT_O)
40
40
+
41
41
+
$(obj)/$(NVIDIA_BINARY_OBJECT_O): $(NVIDIA_BINARY_OBJECT) FORCE
42
42
+
- $(call if_changed,symlink)
43
43
+
+ $(call if_changed,symlinkabs)
44
44
+
45
45
+
nvidia-y += $(NVIDIA_BINARY_OBJECT_O)
46
46
+
47
47
+
--
48
48
+
2.47.0
+40
pkgs/os-specific/linux/nvidia-x11/nvidia-nv-Convert-symbol-namespace-to-string-literal.patch
···
1
1
+
From 35a25dda24d8f02ca89d53e5975fa7705058c39e Mon Sep 17 00:00:00 2001
2
2
+
From: Eric Naim <dnaim@cachyos.org>
3
3
+
Date: Mon, 9 Dec 2024 19:45:50 +0800
4
4
+
Subject: [PATCH 07/10] nvidia/nv: Convert symbol namespace to string literal
5
5
+
6
6
+
Commit https://github.com/torvalds/linux/commit/cdd30ebb1b9f36159d66f088b61aee264e649d7a ("module: Convert symbol namespace to string literal")
7
7
+
breaks importing symbol namespaces. Apply this change only for 6.13 and higher.
8
8
+
9
9
+
Signed-off-by: Eric Naim <dnaim@cachyos.org>
10
10
+
---
11
11
+
kernel-open/nvidia/nv.c | 5 +++++
12
12
+
1 file changed, 5 insertions(+)
13
13
+
14
14
+
diff --git a/kernel-open/nvidia/nv.c b/kernel-open/nvidia/nv.c
15
15
+
index 83705a05..1e7de9ea 100644
16
16
+
--- a/kernel-open/nvidia/nv.c
17
17
+
+++ b/kernel-open/nvidia/nv.c
18
18
+
@@ -22,6 +22,7 @@
19
19
+
*/
20
20
+
21
21
+
#include <linux/module.h> // for MODULE_FIRMWARE
22
22
+
+#include <linux/version.h>
23
23
+
24
24
+
// must precede "nv.h" and "nv-firmware.h" includes
25
25
+
#define NV_FIRMWARE_FOR_NAME(name) "nvidia/" NV_VERSION_STRING "/" name ".bin"
26
26
+
@@ -127,7 +128,11 @@ MODULE_ALIAS_CHARDEV_MAJOR(NV_MAJOR_DEVICE_NUMBER);
27
27
+
* DMA_BUF namespace is added by commit id 16b0314aa746
28
28
+
* ("dma-buf: move dma-buf symbols into the DMA_BUF module namespace") in 5.16
29
29
+
*/
30
30
+
+#if LINUX_VERSION_CODE >= KERNEL_VERSION(6, 13, 0)
31
31
+
+MODULE_IMPORT_NS("DMA_BUF");
32
32
+
+#else
33
33
+
MODULE_IMPORT_NS(DMA_BUF);
34
34
+
+#endif
35
35
+
#endif // defined(MODULE_IMPORT_NS)
36
36
+
37
37
+
const NvBool nv_is_rm_firmware_supported_os = NV_TRUE;
38
38
+
--
39
39
+
2.47.1
40
40
+