@@ -242,8 +242,8 @@ struct key *key_alloc(struct key_type *type, const char *desc,
242
242
}
243
243
}
244
244
245
- desclen = strlen (desc ) + 1 ;
246
- quotalen = desclen + type -> def_datalen ;
245
+ desclen = strlen (desc );
246
+ quotalen = desclen + 1 + type -> def_datalen ;
247
247
248
248
/* get hold of the key tracking for this user */
249
249
user = key_user_lookup (uid );
@@ -277,15 +277,16 @@ struct key *key_alloc(struct key_type *type, const char *desc,
277
277
goto no_memory_2 ;
278
278
279
279
if (desc ) {
280
- key -> description = kmemdup (desc , desclen , GFP_KERNEL );
280
+ key -> index_key .desc_len = desclen ;
281
+ key -> index_key .description = kmemdup (desc , desclen + 1 , GFP_KERNEL );
281
282
if (!key -> description )
282
283
goto no_memory_3 ;
283
284
}
284
285
285
286
atomic_set (& key -> usage , 1 );
286
287
init_rwsem (& key -> sem );
287
288
lockdep_set_class (& key -> sem , & type -> lock_class );
288
- key -> type = type ;
289
+ key -> index_key . type = type ;
289
290
key -> user = user ;
290
291
key -> quotalen = quotalen ;
291
292
key -> datalen = type -> def_datalen ;
@@ -489,8 +490,7 @@ int key_instantiate_and_link(struct key *key,
489
490
}
490
491
491
492
if (keyring ) {
492
- ret = __key_link_begin (keyring , key -> type , key -> description ,
493
- & prealloc );
493
+ ret = __key_link_begin (keyring , & key -> index_key , & prealloc );
494
494
if (ret < 0 )
495
495
goto error_free_preparse ;
496
496
}
@@ -499,7 +499,7 @@ int key_instantiate_and_link(struct key *key,
499
499
& prealloc );
500
500
501
501
if (keyring )
502
- __key_link_end (keyring , key -> type , prealloc );
502
+ __key_link_end (keyring , & key -> index_key , prealloc );
503
503
504
504
error_free_preparse :
505
505
if (key -> type -> preparse )
@@ -548,8 +548,7 @@ int key_reject_and_link(struct key *key,
548
548
ret = - EBUSY ;
549
549
550
550
if (keyring )
551
- link_ret = __key_link_begin (keyring , key -> type ,
552
- key -> description , & prealloc );
551
+ link_ret = __key_link_begin (keyring , & key -> index_key , & prealloc );
553
552
554
553
mutex_lock (& key_construction_mutex );
555
554
@@ -581,7 +580,7 @@ int key_reject_and_link(struct key *key,
581
580
mutex_unlock (& key_construction_mutex );
582
581
583
582
if (keyring )
584
- __key_link_end (keyring , key -> type , prealloc );
583
+ __key_link_end (keyring , & key -> index_key , prealloc );
585
584
586
585
/* wake up anyone waiting for a key to be constructed */
587
586
if (awaken )
@@ -780,25 +779,27 @@ key_ref_t key_create_or_update(key_ref_t keyring_ref,
780
779
key_perm_t perm ,
781
780
unsigned long flags )
782
781
{
783
- unsigned long prealloc ;
782
+ struct keyring_index_key index_key = {
783
+ .description = description ,
784
+ };
784
785
struct key_preparsed_payload prep ;
785
786
const struct cred * cred = current_cred ();
786
- struct key_type * ktype ;
787
+ unsigned long prealloc ;
787
788
struct key * keyring , * key = NULL ;
788
789
key_ref_t key_ref ;
789
790
int ret ;
790
791
791
792
/* look up the key type to see if it's one of the registered kernel
792
793
* types */
793
- ktype = key_type_lookup (type );
794
- if (IS_ERR (ktype )) {
794
+ index_key . type = key_type_lookup (type );
795
+ if (IS_ERR (index_key . type )) {
795
796
key_ref = ERR_PTR (- ENODEV );
796
797
goto error ;
797
798
}
798
799
799
800
key_ref = ERR_PTR (- EINVAL );
800
- if (!ktype -> match || !ktype -> instantiate ||
801
- (!description && !ktype -> preparse ))
801
+ if (!index_key . type -> match || !index_key . type -> instantiate ||
802
+ (!index_key . description && !index_key . type -> preparse ))
802
803
goto error_put_type ;
803
804
804
805
keyring = key_ref_to_ptr (keyring_ref );
@@ -812,21 +813,22 @@ key_ref_t key_create_or_update(key_ref_t keyring_ref,
812
813
memset (& prep , 0 , sizeof (prep ));
813
814
prep .data = payload ;
814
815
prep .datalen = plen ;
815
- prep .quotalen = ktype -> def_datalen ;
816
- if (ktype -> preparse ) {
817
- ret = ktype -> preparse (& prep );
816
+ prep .quotalen = index_key . type -> def_datalen ;
817
+ if (index_key . type -> preparse ) {
818
+ ret = index_key . type -> preparse (& prep );
818
819
if (ret < 0 ) {
819
820
key_ref = ERR_PTR (ret );
820
821
goto error_put_type ;
821
822
}
822
- if (!description )
823
- description = prep .description ;
823
+ if (!index_key . description )
824
+ index_key . description = prep .description ;
824
825
key_ref = ERR_PTR (- EINVAL );
825
- if (!description )
826
+ if (!index_key . description )
826
827
goto error_free_prep ;
827
828
}
829
+ index_key .desc_len = strlen (index_key .description );
828
830
829
- ret = __key_link_begin (keyring , ktype , description , & prealloc );
831
+ ret = __key_link_begin (keyring , & index_key , & prealloc );
830
832
if (ret < 0 ) {
831
833
key_ref = ERR_PTR (ret );
832
834
goto error_free_prep ;
@@ -844,9 +846,8 @@ key_ref_t key_create_or_update(key_ref_t keyring_ref,
844
846
* key of the same type and description in the destination keyring and
845
847
* update that instead if possible
846
848
*/
847
- if (ktype -> update ) {
848
- key_ref = __keyring_search_one (keyring_ref , ktype , description ,
849
- 0 );
849
+ if (index_key .type -> update ) {
850
+ key_ref = __keyring_search_one (keyring_ref , & index_key , 0 );
850
851
if (!IS_ERR (key_ref ))
851
852
goto found_matching_key ;
852
853
}
@@ -856,16 +857,17 @@ key_ref_t key_create_or_update(key_ref_t keyring_ref,
856
857
perm = KEY_POS_VIEW | KEY_POS_SEARCH | KEY_POS_LINK | KEY_POS_SETATTR ;
857
858
perm |= KEY_USR_VIEW ;
858
859
859
- if (ktype -> read )
860
+ if (index_key . type -> read )
860
861
perm |= KEY_POS_READ ;
861
862
862
- if (ktype == & key_type_keyring || ktype -> update )
863
+ if (index_key .type == & key_type_keyring ||
864
+ index_key .type -> update )
863
865
perm |= KEY_POS_WRITE ;
864
866
}
865
867
866
868
/* allocate a new key */
867
- key = key_alloc (ktype , description , cred -> fsuid , cred -> fsgid , cred ,
868
- perm , flags );
869
+ key = key_alloc (index_key . type , index_key . description ,
870
+ cred -> fsuid , cred -> fsgid , cred , perm , flags );
869
871
if (IS_ERR (key )) {
870
872
key_ref = ERR_CAST (key );
871
873
goto error_link_end ;
@@ -882,20 +884,20 @@ key_ref_t key_create_or_update(key_ref_t keyring_ref,
882
884
key_ref = make_key_ref (key , is_key_possessed (keyring_ref ));
883
885
884
886
error_link_end :
885
- __key_link_end (keyring , ktype , prealloc );
887
+ __key_link_end (keyring , & index_key , prealloc );
886
888
error_free_prep :
887
- if (ktype -> preparse )
888
- ktype -> free_preparse (& prep );
889
+ if (index_key . type -> preparse )
890
+ index_key . type -> free_preparse (& prep );
889
891
error_put_type :
890
- key_type_put (ktype );
892
+ key_type_put (index_key . type );
891
893
error :
892
894
return key_ref ;
893
895
894
896
found_matching_key :
895
897
/* we found a matching key, so we're going to try to update it
896
898
* - we can drop the locks first as we have the key pinned
897
899
*/
898
- __key_link_end (keyring , ktype , prealloc );
900
+ __key_link_end (keyring , & index_key , prealloc );
899
901
900
902
key_ref = __key_update (key_ref , & prep );
901
903
goto error_free_prep ;
0 commit comments