All of lore.kernel.org
 help / color / mirror / Atom feed
From: Randy Dunlap <rdunlap@infradead.org>
To: Heikki Krogerus <heikki.krogerus@linux.intel.com>,
	Zwane Mwaikambo <zwanem@gmail.com>
Cc: Greg KH <gregkh@linuxfoundation.org>,
	Zwane Mwaikambo <zwane@yosper.io>,
	linux-usb@vger.kernel.org
Subject: Re: [PATCH v5 2/2] usb/typec: fix array overruns in ucsi.c partner_altmode[]
Date: Wed, 9 Sep 2020 08:07:37 -0700	[thread overview]
Message-ID: <6a7cd809-5309-2945-d5f9-8147101bff03@infradead.org> (raw)
In-Reply-To: <20200909123355.GA3627076@kuha.fi.intel.com>

On 9/9/20 5:33 AM, Heikki Krogerus wrote:
> Hi,
> 
> One nitpick below...
> 
> On Sun, Aug 30, 2020 at 02:28:39AM -0700, Zwane Mwaikambo wrote:
>> This fixes the second array overrun occurrence (similar failure mode to 
>> the first), this time in ucsi_unregister_altmodes.
>>
>> [ 4373.153246] BUG: kernel NULL pointer dereference, address: 
>> 00000000000002f2
>> [ 4373.153267] #PF: supervisor read access in kernel mode
>> [ 4373.153271] #PF: error_code(0x0000) - not-present page
>> [ 4373.153275] PGD 0 P4D 0 
>> [ 4373.153284] Oops: 0000 [#2] PREEMPT SMP NOPTI
>> [ 4373.153292] CPU: 0 PID: 13242 Comm: kworker/0:0 Tainted: G      D           
>> 5.8.0-rc6+ #1
>> [ 4373.153296] Hardware name: LENOVO 20RD002VUS/20RD002VUS, BIOS R16ET25W 
>> (1.11 ) 04/21/2020
>> [ 4373.153308] Workqueue: events ucsi_handle_connector_change [typec_ucsi]
>> [ 4373.153320] RIP: 0010:ucsi_unregister_altmodes+0x5f/0xa0 [typec_ucsi]
>> [ 4373.153326] Code: 54 48 8b 3b 41 83 c4 01 e8 9e f9 0c 00 49 63 c4 48 c7 
>> 03 00 00 00 00 49 8d 5c c5 00 48 8b 3b 48 85 ff 74 31 41 80 fe 01 75 d7 
>> <0f> b7 87 f0 02 00 00 66 3d 01 ff 74 0f 66 3d 55 09 75 c4 83 bf f8
>> [ 4373.153332] RSP: 0018:ffffb2ef036b3dc8 EFLAGS: 00010246
>> [ 4373.153338] RAX: 000000000000001e RBX: ffff94268b006a60 RCX: 
>> 0000000080800067
>> [ 4373.153342] RDX: 0000000080800068 RSI: 0000000000000001 RDI: 
>> 0000000000000002
>> [ 4373.153347] RBP: ffffb2ef036b3de8 R08: 0000000000000000 R09: 
>> ffffffff8dc65400
>> [ 4373.153351] R10: ffff9426678d7200 R11: 0000000000000001 R12: 
>> 000000000000001e
>> [ 4373.153355] R13: ffff94268b006970 R14: 0000000000000001 R15: 
>> ffff94268b006800
>> [ 4373.153361] FS:  0000000000000000(0000) GS:ffff942691400000(0000) 
>> knlGS:0000000000000000
>> [ 4373.153366] CS:  0010 DS: 0000 ES: 0000 CR0: 0000000080050033
>> [ 4373.153371] CR2: 00000000000002f2 CR3: 00000004445a6005 CR4: 
>> 00000000003606f0
>> [ 4373.153375] Call Trace:
>> [ 4373.153389]  ucsi_unregister_partner.part.0+0x17/0x30 [typec_ucsi]
>> [ 4373.153400]  ucsi_handle_connector_change+0x25c/0x320 [typec_ucsi]
>> [ 4373.153418]  process_one_work+0x1df/0x3d0
>> [ 4373.153428]  worker_thread+0x4a/0x3d0
>> [ 4373.153436]  ? process_one_work+0x3d0/0x3d0
>> [ 4373.153444]  kthread+0x127/0x170
>> [ 4373.153451]  ? kthread_park+0x90/0x90
>> [ 4373.153461]  ret_from_fork+0x1f/0x30
>> [ 4373.153661] CR2: 00000000000002f2
>>
>> Fixes: ad74b8649beaf ("usb: typec: ucsi: Preliminary support for alternate modes")
>> Cc: stable@vger.kernel.org
>> Signed-off-by: Zwane Mwaikambo <zwane@yosper.io>
>> ---
>> v2 addresses both instances of array overrun
>> v3 addresses patch submission/formatting issues
>> v4 addresses patch submission/formatting issues
>> v5 adds and cc to stable
>>
>> diff --git a/drivers/usb/typec/ucsi/ucsi.c b/drivers/usb/typec/ucsi/ucsi.c
>> index d0c63afaf..79061705e 100644
>> --- a/drivers/usb/typec/ucsi/ucsi.c
>> +++ b/drivers/usb/typec/ucsi/ucsi.c
>> @@ -479,7 +480,10 @@ static void ucsi_unregister_altmodes(struct ucsi_connector *con, u8 recipient)
>>  		return;
>>  	}
>>  
>> -	while (adev[i]) {
>> +	for (i = 0; i < UCSI_MAX_ALTMODES; i++) {
>> +		if (!adev[i])
>> +			break;
> 
>         for (i = 0; i < UCSI_MAX_ALTMODES && adev[u]; i++) {

make that                                      adev[i]

>>  		if (recipient == UCSI_RECIPIENT_SOP &&
>>  		    (adev[i]->svid == USB_TYPEC_DP_SID ||
>>  			(adev[i]->svid == USB_TYPEC_NVIDIA_VLINK_SID &&
>> @@ -488,7 +492,7 @@ static void ucsi_unregister_altmodes(struct ucsi_connector *con, u8 recipient)
>>  			ucsi_displayport_remove_partner((void *)pdev);
>>  		}
>>  		typec_unregister_altmode(adev[i]);
>> -		adev[i++] = NULL;
>> +		adev[i] = NULL;
>>  	}
>>  }
>>  
> 
> thanks,
> 


-- 
~Randy
Reported-by: Randy Dunlap <rdunlap@infradead.org>

  reply	other threads:[~2020-09-09 17:13 UTC|newest]

Thread overview: 23+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2020-08-27 17:49 [PATCH v3 1/2] usb/typec: fix array overruns in ucsi.c partner_altmode[] Zwane Mwaikambo
2020-08-27 17:52 ` [PATCH v3 2/2] " Zwane Mwaikambo
2020-08-27 17:54 ` [PATCH v3 1/2] " Randy Dunlap
2020-08-27 18:29   ` Zwane Mwaikambo
2020-08-27 18:34     ` [PATCH v4 " Zwane Mwaikambo
2020-08-27 18:35       ` [PATCH v4 2/2] " Zwane Mwaikambo
2020-08-28 12:41         ` Heikki Krogerus
2020-08-28 12:33       ` [PATCH v4 1/2] " Heikki Krogerus
2020-08-30  9:26         ` [PATCH v5 " Zwane Mwaikambo
2020-08-30  9:28           ` [PATCH v5 2/2] " Zwane Mwaikambo
2020-09-09 12:33             ` Heikki Krogerus
2020-09-09 15:07               ` Randy Dunlap [this message]
2020-09-10  7:49                 ` Zwane Mwaikambo
2020-09-03 11:10           ` [PATCH v5 1/2] " Heikki Krogerus
2020-09-04 17:33             ` Zwane Mwaikambo
2020-09-09 13:10             ` Heikki Krogerus
2020-09-10  7:52               ` Zwane Mwaikambo
2020-09-10 12:50                 ` Heikki Krogerus
2020-09-11  2:13                   ` Zwane Mwaikambo
     [not found]                     ` <20200911135618.GA4168153@kuha.fi.intel.com>
2020-09-14 13:49                       ` Heikki Krogerus
2020-09-14 17:56                         ` Zwane Mwaikambo
2020-09-16  7:59                           ` Heikki Krogerus
2020-09-17 20:55                             ` Zwane Mwaikambo

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=6a7cd809-5309-2945-d5f9-8147101bff03@infradead.org \
    --to=rdunlap@infradead.org \
    --cc=gregkh@linuxfoundation.org \
    --cc=heikki.krogerus@linux.intel.com \
    --cc=linux-usb@vger.kernel.org \
    --cc=zwane@yosper.io \
    --cc=zwanem@gmail.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.