* Re: [PATCH] drm: amdgpu: Use the correct size when allocating memory
@ 2020-08-10 18:41 ` Marion & Christophe JAILLET
0 siblings, 0 replies; 28+ messages in thread
From: Marion & Christophe JAILLET @ 2020-08-10 18:41 UTC (permalink / raw)
To: Dan Carpenter
Cc: alexander.deucher, christian.koenig, airlied, daniel,
sumit.semwal, colton.w.lewis, Ori.Messinger, m.szyprowski,
bernard, dri-devel, amd-gfx, linux-kernel, kernel-janitors
Le 10/08/2020 à 17:42, Dan Carpenter a écrit :
> On Sun, Aug 09, 2020 at 10:34:06PM +0200, Christophe JAILLET wrote:
>> When '*sgt' is allocated, we must allocated 'sizeof(**sgt)' bytes instead
>> of 'sizeof(*sg)'. 'sg' (i.e. struct scatterlist) is smaller than
>> 'sgt' (i.e struct sg_table), so this could lead to memory corruption.
> The sizeof(*sg) is bigger than sizeof(**sgt) so this wastes memory but
> it won't lead to corruption.
>
> 11 struct scatterlist {
> 12 unsigned long page_link;
> 13 unsigned int offset;
> 14 unsigned int length;
> 15 dma_addr_t dma_address;
> 16 #ifdef CONFIG_NEED_SG_DMA_LENGTH
> 17 unsigned int dma_length;
> 18 #endif
> 19 };
>
> 42 struct sg_table {
> 43 struct scatterlist *sgl; /* the list */
> 44 unsigned int nents; /* number of mapped entries */
> 45 unsigned int orig_nents; /* original size of list */
> 46 };
>
> regards,
> dan carpenter
My bad. I read 'struct scatterlist sgl' (without the *)
Thanks for the follow-up, Dan.
Doesn't smatch catch such mismatch?
(I've not run smatch for a while, so it is maybe reported)
Well, the proposal is still valid, even if it has less impact as
initially thought.
Thx for the review.
CJ
^ permalink raw reply [flat|nested] 28+ messages in thread* Re: [PATCH] drm: amdgpu: Use the correct size when allocating memory
@ 2020-08-10 18:41 ` Marion & Christophe JAILLET
0 siblings, 0 replies; 28+ messages in thread
From: Marion & Christophe JAILLET @ 2020-08-10 18:41 UTC (permalink / raw)
To: Dan Carpenter
Cc: Ori.Messinger, airlied, bernard, kernel-janitors, linux-kernel,
dri-devel, colton.w.lewis, amd-gfx, alexander.deucher,
christian.koenig, m.szyprowski
Le 10/08/2020 à 17:42, Dan Carpenter a écrit :
> On Sun, Aug 09, 2020 at 10:34:06PM +0200, Christophe JAILLET wrote:
>> When '*sgt' is allocated, we must allocated 'sizeof(**sgt)' bytes instead
>> of 'sizeof(*sg)'. 'sg' (i.e. struct scatterlist) is smaller than
>> 'sgt' (i.e struct sg_table), so this could lead to memory corruption.
> The sizeof(*sg) is bigger than sizeof(**sgt) so this wastes memory but
> it won't lead to corruption.
>
> 11 struct scatterlist {
> 12 unsigned long page_link;
> 13 unsigned int offset;
> 14 unsigned int length;
> 15 dma_addr_t dma_address;
> 16 #ifdef CONFIG_NEED_SG_DMA_LENGTH
> 17 unsigned int dma_length;
> 18 #endif
> 19 };
>
> 42 struct sg_table {
> 43 struct scatterlist *sgl; /* the list */
> 44 unsigned int nents; /* number of mapped entries */
> 45 unsigned int orig_nents; /* original size of list */
> 46 };
>
> regards,
> dan carpenter
My bad. I read 'struct scatterlist sgl' (without the *)
Thanks for the follow-up, Dan.
Doesn't smatch catch such mismatch?
(I've not run smatch for a while, so it is maybe reported)
Well, the proposal is still valid, even if it has less impact as
initially thought.
Thx for the review.
CJ
_______________________________________________
dri-devel mailing list
dri-devel@lists.freedesktop.org
https://lists.freedesktop.org/mailman/listinfo/dri-devel
^ permalink raw reply [flat|nested] 28+ messages in thread* Re: [PATCH] drm: amdgpu: Use the correct size when allocating memory
@ 2020-08-10 18:41 ` Marion & Christophe JAILLET
0 siblings, 0 replies; 28+ messages in thread
From: Marion & Christophe JAILLET @ 2020-08-10 18:41 UTC (permalink / raw)
To: Dan Carpenter
Cc: Ori.Messinger, airlied, bernard, kernel-janitors, linux-kernel,
dri-devel, sumit.semwal, colton.w.lewis, amd-gfx, daniel,
alexander.deucher, christian.koenig, m.szyprowski
Le 10/08/2020 à 17:42, Dan Carpenter a écrit :
> On Sun, Aug 09, 2020 at 10:34:06PM +0200, Christophe JAILLET wrote:
>> When '*sgt' is allocated, we must allocated 'sizeof(**sgt)' bytes instead
>> of 'sizeof(*sg)'. 'sg' (i.e. struct scatterlist) is smaller than
>> 'sgt' (i.e struct sg_table), so this could lead to memory corruption.
> The sizeof(*sg) is bigger than sizeof(**sgt) so this wastes memory but
> it won't lead to corruption.
>
> 11 struct scatterlist {
> 12 unsigned long page_link;
> 13 unsigned int offset;
> 14 unsigned int length;
> 15 dma_addr_t dma_address;
> 16 #ifdef CONFIG_NEED_SG_DMA_LENGTH
> 17 unsigned int dma_length;
> 18 #endif
> 19 };
>
> 42 struct sg_table {
> 43 struct scatterlist *sgl; /* the list */
> 44 unsigned int nents; /* number of mapped entries */
> 45 unsigned int orig_nents; /* original size of list */
> 46 };
>
> regards,
> dan carpenter
My bad. I read 'struct scatterlist sgl' (without the *)
Thanks for the follow-up, Dan.
Doesn't smatch catch such mismatch?
(I've not run smatch for a while, so it is maybe reported)
Well, the proposal is still valid, even if it has less impact as
initially thought.
Thx for the review.
CJ
^ permalink raw reply [flat|nested] 28+ messages in thread* Re: [PATCH] drm: amdgpu: Use the correct size when allocating memory
2020-08-10 18:41 ` Marion & Christophe JAILLET
(?)
(?)
@ 2020-08-10 21:15 ` Alex Deucher
-1 siblings, 0 replies; 28+ messages in thread
From: Alex Deucher @ 2020-08-10 21:15 UTC (permalink / raw)
To: Marion & Christophe JAILLET
Cc: Messinger, Ori, Dave Airlie, Bernard Zhao, kernel-janitors, LKML,
Maling list - DRI developers, Christian Koenig, Colton Lewis,
amd-gfx list, Daniel Vetter, Deucher, Alexander, Sumit Semwal,
Dan Carpenter, Marek Szyprowski
Applied and updated the commit message to reflect the sizes.
Thanks!
Alex
On Mon, Aug 10, 2020 at 3:07 PM Marion & Christophe JAILLET
<christophe.jaillet@wanadoo.fr> wrote:
>
>
> Le 10/08/2020 à 17:42, Dan Carpenter a écrit :
> > On Sun, Aug 09, 2020 at 10:34:06PM +0200, Christophe JAILLET wrote:
> >> When '*sgt' is allocated, we must allocated 'sizeof(**sgt)' bytes instead
> >> of 'sizeof(*sg)'. 'sg' (i.e. struct scatterlist) is smaller than
> >> 'sgt' (i.e struct sg_table), so this could lead to memory corruption.
> > The sizeof(*sg) is bigger than sizeof(**sgt) so this wastes memory but
> > it won't lead to corruption.
> >
> > 11 struct scatterlist {
> > 12 unsigned long page_link;
> > 13 unsigned int offset;
> > 14 unsigned int length;
> > 15 dma_addr_t dma_address;
> > 16 #ifdef CONFIG_NEED_SG_DMA_LENGTH
> > 17 unsigned int dma_length;
> > 18 #endif
> > 19 };
> >
> > 42 struct sg_table {
> > 43 struct scatterlist *sgl; /* the list */
> > 44 unsigned int nents; /* number of mapped entries */
> > 45 unsigned int orig_nents; /* original size of list */
> > 46 };
> >
> > regards,
> > dan carpenter
>
>
> My bad. I read 'struct scatterlist sgl' (without the *)
> Thanks for the follow-up, Dan.
>
> Doesn't smatch catch such mismatch?
> (I've not run smatch for a while, so it is maybe reported)
>
> Well, the proposal is still valid, even if it has less impact as
> initially thought.
>
> Thx for the review.
>
> CJ
>
> _______________________________________________
> amd-gfx mailing list
> amd-gfx@lists.freedesktop.org
> https://lists.freedesktop.org/mailman/listinfo/amd-gfx
_______________________________________________
amd-gfx mailing list
amd-gfx@lists.freedesktop.org
https://lists.freedesktop.org/mailman/listinfo/amd-gfx
^ permalink raw reply [flat|nested] 28+ messages in thread* Re: [PATCH] drm: amdgpu: Use the correct size when allocating memory
@ 2020-08-10 21:15 ` Alex Deucher
0 siblings, 0 replies; 28+ messages in thread
From: Alex Deucher @ 2020-08-10 21:15 UTC (permalink / raw)
To: Marion & Christophe JAILLET
Cc: Dan Carpenter, Messinger, Ori, Dave Airlie, Bernard Zhao,
kernel-janitors, LKML, Maling list - DRI developers, Sumit Semwal,
Colton Lewis, amd-gfx list, Daniel Vetter, Deucher, Alexander,
Christian Koenig, Marek Szyprowski
Applied and updated the commit message to reflect the sizes.
Thanks!
Alex
On Mon, Aug 10, 2020 at 3:07 PM Marion & Christophe JAILLET
<christophe.jaillet@wanadoo.fr> wrote:
>
>
> Le 10/08/2020 à 17:42, Dan Carpenter a écrit :
> > On Sun, Aug 09, 2020 at 10:34:06PM +0200, Christophe JAILLET wrote:
> >> When '*sgt' is allocated, we must allocated 'sizeof(**sgt)' bytes instead
> >> of 'sizeof(*sg)'. 'sg' (i.e. struct scatterlist) is smaller than
> >> 'sgt' (i.e struct sg_table), so this could lead to memory corruption.
> > The sizeof(*sg) is bigger than sizeof(**sgt) so this wastes memory but
> > it won't lead to corruption.
> >
> > 11 struct scatterlist {
> > 12 unsigned long page_link;
> > 13 unsigned int offset;
> > 14 unsigned int length;
> > 15 dma_addr_t dma_address;
> > 16 #ifdef CONFIG_NEED_SG_DMA_LENGTH
> > 17 unsigned int dma_length;
> > 18 #endif
> > 19 };
> >
> > 42 struct sg_table {
> > 43 struct scatterlist *sgl; /* the list */
> > 44 unsigned int nents; /* number of mapped entries */
> > 45 unsigned int orig_nents; /* original size of list */
> > 46 };
> >
> > regards,
> > dan carpenter
>
>
> My bad. I read 'struct scatterlist sgl' (without the *)
> Thanks for the follow-up, Dan.
>
> Doesn't smatch catch such mismatch?
> (I've not run smatch for a while, so it is maybe reported)
>
> Well, the proposal is still valid, even if it has less impact as
> initially thought.
>
> Thx for the review.
>
> CJ
>
> _______________________________________________
> amd-gfx mailing list
> amd-gfx@lists.freedesktop.org
> https://lists.freedesktop.org/mailman/listinfo/amd-gfx
^ permalink raw reply [flat|nested] 28+ messages in thread* Re: [PATCH] drm: amdgpu: Use the correct size when allocating memory
@ 2020-08-10 21:15 ` Alex Deucher
0 siblings, 0 replies; 28+ messages in thread
From: Alex Deucher @ 2020-08-10 21:15 UTC (permalink / raw)
To: Marion & Christophe JAILLET
Cc: Messinger, Ori, Dave Airlie, Bernard Zhao, kernel-janitors, LKML,
Maling list - DRI developers, Christian Koenig, Colton Lewis,
amd-gfx list, Deucher, Alexander, Dan Carpenter, Marek Szyprowski
Applied and updated the commit message to reflect the sizes.
Thanks!
Alex
On Mon, Aug 10, 2020 at 3:07 PM Marion & Christophe JAILLET
<christophe.jaillet@wanadoo.fr> wrote:
>
>
> Le 10/08/2020 à 17:42, Dan Carpenter a écrit :
> > On Sun, Aug 09, 2020 at 10:34:06PM +0200, Christophe JAILLET wrote:
> >> When '*sgt' is allocated, we must allocated 'sizeof(**sgt)' bytes instead
> >> of 'sizeof(*sg)'. 'sg' (i.e. struct scatterlist) is smaller than
> >> 'sgt' (i.e struct sg_table), so this could lead to memory corruption.
> > The sizeof(*sg) is bigger than sizeof(**sgt) so this wastes memory but
> > it won't lead to corruption.
> >
> > 11 struct scatterlist {
> > 12 unsigned long page_link;
> > 13 unsigned int offset;
> > 14 unsigned int length;
> > 15 dma_addr_t dma_address;
> > 16 #ifdef CONFIG_NEED_SG_DMA_LENGTH
> > 17 unsigned int dma_length;
> > 18 #endif
> > 19 };
> >
> > 42 struct sg_table {
> > 43 struct scatterlist *sgl; /* the list */
> > 44 unsigned int nents; /* number of mapped entries */
> > 45 unsigned int orig_nents; /* original size of list */
> > 46 };
> >
> > regards,
> > dan carpenter
>
>
> My bad. I read 'struct scatterlist sgl' (without the *)
> Thanks for the follow-up, Dan.
>
> Doesn't smatch catch such mismatch?
> (I've not run smatch for a while, so it is maybe reported)
>
> Well, the proposal is still valid, even if it has less impact as
> initially thought.
>
> Thx for the review.
>
> CJ
>
> _______________________________________________
> amd-gfx mailing list
> amd-gfx@lists.freedesktop.org
> https://lists.freedesktop.org/mailman/listinfo/amd-gfx
_______________________________________________
dri-devel mailing list
dri-devel@lists.freedesktop.org
https://lists.freedesktop.org/mailman/listinfo/dri-devel
^ permalink raw reply [flat|nested] 28+ messages in thread* Re: [PATCH] drm: amdgpu: Use the correct size when allocating memory
@ 2020-08-10 21:15 ` Alex Deucher
0 siblings, 0 replies; 28+ messages in thread
From: Alex Deucher @ 2020-08-10 21:15 UTC (permalink / raw)
To: Marion & Christophe JAILLET
Cc: Messinger, Ori, Dave Airlie, Bernard Zhao, kernel-janitors, LKML,
Maling list - DRI developers, Christian Koenig, Colton Lewis,
amd-gfx list, Daniel Vetter, Deucher, Alexander, Sumit Semwal,
Dan Carpenter, Marek Szyprowski
Applied and updated the commit message to reflect the sizes.
Thanks!
Alex
On Mon, Aug 10, 2020 at 3:07 PM Marion & Christophe JAILLET
<christophe.jaillet@wanadoo.fr> wrote:
>
>
> Le 10/08/2020 à 17:42, Dan Carpenter a écrit :
> > On Sun, Aug 09, 2020 at 10:34:06PM +0200, Christophe JAILLET wrote:
> >> When '*sgt' is allocated, we must allocated 'sizeof(**sgt)' bytes instead
> >> of 'sizeof(*sg)'. 'sg' (i.e. struct scatterlist) is smaller than
> >> 'sgt' (i.e struct sg_table), so this could lead to memory corruption.
> > The sizeof(*sg) is bigger than sizeof(**sgt) so this wastes memory but
> > it won't lead to corruption.
> >
> > 11 struct scatterlist {
> > 12 unsigned long page_link;
> > 13 unsigned int offset;
> > 14 unsigned int length;
> > 15 dma_addr_t dma_address;
> > 16 #ifdef CONFIG_NEED_SG_DMA_LENGTH
> > 17 unsigned int dma_length;
> > 18 #endif
> > 19 };
> >
> > 42 struct sg_table {
> > 43 struct scatterlist *sgl; /* the list */
> > 44 unsigned int nents; /* number of mapped entries */
> > 45 unsigned int orig_nents; /* original size of list */
> > 46 };
> >
> > regards,
> > dan carpenter
>
>
> My bad. I read 'struct scatterlist sgl' (without the *)
> Thanks for the follow-up, Dan.
>
> Doesn't smatch catch such mismatch?
> (I've not run smatch for a while, so it is maybe reported)
>
> Well, the proposal is still valid, even if it has less impact as
> initially thought.
>
> Thx for the review.
>
> CJ
>
> _______________________________________________
> amd-gfx mailing list
> amd-gfx@lists.freedesktop.org
> https://lists.freedesktop.org/mailman/listinfo/amd-gfx
^ permalink raw reply [flat|nested] 28+ messages in thread
* Re: [PATCH] drm: amdgpu: Use the correct size when allocating memory
2020-08-10 18:41 ` Marion & Christophe JAILLET
(?)
(?)
@ 2020-08-11 7:57 ` Dan Carpenter
-1 siblings, 0 replies; 28+ messages in thread
From: Dan Carpenter @ 2020-08-11 7:57 UTC (permalink / raw)
To: Marion & Christophe JAILLET
Cc: Ori.Messinger, airlied, bernard, kernel-janitors, linux-kernel,
dri-devel, sumit.semwal, colton.w.lewis, amd-gfx, daniel,
alexander.deucher, christian.koenig, m.szyprowski
On Mon, Aug 10, 2020 at 08:41:14PM +0200, Marion & Christophe JAILLET wrote:
>
> Le 10/08/2020 à 17:42, Dan Carpenter a écrit :
> > On Sun, Aug 09, 2020 at 10:34:06PM +0200, Christophe JAILLET wrote:
> > > When '*sgt' is allocated, we must allocated 'sizeof(**sgt)' bytes instead
> > > of 'sizeof(*sg)'. 'sg' (i.e. struct scatterlist) is smaller than
> > > 'sgt' (i.e struct sg_table), so this could lead to memory corruption.
> > The sizeof(*sg) is bigger than sizeof(**sgt) so this wastes memory but
> > it won't lead to corruption.
> >
> > 11 struct scatterlist {
> > 12 unsigned long page_link;
> > 13 unsigned int offset;
> > 14 unsigned int length;
> > 15 dma_addr_t dma_address;
> > 16 #ifdef CONFIG_NEED_SG_DMA_LENGTH
> > 17 unsigned int dma_length;
> > 18 #endif
> > 19 };
> >
> > 42 struct sg_table {
> > 43 struct scatterlist *sgl; /* the list */
> > 44 unsigned int nents; /* number of mapped entries */
> > 45 unsigned int orig_nents; /* original size of list */
> > 46 };
> >
> > regards,
> > dan carpenter
>
>
> My bad. I read 'struct scatterlist sgl' (without the *)
> Thanks for the follow-up, Dan.
>
> Doesn't smatch catch such mismatch?
> (I've not run smatch for a while, so it is maybe reported)
That's why I was investigating it, because Smatch didn't catch it.
Smatch would have warned if it led to memory corruption. Smatch also
tries to detect struct mismatches as a separate check but for some
reason it missed it. I'm not totally sure why yet. I suspect that it's
a complicated internal reason where Sparse is the sizeof to a normal
number... It's a known issue and hard to fix.
>
> Well, the proposal is still valid, even if it has less impact as initially
> thought.
Yep.
regards,
dan carpenter
_______________________________________________
amd-gfx mailing list
amd-gfx@lists.freedesktop.org
https://lists.freedesktop.org/mailman/listinfo/amd-gfx
^ permalink raw reply [flat|nested] 28+ messages in thread* Re: [PATCH] drm: amdgpu: Use the correct size when allocating memory
@ 2020-08-11 7:57 ` Dan Carpenter
0 siblings, 0 replies; 28+ messages in thread
From: Dan Carpenter @ 2020-08-11 7:57 UTC (permalink / raw)
To: Marion & Christophe JAILLET
Cc: alexander.deucher, christian.koenig, airlied, daniel,
sumit.semwal, colton.w.lewis, Ori.Messinger, m.szyprowski,
bernard, dri-devel, amd-gfx, linux-kernel, kernel-janitors
On Mon, Aug 10, 2020 at 08:41:14PM +0200, Marion & Christophe JAILLET wrote:
>
> Le 10/08/2020 à 17:42, Dan Carpenter a écrit :
> > On Sun, Aug 09, 2020 at 10:34:06PM +0200, Christophe JAILLET wrote:
> > > When '*sgt' is allocated, we must allocated 'sizeof(**sgt)' bytes instead
> > > of 'sizeof(*sg)'. 'sg' (i.e. struct scatterlist) is smaller than
> > > 'sgt' (i.e struct sg_table), so this could lead to memory corruption.
> > The sizeof(*sg) is bigger than sizeof(**sgt) so this wastes memory but
> > it won't lead to corruption.
> >
> > 11 struct scatterlist {
> > 12 unsigned long page_link;
> > 13 unsigned int offset;
> > 14 unsigned int length;
> > 15 dma_addr_t dma_address;
> > 16 #ifdef CONFIG_NEED_SG_DMA_LENGTH
> > 17 unsigned int dma_length;
> > 18 #endif
> > 19 };
> >
> > 42 struct sg_table {
> > 43 struct scatterlist *sgl; /* the list */
> > 44 unsigned int nents; /* number of mapped entries */
> > 45 unsigned int orig_nents; /* original size of list */
> > 46 };
> >
> > regards,
> > dan carpenter
>
>
> My bad. I read 'struct scatterlist sgl' (without the *)
> Thanks for the follow-up, Dan.
>
> Doesn't smatch catch such mismatch?
> (I've not run smatch for a while, so it is maybe reported)
That's why I was investigating it, because Smatch didn't catch it.
Smatch would have warned if it led to memory corruption. Smatch also
tries to detect struct mismatches as a separate check but for some
reason it missed it. I'm not totally sure why yet. I suspect that it's
a complicated internal reason where Sparse is the sizeof to a normal
number... It's a known issue and hard to fix.
>
> Well, the proposal is still valid, even if it has less impact as initially
> thought.
Yep.
regards,
dan carpenter
^ permalink raw reply [flat|nested] 28+ messages in thread* Re: [PATCH] drm: amdgpu: Use the correct size when allocating memory
@ 2020-08-11 7:57 ` Dan Carpenter
0 siblings, 0 replies; 28+ messages in thread
From: Dan Carpenter @ 2020-08-11 7:57 UTC (permalink / raw)
To: Marion & Christophe JAILLET
Cc: Ori.Messinger, airlied, bernard, kernel-janitors, linux-kernel,
dri-devel, colton.w.lewis, amd-gfx, alexander.deucher,
christian.koenig, m.szyprowski
On Mon, Aug 10, 2020 at 08:41:14PM +0200, Marion & Christophe JAILLET wrote:
>
> Le 10/08/2020 à 17:42, Dan Carpenter a écrit :
> > On Sun, Aug 09, 2020 at 10:34:06PM +0200, Christophe JAILLET wrote:
> > > When '*sgt' is allocated, we must allocated 'sizeof(**sgt)' bytes instead
> > > of 'sizeof(*sg)'. 'sg' (i.e. struct scatterlist) is smaller than
> > > 'sgt' (i.e struct sg_table), so this could lead to memory corruption.
> > The sizeof(*sg) is bigger than sizeof(**sgt) so this wastes memory but
> > it won't lead to corruption.
> >
> > 11 struct scatterlist {
> > 12 unsigned long page_link;
> > 13 unsigned int offset;
> > 14 unsigned int length;
> > 15 dma_addr_t dma_address;
> > 16 #ifdef CONFIG_NEED_SG_DMA_LENGTH
> > 17 unsigned int dma_length;
> > 18 #endif
> > 19 };
> >
> > 42 struct sg_table {
> > 43 struct scatterlist *sgl; /* the list */
> > 44 unsigned int nents; /* number of mapped entries */
> > 45 unsigned int orig_nents; /* original size of list */
> > 46 };
> >
> > regards,
> > dan carpenter
>
>
> My bad. I read 'struct scatterlist sgl' (without the *)
> Thanks for the follow-up, Dan.
>
> Doesn't smatch catch such mismatch?
> (I've not run smatch for a while, so it is maybe reported)
That's why I was investigating it, because Smatch didn't catch it.
Smatch would have warned if it led to memory corruption. Smatch also
tries to detect struct mismatches as a separate check but for some
reason it missed it. I'm not totally sure why yet. I suspect that it's
a complicated internal reason where Sparse is the sizeof to a normal
number... It's a known issue and hard to fix.
>
> Well, the proposal is still valid, even if it has less impact as initially
> thought.
Yep.
regards,
dan carpenter
_______________________________________________
dri-devel mailing list
dri-devel@lists.freedesktop.org
https://lists.freedesktop.org/mailman/listinfo/dri-devel
^ permalink raw reply [flat|nested] 28+ messages in thread* Re: [PATCH] drm: amdgpu: Use the correct size when allocating memory
@ 2020-08-11 7:57 ` Dan Carpenter
0 siblings, 0 replies; 28+ messages in thread
From: Dan Carpenter @ 2020-08-11 7:57 UTC (permalink / raw)
To: Marion & Christophe JAILLET
Cc: Ori.Messinger, airlied, bernard, kernel-janitors, linux-kernel,
dri-devel, sumit.semwal, colton.w.lewis, amd-gfx, daniel,
alexander.deucher, christian.koenig, m.szyprowski
On Mon, Aug 10, 2020 at 08:41:14PM +0200, Marion & Christophe JAILLET wrote:
>
> Le 10/08/2020 à 17:42, Dan Carpenter a écrit :
> > On Sun, Aug 09, 2020 at 10:34:06PM +0200, Christophe JAILLET wrote:
> > > When '*sgt' is allocated, we must allocated 'sizeof(**sgt)' bytes instead
> > > of 'sizeof(*sg)'. 'sg' (i.e. struct scatterlist) is smaller than
> > > 'sgt' (i.e struct sg_table), so this could lead to memory corruption.
> > The sizeof(*sg) is bigger than sizeof(**sgt) so this wastes memory but
> > it won't lead to corruption.
> >
> > 11 struct scatterlist {
> > 12 unsigned long page_link;
> > 13 unsigned int offset;
> > 14 unsigned int length;
> > 15 dma_addr_t dma_address;
> > 16 #ifdef CONFIG_NEED_SG_DMA_LENGTH
> > 17 unsigned int dma_length;
> > 18 #endif
> > 19 };
> >
> > 42 struct sg_table {
> > 43 struct scatterlist *sgl; /* the list */
> > 44 unsigned int nents; /* number of mapped entries */
> > 45 unsigned int orig_nents; /* original size of list */
> > 46 };
> >
> > regards,
> > dan carpenter
>
>
> My bad. I read 'struct scatterlist sgl' (without the *)
> Thanks for the follow-up, Dan.
>
> Doesn't smatch catch such mismatch?
> (I've not run smatch for a while, so it is maybe reported)
That's why I was investigating it, because Smatch didn't catch it.
Smatch would have warned if it led to memory corruption. Smatch also
tries to detect struct mismatches as a separate check but for some
reason it missed it. I'm not totally sure why yet. I suspect that it's
a complicated internal reason where Sparse is the sizeof to a normal
number... It's a known issue and hard to fix.
>
> Well, the proposal is still valid, even if it has less impact as initially
> thought.
Yep.
regards,
dan carpenter
^ permalink raw reply [flat|nested] 28+ messages in thread* Re: [PATCH] drm: amdgpu: Use the correct size when allocating memory
2020-08-11 7:57 ` Dan Carpenter
(?)
(?)
@ 2020-08-11 8:00 ` Dan Carpenter
-1 siblings, 0 replies; 28+ messages in thread
From: Dan Carpenter @ 2020-08-11 8:00 UTC (permalink / raw)
To: Marion & Christophe JAILLET
Cc: Ori.Messinger, airlied, bernard, kernel-janitors, linux-kernel,
dri-devel, sumit.semwal, colton.w.lewis, amd-gfx, daniel,
alexander.deucher, christian.koenig, m.szyprowski
On Tue, Aug 11, 2020 at 10:57:02AM +0300, Dan Carpenter wrote:
> On Mon, Aug 10, 2020 at 08:41:14PM +0200, Marion & Christophe JAILLET wrote:
> >
> > Le 10/08/2020 à 17:42, Dan Carpenter a écrit :
> > > On Sun, Aug 09, 2020 at 10:34:06PM +0200, Christophe JAILLET wrote:
> > > > When '*sgt' is allocated, we must allocated 'sizeof(**sgt)' bytes instead
> > > > of 'sizeof(*sg)'. 'sg' (i.e. struct scatterlist) is smaller than
> > > > 'sgt' (i.e struct sg_table), so this could lead to memory corruption.
> > > The sizeof(*sg) is bigger than sizeof(**sgt) so this wastes memory but
> > > it won't lead to corruption.
> > >
> > > 11 struct scatterlist {
> > > 12 unsigned long page_link;
> > > 13 unsigned int offset;
> > > 14 unsigned int length;
> > > 15 dma_addr_t dma_address;
> > > 16 #ifdef CONFIG_NEED_SG_DMA_LENGTH
> > > 17 unsigned int dma_length;
> > > 18 #endif
> > > 19 };
> > >
> > > 42 struct sg_table {
> > > 43 struct scatterlist *sgl; /* the list */
> > > 44 unsigned int nents; /* number of mapped entries */
> > > 45 unsigned int orig_nents; /* original size of list */
> > > 46 };
> > >
> > > regards,
> > > dan carpenter
> >
> >
> > My bad. I read 'struct scatterlist sgl' (without the *)
> > Thanks for the follow-up, Dan.
> >
> > Doesn't smatch catch such mismatch?
> > (I've not run smatch for a while, so it is maybe reported)
>
> That's why I was investigating it, because Smatch didn't catch it.
>
> Smatch would have warned if it led to memory corruption. Smatch also
> tries to detect struct mismatches as a separate check but for some
> reason it missed it. I'm not totally sure why yet. I suspect that it's
> a complicated internal reason where Sparse is the sizeof to a normal
s/is/changes/
> number... It's a known issue and hard to fix.
regards,
dan carpenter
_______________________________________________
amd-gfx mailing list
amd-gfx@lists.freedesktop.org
https://lists.freedesktop.org/mailman/listinfo/amd-gfx
^ permalink raw reply [flat|nested] 28+ messages in thread* Re: [PATCH] drm: amdgpu: Use the correct size when allocating memory
@ 2020-08-11 8:00 ` Dan Carpenter
0 siblings, 0 replies; 28+ messages in thread
From: Dan Carpenter @ 2020-08-11 8:00 UTC (permalink / raw)
To: Marion & Christophe JAILLET
Cc: alexander.deucher, christian.koenig, airlied, daniel,
sumit.semwal, colton.w.lewis, Ori.Messinger, m.szyprowski,
bernard, dri-devel, amd-gfx, linux-kernel, kernel-janitors
On Tue, Aug 11, 2020 at 10:57:02AM +0300, Dan Carpenter wrote:
> On Mon, Aug 10, 2020 at 08:41:14PM +0200, Marion & Christophe JAILLET wrote:
> >
> > Le 10/08/2020 à 17:42, Dan Carpenter a écrit :
> > > On Sun, Aug 09, 2020 at 10:34:06PM +0200, Christophe JAILLET wrote:
> > > > When '*sgt' is allocated, we must allocated 'sizeof(**sgt)' bytes instead
> > > > of 'sizeof(*sg)'. 'sg' (i.e. struct scatterlist) is smaller than
> > > > 'sgt' (i.e struct sg_table), so this could lead to memory corruption.
> > > The sizeof(*sg) is bigger than sizeof(**sgt) so this wastes memory but
> > > it won't lead to corruption.
> > >
> > > 11 struct scatterlist {
> > > 12 unsigned long page_link;
> > > 13 unsigned int offset;
> > > 14 unsigned int length;
> > > 15 dma_addr_t dma_address;
> > > 16 #ifdef CONFIG_NEED_SG_DMA_LENGTH
> > > 17 unsigned int dma_length;
> > > 18 #endif
> > > 19 };
> > >
> > > 42 struct sg_table {
> > > 43 struct scatterlist *sgl; /* the list */
> > > 44 unsigned int nents; /* number of mapped entries */
> > > 45 unsigned int orig_nents; /* original size of list */
> > > 46 };
> > >
> > > regards,
> > > dan carpenter
> >
> >
> > My bad. I read 'struct scatterlist sgl' (without the *)
> > Thanks for the follow-up, Dan.
> >
> > Doesn't smatch catch such mismatch?
> > (I've not run smatch for a while, so it is maybe reported)
>
> That's why I was investigating it, because Smatch didn't catch it.
>
> Smatch would have warned if it led to memory corruption. Smatch also
> tries to detect struct mismatches as a separate check but for some
> reason it missed it. I'm not totally sure why yet. I suspect that it's
> a complicated internal reason where Sparse is the sizeof to a normal
s/is/changes/
> number... It's a known issue and hard to fix.
regards,
dan carpenter
^ permalink raw reply [flat|nested] 28+ messages in thread* Re: [PATCH] drm: amdgpu: Use the correct size when allocating memory
@ 2020-08-11 8:00 ` Dan Carpenter
0 siblings, 0 replies; 28+ messages in thread
From: Dan Carpenter @ 2020-08-11 8:00 UTC (permalink / raw)
To: Marion & Christophe JAILLET
Cc: Ori.Messinger, airlied, bernard, kernel-janitors, linux-kernel,
dri-devel, colton.w.lewis, amd-gfx, alexander.deucher,
christian.koenig, m.szyprowski
On Tue, Aug 11, 2020 at 10:57:02AM +0300, Dan Carpenter wrote:
> On Mon, Aug 10, 2020 at 08:41:14PM +0200, Marion & Christophe JAILLET wrote:
> >
> > Le 10/08/2020 à 17:42, Dan Carpenter a écrit :
> > > On Sun, Aug 09, 2020 at 10:34:06PM +0200, Christophe JAILLET wrote:
> > > > When '*sgt' is allocated, we must allocated 'sizeof(**sgt)' bytes instead
> > > > of 'sizeof(*sg)'. 'sg' (i.e. struct scatterlist) is smaller than
> > > > 'sgt' (i.e struct sg_table), so this could lead to memory corruption.
> > > The sizeof(*sg) is bigger than sizeof(**sgt) so this wastes memory but
> > > it won't lead to corruption.
> > >
> > > 11 struct scatterlist {
> > > 12 unsigned long page_link;
> > > 13 unsigned int offset;
> > > 14 unsigned int length;
> > > 15 dma_addr_t dma_address;
> > > 16 #ifdef CONFIG_NEED_SG_DMA_LENGTH
> > > 17 unsigned int dma_length;
> > > 18 #endif
> > > 19 };
> > >
> > > 42 struct sg_table {
> > > 43 struct scatterlist *sgl; /* the list */
> > > 44 unsigned int nents; /* number of mapped entries */
> > > 45 unsigned int orig_nents; /* original size of list */
> > > 46 };
> > >
> > > regards,
> > > dan carpenter
> >
> >
> > My bad. I read 'struct scatterlist sgl' (without the *)
> > Thanks for the follow-up, Dan.
> >
> > Doesn't smatch catch such mismatch?
> > (I've not run smatch for a while, so it is maybe reported)
>
> That's why I was investigating it, because Smatch didn't catch it.
>
> Smatch would have warned if it led to memory corruption. Smatch also
> tries to detect struct mismatches as a separate check but for some
> reason it missed it. I'm not totally sure why yet. I suspect that it's
> a complicated internal reason where Sparse is the sizeof to a normal
s/is/changes/
> number... It's a known issue and hard to fix.
regards,
dan carpenter
_______________________________________________
dri-devel mailing list
dri-devel@lists.freedesktop.org
https://lists.freedesktop.org/mailman/listinfo/dri-devel
^ permalink raw reply [flat|nested] 28+ messages in thread* Re: [PATCH] drm: amdgpu: Use the correct size when allocating memory
@ 2020-08-11 8:00 ` Dan Carpenter
0 siblings, 0 replies; 28+ messages in thread
From: Dan Carpenter @ 2020-08-11 8:00 UTC (permalink / raw)
To: Marion & Christophe JAILLET
Cc: Ori.Messinger, airlied, bernard, kernel-janitors, linux-kernel,
dri-devel, sumit.semwal, colton.w.lewis, amd-gfx, daniel,
alexander.deucher, christian.koenig, m.szyprowski
On Tue, Aug 11, 2020 at 10:57:02AM +0300, Dan Carpenter wrote:
> On Mon, Aug 10, 2020 at 08:41:14PM +0200, Marion & Christophe JAILLET wrote:
> >
> > Le 10/08/2020 à 17:42, Dan Carpenter a écrit :
> > > On Sun, Aug 09, 2020 at 10:34:06PM +0200, Christophe JAILLET wrote:
> > > > When '*sgt' is allocated, we must allocated 'sizeof(**sgt)' bytes instead
> > > > of 'sizeof(*sg)'. 'sg' (i.e. struct scatterlist) is smaller than
> > > > 'sgt' (i.e struct sg_table), so this could lead to memory corruption.
> > > The sizeof(*sg) is bigger than sizeof(**sgt) so this wastes memory but
> > > it won't lead to corruption.
> > >
> > > 11 struct scatterlist {
> > > 12 unsigned long page_link;
> > > 13 unsigned int offset;
> > > 14 unsigned int length;
> > > 15 dma_addr_t dma_address;
> > > 16 #ifdef CONFIG_NEED_SG_DMA_LENGTH
> > > 17 unsigned int dma_length;
> > > 18 #endif
> > > 19 };
> > >
> > > 42 struct sg_table {
> > > 43 struct scatterlist *sgl; /* the list */
> > > 44 unsigned int nents; /* number of mapped entries */
> > > 45 unsigned int orig_nents; /* original size of list */
> > > 46 };
> > >
> > > regards,
> > > dan carpenter
> >
> >
> > My bad. I read 'struct scatterlist sgl' (without the *)
> > Thanks for the follow-up, Dan.
> >
> > Doesn't smatch catch such mismatch?
> > (I've not run smatch for a while, so it is maybe reported)
>
> That's why I was investigating it, because Smatch didn't catch it.
>
> Smatch would have warned if it led to memory corruption. Smatch also
> tries to detect struct mismatches as a separate check but for some
> reason it missed it. I'm not totally sure why yet. I suspect that it's
> a complicated internal reason where Sparse is the sizeof to a normal
s/is/changes/
> number... It's a known issue and hard to fix.
regards,
dan carpenter
^ permalink raw reply [flat|nested] 28+ messages in thread