Skip to contentSkip to conversation

keys: correctly check failed allocation for kmemdup

PATCH In review Insu Yun 2 participants 3 messages Oct 15, 2015 1 message not in the archive

Subsystems (2)
lore
Share & tools
lore

Insu Yun

author
#0 lore raw

PATCH 1/1 keys: correctly check failed allocation for kmemdup

kmemdup return value is saved in 'key->index_key.description', not 'key->descrption' and kmemdup can be failed in memory pressure. Therefore, key->index_key.description should be checked.

---
 security/keys/key.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
security/keys/key.c +1 -1
index aee2ec5..c047846 100644
@@ -278,7 +278,7 @@ struct key *key_alloc(struct key_type *type, const char *desc,
 
 	key->index_key.desc_len = desclen;
 	key->index_key.description = kmemdup(desc, desclen + 1, GFP_KERNEL);
-	if (!key->description)
+	if (!key->index_key.description)
 		goto no_memory_3;
 
 	atomic_set(&key->usage, 1);
Signature · 1 line
1.9.1
maintainer
#1 lore raw
Quoted 3 lines · Insu Yun

kmemdup return value is saved in 'key->index_key.description', not 'key->descrption' and kmemdup can be failed in memory pressure. Therefore, key->index_key.description should be checked.

The fields are unioned. It makes no difference.

David

A message that is not in the archive (sent off-list or not yet received): CAGoFzNe6VAQZd_jYb_rXSB=DhSW4bMm1vgtqwPadHbZLWav42w@mail.gmail.com

maintainer
#3 lore raw
Quoted 4 lines · Insu Yun

Thanks David. Then it is not a bug.
It's a pure question.
Why use different name for allocation and check?
For me, it is quite confusing.

Either I didn't notice at the time, or the shorter variant is the original.

If you want to give me a patch making it consistent, feel free.

David