* [PATCH][next] extcon: usbc-cros-ec: Use struct_size() helper in kzalloc() @ 2022-01-25 19:26 ` Gustavo A. R. Silva 2022-02-16 1:26 ` Chanwoo Choi 0 siblings, 1 reply; 3+ messages in thread From: Gustavo A. R. Silva @ 2022-01-25 19:26 UTC (permalink / raw) To: MyungJoo Ham, Chanwoo Choi, Benson Leung, Guenter Roeck Cc: linux-kernel, Gustavo A. R. Silva, linux-hardening Make use of the struct_size() helper instead of an open-coded version, in order to avoid any potential type mistakes or integer overflows that, in the worst scenario, could lead to heap overflows. Also, address the following sparse warnings: drivers/extcon/extcon-usbc-cros-ec.c:71:23: warning: using sizeof on a flexible structure Link: https://github.com/KSPP/linux/issues/174 Signed-off-by: Gustavo A. R. Silva <gustavoars@kernel.org> --- drivers/extcon/extcon-usbc-cros-ec.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/drivers/extcon/extcon-usbc-cros-ec.c b/drivers/extcon/extcon-usbc-cros-ec.c index 5290cc2d19d9..fde1db62be0d 100644 --- a/drivers/extcon/extcon-usbc-cros-ec.c +++ b/drivers/extcon/extcon-usbc-cros-ec.c @@ -68,7 +68,7 @@ static int cros_ec_pd_command(struct cros_ec_extcon_info *info, struct cros_ec_command *msg; int ret; - msg = kzalloc(sizeof(*msg) + max(outsize, insize), GFP_KERNEL); + msg = kzalloc(struct_size(msg, data, max(outsize, insize)), GFP_KERNEL); if (!msg) return -ENOMEM; -- 2.27.0 ^ permalink raw reply related [flat|nested] 3+ messages in thread
* Re: [PATCH][next] extcon: usbc-cros-ec: Use struct_size() helper in kzalloc() 2022-01-25 19:26 ` [PATCH][next] extcon: usbc-cros-ec: Use struct_size() helper in kzalloc() Gustavo A. R. Silva @ 2022-02-16 1:26 ` Chanwoo Choi 2022-02-16 1:18 ` Gustavo A. R. Silva 0 siblings, 1 reply; 3+ messages in thread From: Chanwoo Choi @ 2022-02-16 1:26 UTC (permalink / raw) To: Gustavo A. R. Silva, MyungJoo Ham, Benson Leung, Guenter Roeck Cc: linux-kernel, linux-hardening On 1/26/22 4:26 AM, Gustavo A. R. Silva wrote: > Make use of the struct_size() helper instead of an open-coded version, > in order to avoid any potential type mistakes or integer overflows that, > in the worst scenario, could lead to heap overflows. > > Also, address the following sparse warnings: > drivers/extcon/extcon-usbc-cros-ec.c:71:23: warning: using sizeof on a flexible structure > > Link: https://protect2.fireeye.com/v1/url?k=2dc5c327-725efa52-2dc44868-0cc47a31ce4e-cb277ab0badba227&q=1&e=e53efbe1-ab25-4a39-a8b1-9e099fcccde3&u=https%3A%2F%2Fgithub.com%2FKSPP%2Flinux%2Fissues%2F174 > Signed-off-by: Gustavo A. R. Silva <gustavoars@kernel.org> > --- > drivers/extcon/extcon-usbc-cros-ec.c | 2 +- > 1 file changed, 1 insertion(+), 1 deletion(-) > > diff --git a/drivers/extcon/extcon-usbc-cros-ec.c b/drivers/extcon/extcon-usbc-cros-ec.c > index 5290cc2d19d9..fde1db62be0d 100644 > --- a/drivers/extcon/extcon-usbc-cros-ec.c > +++ b/drivers/extcon/extcon-usbc-cros-ec.c > @@ -68,7 +68,7 @@ static int cros_ec_pd_command(struct cros_ec_extcon_info *info, > struct cros_ec_command *msg; > int ret; > > - msg = kzalloc(sizeof(*msg) + max(outsize, insize), GFP_KERNEL); > + msg = kzalloc(struct_size(msg, data, max(outsize, insize)), GFP_KERNEL); > if (!msg) > return -ENOMEM; > > Applied it. Thanks. -- Best Regards, Chanwoo Choi Samsung Electronics ^ permalink raw reply [flat|nested] 3+ messages in thread
* Re: [PATCH][next] extcon: usbc-cros-ec: Use struct_size() helper in kzalloc() 2022-02-16 1:26 ` Chanwoo Choi @ 2022-02-16 1:18 ` Gustavo A. R. Silva 0 siblings, 0 replies; 3+ messages in thread From: Gustavo A. R. Silva @ 2022-02-16 1:18 UTC (permalink / raw) To: Chanwoo Choi Cc: MyungJoo Ham, Benson Leung, Guenter Roeck, linux-kernel, linux-hardening On Wed, Feb 16, 2022 at 10:26:34AM +0900, Chanwoo Choi wrote: > On 1/26/22 4:26 AM, Gustavo A. R. Silva wrote: > > Applied it. Thanks. Great. :) Thanks, Chanwoo. -- Gustavo ^ permalink raw reply [flat|nested] 3+ messages in thread
end of thread, other threads:[~2022-02-16 1:11 UTC | newest]
Thread overview: 3+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
[not found] <CGME20220125192140epcas1p27d09a1d2ceaed49dd7c410c0223c51d7@epcas1p2.samsung.com>
2022-01-25 19:26 ` [PATCH][next] extcon: usbc-cros-ec: Use struct_size() helper in kzalloc() Gustavo A. R. Silva
2022-02-16 1:26 ` Chanwoo Choi
2022-02-16 1:18 ` Gustavo A. R. Silva
This is a public inbox, see mirroring instructions for how to clone and mirror all data and code used for this inbox