* [PATCH] Input: cyttsp4 - Fix error on calculating memory size passed to krealloc.
@ 2017-10-31 19:19 Vince Kim
[not found] ` <CAJRpnq5CtGDHjSpa_mBqsJmZxvdrkAwPYwFk1tM20h4vvEbb4A@mail.gmail.com>
0 siblings, 1 reply; 4+ messages in thread
From: Vince Kim @ 2017-10-31 19:19 UTC (permalink / raw)
Cc: Vince Kim, Ferruh Yigit, Dmitry Torokhov, linux-input, linux-kernel
There are several places to perform subtraction to calculate buffer
size such as:
si->si_ofs.cydata_size = si->si_ofs.test_ofs - si->si_ofs.cydata_ofs;
...
p = krealloc(si->si_ptrs.cydata, si->si_ofs.cydata_size, GFP_KERNEL);
Actually, data types of above variables during subtraction are size_t, so it is
unsigned. That means if second operand(si->si_ofs.cydata_ofs) is
greater than the first operand(si->si_ofs.test_ofs), then resulting
si->si_ofs.cydata_size could result in an unsigned integer wrap which is
not desiarable.
The properway to correct this problem is to perform a test of both
operands to avoid having unsigned wrap.
---
drivers/input/touchscreen/cyttsp4_core.c | 20 ++++++++++++++++++++
1 file changed, 20 insertions(+)
diff --git a/drivers/input/touchscreen/cyttsp4_core.c b/drivers/input/touchscreen/cyttsp4_core.c
index beaf61c..eecc7f1 100644
--- a/drivers/input/touchscreen/cyttsp4_core.c
+++ b/drivers/input/touchscreen/cyttsp4_core.c
@@ -201,6 +201,11 @@ static int cyttsp4_si_get_cydata(struct cyttsp4 *cd)
void *p;
int rc;
+ if (si->si_ofs.test_ofs <= si->si_ofs.cydata_ofs)
+ dev_err(cd->dev, "%s: invalid offset test_ofs:%zd, cydata_ofs:%zd \n", __func__, si->si_ofs.test_ofs, si->si_ofs.cydata_ofs);
+ return -EINVAL;
+ }
+
si->si_ofs.cydata_size = si->si_ofs.test_ofs - si->si_ofs.cydata_ofs;
dev_dbg(cd->dev, "%s: cydata size: %zd\n", __func__,
si->si_ofs.cydata_size);
@@ -270,6 +275,11 @@ static int cyttsp4_si_get_test_data(struct cyttsp4 *cd)
void *p;
int rc;
+ if (si->si_ofs.pcfg_ofs <= si->si_ofs.test_ofs)
+ dev_err(cd->dev, "%s: invalid offset pcfg_ofs:%zd, test_ofs:%zd \n", __func__, si->si_ofs.pcfg_ofs, si->si_ofs.test_ofs);
+ return -EINVAL;
+ }
+
si->si_ofs.test_size = si->si_ofs.pcfg_ofs - si->si_ofs.test_ofs;
p = krealloc(si->si_ptrs.test, si->si_ofs.test_size, GFP_KERNEL);
@@ -321,6 +331,11 @@ static int cyttsp4_si_get_pcfg_data(struct cyttsp4 *cd)
void *p;
int rc;
+ if (si->si_ofs.opcfg_ofs <= si->si_ofs.pcfg_ofs)
+ dev_err(cd->dev, "%s: invalid offset opcfg_ofs:%zd, pcfg_ofs:%zd \n", __func__, si->si_ofs.opcfg_ofs, si->si_ofs.pcfg_ofs);
+ return -EINVAL;
+ }
+
si->si_ofs.pcfg_size = si->si_ofs.opcfg_ofs - si->si_ofs.pcfg_ofs;
p = krealloc(si->si_ptrs.pcfg, si->si_ofs.pcfg_size, GFP_KERNEL);
@@ -367,6 +382,11 @@ static int cyttsp4_si_get_opcfg_data(struct cyttsp4 *cd)
void *p;
int rc;
+ if (si->si_ofs.ddata_ofs <= si->si_ofs.opcfg_ofs)
+ dev_err(cd->dev, "%s: invalid offset ddata_ofs:%zd, opcfg_ofs:%zd \n", __func__, si->si_ofs.ddata_ofs, si->si_ofs.opcfg_ofs);
+ return -EINVAL;
+ }
+
si->si_ofs.opcfg_size = si->si_ofs.ddata_ofs - si->si_ofs.opcfg_ofs;
p = krealloc(si->si_ptrs.opcfg, si->si_ofs.opcfg_size, GFP_KERNEL);
--
2.7.4
^ permalink raw reply related [flat|nested] 4+ messages in thread
* Re: [PATCH] Input: cyttsp4 - Fix error on calculating memory size passed to krealloc.
[not found] ` <CAJRpnq5CtGDHjSpa_mBqsJmZxvdrkAwPYwFk1tM20h4vvEbb4A@mail.gmail.com>
@ 2017-11-02 23:54 ` Dmitry Torokhov
[not found] ` <CAJRpnq5CdTk0UHhyN8D-n4U3cutA11KDPYXsRQATc+BHmpzNqQ@mail.gmail.com>
0 siblings, 1 reply; 4+ messages in thread
From: Dmitry Torokhov @ 2017-11-02 23:54 UTC (permalink / raw)
To: Vince Kim; +Cc: Ferruh Yigit, linux-input, linux-kernel
Hi Vince,
On Wed, Nov 01, 2017 at 09:13:58PM -0700, Vince Kim wrote:
> It looks patch send to the maintainer rejected.
>
I can take the patch, but I need your signed-off-by please.
> Can anyone take a look?
>
>
>
> *==============================*
>
> *Delivery has failed to these recipients or groups:*
>
> Ferruh Yigit (fery@cypress.com) <fery@cypress.com>
> Your message wasn't delivered due to a permission or security issue. It may
> have been rejected by a moderator, the address may only accept e-mail from
> certain senders, or another restriction may be preventing delivery.
> *==============================*
>
> On Tue, Oct 31, 2017 at 12:19 PM, Vince Kim <vince.k.kim@gmail.com> wrote:
>
> > There are several places to perform subtraction to calculate buffer
> > size such as:
> >
> > si->si_ofs.cydata_size = si->si_ofs.test_ofs - si->si_ofs.cydata_ofs;
> > ...
> > p = krealloc(si->si_ptrs.cydata, si->si_ofs.cydata_size, GFP_KERNEL);
> >
> > Actually, data types of above variables during subtraction are size_t, so
> > it is
> > unsigned. That means if second operand(si->si_ofs.cydata_ofs) is
> > greater than the first operand(si->si_ofs.test_ofs), then resulting
> > si->si_ofs.cydata_size could result in an unsigned integer wrap which is
> > not desiarable.
> >
> > The properway to correct this problem is to perform a test of both
> > operands to avoid having unsigned wrap.
> > ---
> > drivers/input/touchscreen/cyttsp4_core.c | 20 ++++++++++++++++++++
> > 1 file changed, 20 insertions(+)
> >
> > diff --git a/drivers/input/touchscreen/cyttsp4_core.c
> > b/drivers/input/touchscreen/cyttsp4_core.c
> > index beaf61c..eecc7f1 100644
> > --- a/drivers/input/touchscreen/cyttsp4_core.c
> > +++ b/drivers/input/touchscreen/cyttsp4_core.c
> > @@ -201,6 +201,11 @@ static int cyttsp4_si_get_cydata(struct cyttsp4 *cd)
> > void *p;
> > int rc;
> >
> > + if (si->si_ofs.test_ofs <= si->si_ofs.cydata_ofs)
> > + dev_err(cd->dev, "%s: invalid offset test_ofs:%zd,
> > cydata_ofs:%zd \n", __func__, si->si_ofs.test_ofs, si->si_ofs.cydata_ofs);
> > + return -EINVAL;
> > + }
> > +
> > si->si_ofs.cydata_size = si->si_ofs.test_ofs -
> > si->si_ofs.cydata_ofs;
> > dev_dbg(cd->dev, "%s: cydata size: %zd\n", __func__,
> > si->si_ofs.cydata_size);
> > @@ -270,6 +275,11 @@ static int cyttsp4_si_get_test_data(struct cyttsp4
> > *cd)
> > void *p;
> > int rc;
> >
> > + if (si->si_ofs.pcfg_ofs <= si->si_ofs.test_ofs)
> > + dev_err(cd->dev, "%s: invalid offset pcfg_ofs:%zd,
> > test_ofs:%zd \n", __func__, si->si_ofs.pcfg_ofs, si->si_ofs.test_ofs);
> > + return -EINVAL;
> > + }
> > +
> > si->si_ofs.test_size = si->si_ofs.pcfg_ofs - si->si_ofs.test_ofs;
> >
> > p = krealloc(si->si_ptrs.test, si->si_ofs.test_size, GFP_KERNEL);
> > @@ -321,6 +331,11 @@ static int cyttsp4_si_get_pcfg_data(struct cyttsp4
> > *cd)
> > void *p;
> > int rc;
> >
> > + if (si->si_ofs.opcfg_ofs <= si->si_ofs.pcfg_ofs)
> > + dev_err(cd->dev, "%s: invalid offset opcfg_ofs:%zd,
> > pcfg_ofs:%zd \n", __func__, si->si_ofs.opcfg_ofs, si->si_ofs.pcfg_ofs);
> > + return -EINVAL;
> > + }
> > +
> > si->si_ofs.pcfg_size = si->si_ofs.opcfg_ofs - si->si_ofs.pcfg_ofs;
> >
> > p = krealloc(si->si_ptrs.pcfg, si->si_ofs.pcfg_size, GFP_KERNEL);
> > @@ -367,6 +382,11 @@ static int cyttsp4_si_get_opcfg_data(struct cyttsp4
> > *cd)
> > void *p;
> > int rc;
> >
> > + if (si->si_ofs.ddata_ofs <= si->si_ofs.opcfg_ofs)
> > + dev_err(cd->dev, "%s: invalid offset ddata_ofs:%zd,
> > opcfg_ofs:%zd \n", __func__, si->si_ofs.ddata_ofs, si->si_ofs.opcfg_ofs);
> > + return -EINVAL;
> > + }
> > +
> > si->si_ofs.opcfg_size = si->si_ofs.ddata_ofs -
> > si->si_ofs.opcfg_ofs;
> >
> > p = krealloc(si->si_ptrs.opcfg, si->si_ofs.opcfg_size, GFP_KERNEL);
> > --
> > 2.7.4
> >
> >
--
Dmitry
^ permalink raw reply [flat|nested] 4+ messages in thread
* Re: [PATCH] Input: cyttsp4 - Fix error on calculating memory size passed to krealloc.
[not found] ` <CAJRpnq5CdTk0UHhyN8D-n4U3cutA11KDPYXsRQATc+BHmpzNqQ@mail.gmail.com>
@ 2017-11-03 19:09 ` Dmitry Torokhov
2017-11-03 21:34 ` [PATCH v2] " Vince Kim
0 siblings, 1 reply; 4+ messages in thread
From: Dmitry Torokhov @ 2017-11-03 19:09 UTC (permalink / raw)
To: Vince Kim; +Cc: Ferruh Yigit, linux-input, linux-kernel
On Thu, Nov 02, 2017 at 08:49:35PM -0700, Vince Kim wrote:
> Hello Dmitry,
>
> I attached patch with signed-off-by.
*sigh* did you try compile that?
+ if (si->si_ofs.test_ofs <= si->si_ofs.cydata_ofs)
+ dev_err(cd->dev, "%s: invalid offset test_ofs:%zd, cydata_ofs:%zd \n", __func__, si->si_ofs.test_ofs, si->si_ofs.cydata_ofs);
+ return -EINVAL;
+ }
+
There is an opening curly brace missing. Same goes for the other 3
chunks of the patch. I fixed it up.
> If you need a patch inline, please let me know.
The inline patch formatted according to Documentation/SubmittingPatches
is preferred, but I'd settle on something that compiles.
Thanks.
>
> Thanks,
> Vince
>
>
>
>
> On Thu, Nov 2, 2017 at 4:54 PM, Dmitry Torokhov <dmitry.torokhov@gmail.com>
> wrote:
>
> > Hi Vince,
> >
> > On Wed, Nov 01, 2017 at 09:13:58PM -0700, Vince Kim wrote:
> > > It looks patch send to the maintainer rejected.
> > >
> >
> > I can take the patch, but I need your signed-off-by please.
> >
> > > Can anyone take a look?
> > >
> > >
> > >
> > > *==============================*
> > >
> > > *Delivery has failed to these recipients or groups:*
> > >
> > > Ferruh Yigit (fery@cypress.com) <fery@cypress.com>
> > > Your message wasn't delivered due to a permission or security issue. It
> > may
> > > have been rejected by a moderator, the address may only accept e-mail
> > from
> > > certain senders, or another restriction may be preventing delivery.
> > > *==============================*
> > >
> > > On Tue, Oct 31, 2017 at 12:19 PM, Vince Kim <vince.k.kim@gmail.com>
> > wrote:
> > >
> > > > There are several places to perform subtraction to calculate buffer
> > > > size such as:
> > > >
> > > > si->si_ofs.cydata_size = si->si_ofs.test_ofs - si->si_ofs.cydata_ofs;
> > > > ...
> > > > p = krealloc(si->si_ptrs.cydata, si->si_ofs.cydata_size, GFP_KERNEL);
> > > >
> > > > Actually, data types of above variables during subtraction are size_t,
> > so
> > > > it is
> > > > unsigned. That means if second operand(si->si_ofs.cydata_ofs) is
> > > > greater than the first operand(si->si_ofs.test_ofs), then resulting
> > > > si->si_ofs.cydata_size could result in an unsigned integer wrap which
> > is
> > > > not desiarable.
> > > >
> > > > The properway to correct this problem is to perform a test of both
> > > > operands to avoid having unsigned wrap.
> > > > ---
> > > > drivers/input/touchscreen/cyttsp4_core.c | 20 ++++++++++++++++++++
> > > > 1 file changed, 20 insertions(+)
> > > >
> > > > diff --git a/drivers/input/touchscreen/cyttsp4_core.c
> > > > b/drivers/input/touchscreen/cyttsp4_core.c
> > > > index beaf61c..eecc7f1 100644
> > > > --- a/drivers/input/touchscreen/cyttsp4_core.c
> > > > +++ b/drivers/input/touchscreen/cyttsp4_core.c
> > > > @@ -201,6 +201,11 @@ static int cyttsp4_si_get_cydata(struct cyttsp4
> > *cd)
> > > > void *p;
> > > > int rc;
> > > >
> > > > + if (si->si_ofs.test_ofs <= si->si_ofs.cydata_ofs)
> > > > + dev_err(cd->dev, "%s: invalid offset test_ofs:%zd,
> > > > cydata_ofs:%zd \n", __func__, si->si_ofs.test_ofs,
> > si->si_ofs.cydata_ofs);
> > > > + return -EINVAL;
> > > > + }
> > > > +
> > > > si->si_ofs.cydata_size = si->si_ofs.test_ofs -
> > > > si->si_ofs.cydata_ofs;
> > > > dev_dbg(cd->dev, "%s: cydata size: %zd\n", __func__,
> > > > si->si_ofs.cydata_size);
> > > > @@ -270,6 +275,11 @@ static int cyttsp4_si_get_test_data(struct
> > cyttsp4
> > > > *cd)
> > > > void *p;
> > > > int rc;
> > > >
> > > > + if (si->si_ofs.pcfg_ofs <= si->si_ofs.test_ofs)
> > > > + dev_err(cd->dev, "%s: invalid offset pcfg_ofs:%zd,
> > > > test_ofs:%zd \n", __func__, si->si_ofs.pcfg_ofs, si->si_ofs.test_ofs);
> > > > + return -EINVAL;
> > > > + }
> > > > +
> > > > si->si_ofs.test_size = si->si_ofs.pcfg_ofs -
> > si->si_ofs.test_ofs;
> > > >
> > > > p = krealloc(si->si_ptrs.test, si->si_ofs.test_size,
> > GFP_KERNEL);
> > > > @@ -321,6 +331,11 @@ static int cyttsp4_si_get_pcfg_data(struct
> > cyttsp4
> > > > *cd)
> > > > void *p;
> > > > int rc;
> > > >
> > > > + if (si->si_ofs.opcfg_ofs <= si->si_ofs.pcfg_ofs)
> > > > + dev_err(cd->dev, "%s: invalid offset opcfg_ofs:%zd,
> > > > pcfg_ofs:%zd \n", __func__, si->si_ofs.opcfg_ofs, si->si_ofs.pcfg_ofs);
> > > > + return -EINVAL;
> > > > + }
> > > > +
> > > > si->si_ofs.pcfg_size = si->si_ofs.opcfg_ofs -
> > si->si_ofs.pcfg_ofs;
> > > >
> > > > p = krealloc(si->si_ptrs.pcfg, si->si_ofs.pcfg_size,
> > GFP_KERNEL);
> > > > @@ -367,6 +382,11 @@ static int cyttsp4_si_get_opcfg_data(struct
> > cyttsp4
> > > > *cd)
> > > > void *p;
> > > > int rc;
> > > >
> > > > + if (si->si_ofs.ddata_ofs <= si->si_ofs.opcfg_ofs)
> > > > + dev_err(cd->dev, "%s: invalid offset ddata_ofs:%zd,
> > > > opcfg_ofs:%zd \n", __func__, si->si_ofs.ddata_ofs,
> > si->si_ofs.opcfg_ofs);
> > > > + return -EINVAL;
> > > > + }
> > > > +
> > > > si->si_ofs.opcfg_size = si->si_ofs.ddata_ofs -
> > > > si->si_ofs.opcfg_ofs;
> > > >
> > > > p = krealloc(si->si_ptrs.opcfg, si->si_ofs.opcfg_size,
> > GFP_KERNEL);
> > > > --
> > > > 2.7.4
> > > >
> > > >
> >
> > --
> > Dmitry
> >
--
Dmitry
^ permalink raw reply [flat|nested] 4+ messages in thread
* [PATCH v2] Input: cyttsp4 - Fix error on calculating memory size passed to krealloc.
2017-11-03 19:09 ` Dmitry Torokhov
@ 2017-11-03 21:34 ` Vince Kim
0 siblings, 0 replies; 4+ messages in thread
From: Vince Kim @ 2017-11-03 21:34 UTC (permalink / raw)
Cc: Vince Kim, Ferruh Yigit, Dmitry Torokhov, linux-input, linux-kernel
There are several places to perform subtraction to calculate buffer
size such as:
si->si_ofs.cydata_size = si->si_ofs.test_ofs - si->si_ofs.cydata_ofs;
...
p = krealloc(si->si_ptrs.cydata, si->si_ofs.cydata_size, GFP_KERNEL);
Actually, data types of above variables during subtraction are size_t, so it is
unsigned. That means if second operand(si->si_ofs.cydata_ofs) is
greater than the first operand(si->si_ofs.test_ofs), then resulting
si->si_ofs.cydata_size could result in an unsigned integer wrap which is
not desiarable.
The properway to correct this problem is to perform a test of both
operands to avoid having unsigned wrap.
Signed-off-by: Vince Kim <vince.k.kim@gmail.com>
---
Cahnges in v2:
- added missing opening curly brace at if statement
drivers/input/touchscreen/cyttsp4_core.c | 20 ++++++++++++++++++++
1 file changed, 20 insertions(+)
diff --git a/drivers/input/touchscreen/cyttsp4_core.c b/drivers/input/touchscreen/cyttsp4_core.c
index beaf61c..e4a3743 100644
--- a/drivers/input/touchscreen/cyttsp4_core.c
+++ b/drivers/input/touchscreen/cyttsp4_core.c
@@ -201,6 +201,11 @@ static int cyttsp4_si_get_cydata(struct cyttsp4 *cd)
void *p;
int rc;
+ if (si->si_ofs.test_ofs <= si->si_ofs.cydata_ofs) {
+ dev_err(cd->dev, "%s: invalid offset test_ofs:%zd, cydata_ofs:%zd \n", __func__, si->si_ofs.test_ofs, si->si_ofs.cydata_ofs);
+ return -EINVAL;
+ }
+
si->si_ofs.cydata_size = si->si_ofs.test_ofs - si->si_ofs.cydata_ofs;
dev_dbg(cd->dev, "%s: cydata size: %zd\n", __func__,
si->si_ofs.cydata_size);
@@ -270,6 +275,11 @@ static int cyttsp4_si_get_test_data(struct cyttsp4 *cd)
void *p;
int rc;
+ if (si->si_ofs.pcfg_ofs <= si->si_ofs.test_ofs) {
+ dev_err(cd->dev, "%s: invalid offset pcfg_ofs:%zd, test_ofs:%zd \n", __func__, si->si_ofs.pcfg_ofs, si->si_ofs.test_ofs);
+ return -EINVAL;
+ }
+
si->si_ofs.test_size = si->si_ofs.pcfg_ofs - si->si_ofs.test_ofs;
p = krealloc(si->si_ptrs.test, si->si_ofs.test_size, GFP_KERNEL);
@@ -321,6 +331,11 @@ static int cyttsp4_si_get_pcfg_data(struct cyttsp4 *cd)
void *p;
int rc;
+ if (si->si_ofs.opcfg_ofs <= si->si_ofs.pcfg_ofs) {
+ dev_err(cd->dev, "%s: invalid offset opcfg_ofs:%zd, pcfg_ofs:%zd \n", __func__, si->si_ofs.opcfg_ofs, si->si_ofs.pcfg_ofs);
+ return -EINVAL;
+ }
+
si->si_ofs.pcfg_size = si->si_ofs.opcfg_ofs - si->si_ofs.pcfg_ofs;
p = krealloc(si->si_ptrs.pcfg, si->si_ofs.pcfg_size, GFP_KERNEL);
@@ -367,6 +382,11 @@ static int cyttsp4_si_get_opcfg_data(struct cyttsp4 *cd)
void *p;
int rc;
+ if (si->si_ofs.ddata_ofs <= si->si_ofs.opcfg_ofs) {
+ dev_err(cd->dev, "%s: invalid offset ddata_ofs:%zd, opcfg_ofs:%zd \n", __func__, si->si_ofs.ddata_ofs, si->si_ofs.opcfg_ofs);
+ return -EINVAL;
+ }
+
si->si_ofs.opcfg_size = si->si_ofs.ddata_ofs - si->si_ofs.opcfg_ofs;
p = krealloc(si->si_ptrs.opcfg, si->si_ofs.opcfg_size, GFP_KERNEL);
--
2.7.4
^ permalink raw reply related [flat|nested] 4+ messages in thread
end of thread, other threads:[~2017-11-03 21:34 UTC | newest]
Thread overview: 4+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2017-10-31 19:19 [PATCH] Input: cyttsp4 - Fix error on calculating memory size passed to krealloc Vince Kim
[not found] ` <CAJRpnq5CtGDHjSpa_mBqsJmZxvdrkAwPYwFk1tM20h4vvEbb4A@mail.gmail.com>
2017-11-02 23:54 ` Dmitry Torokhov
[not found] ` <CAJRpnq5CdTk0UHhyN8D-n4U3cutA11KDPYXsRQATc+BHmpzNqQ@mail.gmail.com>
2017-11-03 19:09 ` Dmitry Torokhov
2017-11-03 21:34 ` [PATCH v2] " Vince Kim
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).