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
255 sc_segments = shortcut->index_key[sc_level >> ASSOC_ARRAY_KEY_CHUNK_SHIFT];255 sc_segments = shortcut->index_key[sc_level >> ASSOC_ARRAY_KEY_CHUNK_SHIFT];
256 dissimilarity = segments ^ sc_segments;256 dissimilarity = segments ^ sc_segments;
257 257
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) {
259 /* Trim segments that are beyond the shortcut */260 /* Trim segments that are beyond the shortcut */
260 int shift = shortcut->skip_to_level & ASSOC_ARRAY_KEY_CHUNK_MASK;261 int shift = shortcut->skip_to_level & ASSOC_ARRAY_KEY_CHUNK_MASK;
261 dissimilarity &= ~(ULONG_MAX << shift);262 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
271 unsigned long chunk = 0;271 unsigned long chunk = 0;
272 const u8 *d;272 const u8 *d;
273 int desc_len = index_key->desc_len, n = sizeof(chunk);273 int desc_len = index_key->desc_len, n = sizeof(chunk);
274 unsigned int offset;
274 275
275 level /= ASSOC_ARRAY_KEY_CHUNK_SIZE;276 level /= ASSOC_ARRAY_KEY_CHUNK_SIZE;
276 switch (level) {277 switch (level) {
@@ -284,17 +285,18 @@ static unsigned long keyring_get_key_chunk(const void *data, int level) · 7 unmodified lines
284 return (unsigned long)index_key->domain_tag;285 return (unsigned long)index_key->domain_tag;
285 default:286 default:
286 level -= 4;287 level -= 4;
287 if (desc_len <= sizeof(index_key->desc))288 offset = sizeof(index_key->desc) + level * sizeof(long);
289 if (desc_len <= offset)
288 return 0;290 return 0;
289 291
290 d = index_key->description + sizeof(index_key->desc);292 d = index_key->description + offset;
291 d += level * sizeof(long);293 desc_len -= offset;
292 desc_len -= sizeof(index_key->desc);
293 if (desc_len > n)294 if (desc_len > n)
294 desc_len = n;295 desc_len = n;
296 d += desc_len;
295 do {297 do {
296 chunk <<= 8;298 chunk <<= 8;
297 chunk |= *d++;299 chunk |= *--d;
298 } while (--desc_len > 0);300 } while (--desc_len > 0);
299 return chunk;301 return chunk;
300 }302 }
@@ -375,7 +377,7 @@ same: · 74 unmodified lines
375 return -1;377 return -1;
376 378
377differ_plus_i:379differ_plus_i:
378 level += i;380 level += i - (int)sizeof(a->desc);
379differ:381differ:
380 i = level * 8 + __ffs(seg_a ^ seg_b);382 i = level * 8 + __ffs(seg_a ^ seg_b);
381 return i;383 return i;
security/keys/trusted-keys/trusted_dcp.c+11−4
@@ -69,7 +69,7 @@ static bool skip_zk_test; · 68 unmodified lines
69module_param_named(dcp_skip_zk_test, skip_zk_test, bool, 0);69module_param_named(dcp_skip_zk_test, skip_zk_test, bool, 0);
70MODULE_PARM_DESC(dcp_skip_zk_test, "Don't test whether device keys are zero'ed");70MODULE_PARM_DESC(dcp_skip_zk_test, "Don't test whether device keys are zero'ed");
71 71
72static unsigned int calc_blob_len(unsigned int payload_len)72static size_t calc_blob_len(unsigned int payload_len)
73{73{
74 return sizeof(struct dcp_blob_fmt) + payload_len + DCP_BLOB_AUTHLEN;74 return sizeof(struct dcp_blob_fmt) + payload_len + DCP_BLOB_AUTHLEN;
75}75}
@@ -200,7 +200,8 @@ static int encrypt_blob_key(u8 *plain_key, u8 *encrypted_key) · 124 unmodified lines
200static int trusted_dcp_seal(struct trusted_key_payload *p, char *datablob)200static int trusted_dcp_seal(struct trusted_key_payload *p, char *datablob)
201{201{
202 struct dcp_blob_fmt *b = (struct dcp_blob_fmt *)p->blob;202 struct dcp_blob_fmt *b = (struct dcp_blob_fmt *)p->blob;
203 int blen, ret;203 size_t blen;
204 int ret;
204 u8 *plain_blob_key;205 u8 *plain_blob_key;
205 206
206 blen = calc_blob_len(p->key_len);207 blen = calc_blob_len(p->key_len);
@@ -242,7 +243,8 @@ out: · 35 unmodified lines
242static int trusted_dcp_unseal(struct trusted_key_payload *p, char *datablob)243static int trusted_dcp_unseal(struct trusted_key_payload *p, char *datablob)
243{244{
244 struct dcp_blob_fmt *b = (struct dcp_blob_fmt *)p->blob;245 struct dcp_blob_fmt *b = (struct dcp_blob_fmt *)p->blob;
245 int blen, ret;246 size_t blen;
247 int ret;
246 u8 *plain_blob_key = NULL;248 u8 *plain_blob_key = NULL;
247 249
248 if (b->fmt_version != DCP_BLOB_VERSION) {250 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
253 }255 }
254 256
255 p->key_len = le32_to_cpu(b->payload_len);257 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
256 blen = calc_blob_len(p->key_len);263 blen = calc_blob_len(p->key_len);
257 if (blen != p->blob_len) {264 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,
259 p->blob_len);266 p->blob_len);
260 ret = -EINVAL;267 ret = -EINVAL;
261 goto out;268 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