History

Merge tag 'for-next-keys-7.2-rc6' of git://git.kernel.org/pub/scm/linux/kernel/git/jarkko/linux-tpmdd

Pull keys fixes from Jarkko Sakkinen: - An unprivileged keyring whose keys collide through the description-chunk path can drive assoc_array node splitting into an out-of-bounds slot write. Fix it. - Fix the DCP trusted keys backend * tag 'for-next-keys-7.2-rc6' of git://git.kernel.org/pub/scm/linux/kernel/git/jarkko/linux-tpmdd: assoc_array: trim the final shortcut word using the current chunk end keys: make keyring key-chunk byte order agree with keyring_diff_objects() keys: fix out-of-bounds read in keyring_get_key_chunk() KEYS: trusted: dcp: fix key_len validation and calc_blob_len() return type

Linus Torvalds committed 3 months ago

Commit aa6fc3d2 parents e895a6f a82c8a03 files · +21 −11Browse files

Unified · Split

3 files
  1. lib/assoc_array.c +2 −1
  2. security/keys/keyring.c +8 −6
  3. security/keys/trusted-keys/trusted_dcp.c +11 −4
lib/assoc_array.c+2−1
@@ -255,7 +255,8 @@ follow_shortcut: · 254 unmodified lines
255255 sc_segments = shortcut->index_key[sc_level >> ASSOC_ARRAY_KEY_CHUNK_SHIFT];
256256 dissimilarity = segments ^ sc_segments;
257257
258− if (round_up(sc_level, ASSOC_ARRAY_KEY_CHUNK_SIZE) > shortcut->skip_to_level) {
258+ if (shortcut->skip_to_level < round_down(sc_level,
259+ ASSOC_ARRAY_KEY_CHUNK_SIZE) + ASSOC_ARRAY_KEY_CHUNK_SIZE) {
259260 /* Trim segments that are beyond the shortcut */
260261 int shift = shortcut->skip_to_level & ASSOC_ARRAY_KEY_CHUNK_MASK;
261262 dissimilarity &= ~(ULONG_MAX << shift);
security/keys/keyring.c+8−6
@@ -271,6 +271,7 @@ static unsigned long keyring_get_key_chunk(const void *data, int level) · 270 unmodified lines
271271 unsigned long chunk = 0;
272272 const u8 *d;
273273 int desc_len = index_key->desc_len, n = sizeof(chunk);
274+ unsigned int offset;
274275
275276 level /= ASSOC_ARRAY_KEY_CHUNK_SIZE;
276277 switch (level) {
@@ -284,17 +285,18 @@ static unsigned long keyring_get_key_chunk(const void *data, int level) · 7 unmodified lines
284285 return (unsigned long)index_key->domain_tag;
285286 default:
286287 level -= 4;
287− if (desc_len <= sizeof(index_key->desc))
288+ offset = sizeof(index_key->desc) + level * sizeof(long);
289+ if (desc_len <= offset)
288290 return 0;
289291
290− d = index_key->description + sizeof(index_key->desc);
291− d += level * sizeof(long);
292− desc_len -= sizeof(index_key->desc);
292+ d = index_key->description + offset;
293+ desc_len -= offset;
293294 if (desc_len > n)
294295 desc_len = n;
296+ d += desc_len;
295297 do {
296298 chunk <<= 8;
297− chunk |= *d++;
299+ chunk |= *--d;
298300 } while (--desc_len > 0);
299301 return chunk;
300302 }
@@ -375,7 +377,7 @@ same: · 74 unmodified lines
375377 return -1;
376378
377379 differ_plus_i:
378− level += i;
380+ level += i - (int)sizeof(a->desc);
379381 differ:
380382 i = level * 8 + __ffs(seg_a ^ seg_b);
381383 return i;
security/keys/trusted-keys/trusted_dcp.c+11−4
@@ -69,7 +69,7 @@ static bool skip_zk_test; · 68 unmodified lines
6969 module_param_named(dcp_skip_zk_test, skip_zk_test, bool, 0);
7070 MODULE_PARM_DESC(dcp_skip_zk_test, "Don't test whether device keys are zero'ed");
7171
72−static unsigned int calc_blob_len(unsigned int payload_len)
72+static size_t calc_blob_len(unsigned int payload_len)
7373 {
7474 return sizeof(struct dcp_blob_fmt) + payload_len + DCP_BLOB_AUTHLEN;
7575 }
@@ -200,7 +200,8 @@ static int encrypt_blob_key(u8 *plain_key, u8 *encrypted_key) · 124 unmodified lines
200200 static int trusted_dcp_seal(struct trusted_key_payload *p, char *datablob)
201201 {
202202 struct dcp_blob_fmt *b = (struct dcp_blob_fmt *)p->blob;
203− int blen, ret;
203+ size_t blen;
204+ int ret;
204205 u8 *plain_blob_key;
205206
206207 blen = calc_blob_len(p->key_len);
@@ -242,7 +243,8 @@ out: · 35 unmodified lines
242243 static int trusted_dcp_unseal(struct trusted_key_payload *p, char *datablob)
243244 {
244245 struct dcp_blob_fmt *b = (struct dcp_blob_fmt *)p->blob;
245− int blen, ret;
246+ size_t blen;
247+ int ret;
246248 u8 *plain_blob_key = NULL;
247249
248250 if (b->fmt_version != DCP_BLOB_VERSION) {
@@ -253,9 +255,14 @@ static int trusted_dcp_unseal(struct trusted_key_payload *p, char *datablob) · 4 unmodified lines
253255 }
254256
255257 p->key_len = le32_to_cpu(b->payload_len);
258+ if (p->key_len < MIN_KEY_SIZE || p->key_len > MAX_KEY_SIZE) {
259+ ret = -EINVAL;
260+ goto out;
261+ }
262+
256263 blen = calc_blob_len(p->key_len);
257264 if (blen != p->blob_len) {
258− pr_err("DCP blob has bad length: %i != %i\n", blen,
265+ pr_err("DCP blob has bad length: %zu != %u\n", blen,
259266 p->blob_len);
260267 ret = -EINVAL;
261268 goto out;

Keyboard shortcuts

General

Show keyboard shortcuts
?
Focus the current search
/

Issues and pull requests

Open filters
f

Issues, pull requests and Inbox

Select next item
j↓
Select previous item
k↑
Open selected item
Enter
Dismiss filters or clear selection
Esc

Repository code

Go to file
t