Potential NULL pointer deference in drbg_ctr_df
PATCH 1/1 Potential NULL pointer deference in drbg_ctr_df
In reply to a message not in the archiveThe handling of additional input data / personalization string data may be subject to a NULL pointer deference for the CTR DRBG. The caller-provided data may be NULL which must be caught by the DRBG.
--- crypto/drbg.c | 23 +++++++++++++---------- 1 file changed, 13 insertions(+), 10 deletions(-)
crypto/drbg.c +13 -10
@@ -513,17 +513,20 @@ static int drbg_ctr_df(struct drbg_state *drbg,drbg_string_fill (&S2 ,L_N ,sizeof (L_N ));drbg_string_fill (&S4 , pad, padlen);S1 .next = &S2 ; -S2 .next = addtl; -/* -* splice in addtl between S2 and S4 -- we place S4 at the end of the -* input data chain -*/ - tempstr = addtl; -for (;NULL != tempstr; tempstr = tempstr->next) -if (NULL == tempstr->next) -break ; - tempstr->next = &S4 ; +if (NULL == addtl) { +S2 .next = &S4 ; + }else { +/* +* splice in addtl between S2 and S4 -- we place S4 at the end +* of the input data chain +*/ +S2 .next = addtl; + tempstr = addtl; +while (tempstr->next) + tempstr = tempstr->next; + tempstr->next = &S4 ; + }/* 10.4.2 step 9 */ while (templen < (drbg_keylen (drbg) + (drbg_blocklen (drbg)))) {
Signature · 1 line
1.9.3
Herbert Xu
maintainerQuoted 31 lines · Stephan Mueller
The handling of additional input data / personalization string data may be subject to a NULL pointer deference for the CTR DRBG. The caller-provided data may be NULL which must be caught by the DRBG.
Reported-by kbuild test robot <[email protected]>Signed-off-by Stephan Mueller <[email protected]>--- crypto/drbg.c | 23 +++++++++++++---------- 1 file changed, 13 insertions(+), 10 deletions(-)crypto/drbg.c +2
-10@@ -513,17 +513,20 @@ static int drbg_ctr_df(struct drbg_state *drbg,drbg_string_fill (&S2 ,L_N ,sizeof (L_N ));drbg_string_fill (&S4 , pad, padlen);S1 .next = &S2 ; -S2 .next = addtl; -/* -* splice in addtl between S2 and S4 -- we place S4 at the end of the -* input data chain -*/ - tempstr = addtl; -for (;NULL != tempstr; tempstr = tempstr->next) -if (NULL == tempstr->next) -break ; - tempstr->next = &S4 ; +if (NULL == addtl) { +S2 .next = &S4 ;
crypto/drbg.c static int drbg_ctr_df(struct drbg_state *drbg, · line 528
Quoted 10 lines
crypto/drbg.c +10
-0+ }else { +/* +* splice in addtl between S2 and S4 -- we place S4 at the end +* of the input data chain +*/ +S2 .next = addtl; + tempstr = addtl; +while (tempstr->next) + tempstr = tempstr->next; + tempstr->next = &S4 ;
You've still got exactly the same NULL dereference.
Signature · 3 lines
Email: Herbert Xu <[email protected]> Home Page: http://gondor.apana.org.au/~herbert/ PGP Key: http://gondor.apana.org.au/~herbert/pubkey.txt
Herbert Xu
maintainerRe: [cryptodev:master 9/28] crypto/drbg.c:526 drbg_ctr_df() error: we previously assumed 'tempstr' could be null (see line 523)
In reply to a message not in the archiveQuoted 10 lines · Stephan Mueller
Am Freitag, 20. Juni 2014, 23:24:18 schrieb kbuild test robot:
Hi,
first of all, thanks for the information. As you have seen, I created a patch covering your comments on the NULL pointer handling.
Quoted 3 lines
The kernel also provides standard linked list features and you should consider using those instead of rolling your own.
Quoted 7 lines
There is a reason for this approach: the very same code (with exception of the interface code part) is also available for libgcrypt -- see [1] and gcrypt- devel. I did not want to have different code, because any bug fix relevant to the one implementation is also important to the other. Thus, I feel that it is beneficial to use the linked list feature as implemented in the current DRBG.
This is unacceptable. We are not going to add crap to the kernel just because the same crap exists elsewhere.
Please fix this or I will be reverting your patches.
Thanks,
Signature · 3 lines
Email: Herbert Xu <[email protected]> Home Page: http://gondor.apana.org.au/~herbert/ PGP Key: http://gondor.apana.org.au/~herbert/pubkey.txt
Quoted 6 lines · Herbert Xu
Quoted 5 lines · Stephan Mueller
The handling of additional input data / personalization string data may be subject to a NULL pointer deference for the CTR DRBG. The caller-provided data may be NULL which must be caught by the DRBG.
Reported-by kbuild test robot <[email protected]>
Oh, huh. This bug was actually reported by me but I forgot to change the from header and apparently my smtp server allows me to send emails as if I work for Intel. :P
Fengguang is much nicer than I am. :P
Quoted 30 lines
Quoted 30 lines
Signed-off-by Stephan Mueller <[email protected]>--- crypto/drbg.c | 23 +++++++++++++---------- 1 file changed, 13 insertions(+), 10 deletions(-)crypto/drbg.c +6
-10@@ -513,17 +513,20 @@ static int drbg_ctr_df(struct drbg_state *drbg,drbg_string_fill (&S2 ,L_N ,sizeof (L_N ));drbg_string_fill (&S4 , pad, padlen);S1 .next = &S2 ; -S2 .next = addtl; -/* -* splice in addtl between S2 and S4 -- we place S4 at the end of the -* input data chain -*/ - tempstr = addtl; -for (;NULL != tempstr; tempstr = tempstr->next) -if (NULL == tempstr->next) -break ; - tempstr->next = &S4 ; +if (NULL == addtl) { +S2 .next = &S4 ; + }else { +/* +* splice in addtl between S2 and S4 -- we place S4 at the end +* of the input data chain
Quoted 8 lines
crypto/drbg.c static int drbg_ctr_df(struct drbg_state *drbg, · line 528
Quoted 6 lines
crypto/drbg.c +6
-0+*/ +S2 .next = addtl; + tempstr = addtl; +while (tempstr->next) + tempstr = tempstr->next; + tempstr->next = &S4 ;You've still got exactly the same NULL dereference.
I was offline for a bit so I'm coming into this late. It's weird that Stephan isn't defending his patch but it looks ok to me...
regards,
dan carpenter
Am Freitag, 4. Juli 2014, 13:50:03 schrieb Dan Carpenter:
Hi Dan,
Quoted 6 lines · Herbert Xu
Quoted 5 lines · Stephan Mueller
Quoted 4 lines
The handling of additional input data / personalization string data may be subject to a NULL pointer deference for the CTR DRBG. The caller-provided data may be NULL which must be caught by the DRBG.
Quoted 7 lines
Quoted 1 line
Quoted 1 line
Reported-by kbuild test robot <[email protected]>Oh, huh. This bug was actually reported by me but I forgot to change the from header and apparently my smtp server allows me to send emails as if I work for Intel. :P
Fengguang is much nicer than I am. :P
Too late, your colleague's name is now in the patches ;-)
Quoted 43 lines
Quoted 34 lines
Quoted 34 lines
Signed-off-by Stephan Mueller <[email protected]>---
crypto/drbg.c | 23 +++++++++++++---------- 1 file changed, 13 insertions(+), 10 deletions(-)crypto/drbg.c +6
-10@@ -513,17 +513,20 @@ static int drbg_ctr_df(struct drbg_state *drbg,drbg_string_fill (&S2 ,L_N ,sizeof (L_N ));drbg_string_fill (&S4 , pad, padlen);S1 .next = &S2 ; -S2 .next = addtl; -/* -* splice in addtl between S2 and S4 -- we place S4 at the end of the -* input data chain -*/ - tempstr = addtl; -for (;NULL != tempstr; tempstr = tempstr->next) -if (NULL == tempstr->next) -break ; - tempstr->next = &S4 ; +if (NULL == addtl) { +S2 .next = &S4 ; + }else { +/* +* splice in addtl between S2 and S4 -- we place S4 at the end +* of the input data chain Quoted 8 lines
crypto/drbg.c static int drbg_ctr_df(struct drbg_state *drbg, · line 528
Quoted 6 lines
crypto/drbg.c +6
-0+*/ +S2 .next = addtl; + tempstr = addtl; +while (tempstr->next) + tempstr = tempstr->next; + tempstr->next = &S4 ;You've still got exactly the same NULL dereference.
Quoted 2 lines
I was offline for a bit so I'm coming into this late. It's weird that Stephan isn't defending his patch but it looks ok to me...
It has been clarified in a later email that there was no NULL pointer after all. I erroneously sent this message and initially missed the check that guards against the NULL pointer.
Quoted 3 lines
regards,
dan carpenter
Signature · 2 lines
Ciao Stephan
Quoted 12 lines · Stephan Mueller
Am Freitag, 4. Juli 2014, 13:50:03 schrieb Dan Carpenter:
Hi Dan,
Quoted 8 lines · Herbert Xu
Quoted 6 lines · Stephan Mueller
Quoted 5 lines
The handling of additional input data / personalization string data may be subject to a NULL pointer deference for the CTR DRBG. The caller-provided data may be NULL which must be caught by the DRBG.
Reported-by kbuild test robot <[email protected]>
Quoted 7 lines
Quoted 5 lines
Oh, huh. This bug was actually reported by me but I forgot to change the from header and apparently my smtp server allows me to send emails as if I work for Intel. :P
Fengguang is much nicer than I am. :P
Too late, your colleague's name is now in the patches ;-)
Thank you nice guys! :P
Thanks,
Fengguang