Re: [PATCH] ppp: deflate: Fix possible crash in deflate_init

From: YueHaibing
Date: Tue May 14 2019 - 10:44:44 EST


On 2019/5/14 22:05, Guillaume Nault wrote:
> On Tue, May 14, 2019 at 03:43:00PM +0800, YueHaibing wrote:
>>
>> If ppp_deflate fails to register in deflate_init,
>> module initialization failed out, however
>> ppp_deflate_draft may has been regiestred and not
>> unregistered before return.
>> Then the seconed modprobe will trigger crash like this.
>>
>> Reported-by: Hulk Robot <hulkci@xxxxxxxxxx>
>> Signed-off-by: YueHaibing <yuehaibing@xxxxxxxxxx>
>> ---
>> drivers/net/ppp/ppp_deflate.c | 14 +++++++++-----
>> 1 file changed, 9 insertions(+), 5 deletions(-)
>>
>> diff --git a/drivers/net/ppp/ppp_deflate.c b/drivers/net/ppp/ppp_deflate.c
>> index b5edc7f..2829efe 100644
>> --- a/drivers/net/ppp/ppp_deflate.c
>> +++ b/drivers/net/ppp/ppp_deflate.c
>> @@ -610,12 +610,16 @@ static void z_incomp(void *arg, unsigned char *ibuf, int icnt)
>>
>> static int __init deflate_init(void)
>> {
>> - int answer = ppp_register_compressor(&ppp_deflate);
>> - if (answer == 0)
>> - printk(KERN_INFO
>> - "PPP Deflate Compression module registered\n");
>> + int answer;
>> +
>> + answer = ppp_register_compressor(&ppp_deflate);
>> + if (answer)
>> + return answer;
>> +
>> + pr_info("PPP Deflate Compression module registered\n");
>> ppp_register_compressor(&ppp_deflate_draft);
>> - return answer;
>> +
>> + return 0;
>> }
>>
> I'd be cleaner to also check for ppp_deflate_draft registration failure
> IMHO (and print the log line only if both compressors get registered
> successfully).

Ok, will send v2 to do that, thanks!

>
> .
>