dma-buf: return -EINVAL if dmabuf object is NULL
Subsystems (2)
PATCH 1/1 dma-buf: return -EINVAL if dmabuf object is NULL
On top of warning about a NULL object, we also want to return with a proper error code (as done in 'dma_buf_begin_cpu_access()'). Otherwise, we will get a NULL pointer dereference.
--- drivers/dma-buf/dma-buf.c | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-)
drivers/dma-buf/dma-buf.c +2 -1
@@ -1231,7 +1231,8 @@ int dma_buf_end_cpu_access(struct dma_buf *dmabuf, {int ret =0 ; -WARN_ON (!dmabuf); +if (WARN_ON (!dmabuf)) +return -EINVAL ;might_lock (&dmabuf->resv->lock.base);
Signature · 1 line
2.32.0
Christian König
maintainerTo be honest I think the if(WARN_ON(!dmabuf)) return -EINVAL handling here is misleading in the first place.
Returning -EINVAL on a hard coding error is not good practice and should probably be removed from the DMA-buf subsystem in general.
Christian.
Am 18.08.21 um 13:58 schrieb Nuno Sá:
Quoted 24 lines
On top of warning about a NULL object, we also want to return with a proper error code (as done in '
dma_buf_begin_cpu_access()'). Otherwise, we will get a NULL pointer dereference.Fixes fc13020e086b ("dma-buf: add support for kernel cpu access")Signed-off-by Nuno Sá <[email protected]>--- drivers/dma-buf/dma-buf.c | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-)drivers/dma-buf/dma-buf.c +2
-1@@ -1231,7 +1231,8 @@ int dma_buf_end_cpu_access(struct dma_buf *dmabuf, {int ret =0 ; -WARN_ON (!dmabuf); +if (WARN_ON (!dmabuf)) +return -EINVAL ;might_lock (&dmabuf->resv->lock.base);
Quoted 12 lines
From: Christian König <[email protected]>
Sent: Wednesday, August 18, 2021 2:10 PM
To: Sa, Nuno <[email protected]>; [email protected]; [email protected]; [email protected]
Cc: Rob Clark <[email protected]>; Sumit Semwal <[email protected]>
Subject: Re: [PATCH] dma-buf: return-EINVALif dmabuf object is NULL[External]
Quoted 7 lines
To be honest I think the if(WARN_ON(!dmabuf)) return
-EINVALhandling
here is misleading in the first place.Returning
-EINVALon a hard coding error is not good practice and should
probably be removed from the DMA-buf subsystem in general.
Would you say to just return 0 then? I don't think that having the dereference is also good..
I used -EINVAL to be coherent with the rest of the code.
- Nuno Sá
Quoted 30 lines
Christian.
Am 18.08.21 um 13:58 schrieb Nuno Sá:
Quoted 2 lines
On top of warning about a NULL object, we also want to return with a proper error code (as done in '
dma_buf_begin_cpu_access()').Otherwise,
drivers/dma-buf/dma-
Quoted 9 lines
we will get a NULL pointer dereference.
Fixes fc13020e086b ("dma-buf: add support for kernel cpu access")Signed-off-by Nuno Sá <[email protected]>--- drivers/dma-buf/dma-buf.c | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-)drivers/dma-buf/dma- renamed from drivers/dma-buf/dma-buf.c +0
-0
buf.cdrivers/dma-buf/dma-buf.c int dma_buf_end_cpu_access(struct
Quoted 4 lines
index
63d32261b63f..8ec7876dd523100644drivers/dma-buf/dma-buf.c +0
-0@@ -1231,7 +1231,8 @@ int dma_buf_end_cpu_access(struct
dma_buf*dmabuf,Quoted 9 lines
drivers/dma-buf/dma-buf.c +2
-1{int ret =0 ; -WARN_ON (!dmabuf); +if (WARN_ON (!dmabuf)) +return -EINVAL ;might_lock (&dmabuf->resv->lock.base);
Christian König
maintainerAm 18.08.21 um 14:17 schrieb Sa, Nuno:
Quoted 15 lines
Quoted 15 lines
From: Christian König <[email protected]>
Sent: Wednesday, August 18, 2021 2:10 PM
To: Sa, Nuno <[email protected]>; [email protected]; [email protected]; [email protected]
Cc: Rob Clark <[email protected]>; Sumit Semwal <[email protected]>
Subject: Re: [PATCH] dma-buf: return-EINVALif dmabuf object is NULL[External]
To be honest I think the if(WARN_ON(!dmabuf)) return
-EINVALhandling
here is misleading in the first place.
Quoted 5 lines
Quoted 3 lines
Returning
-EINVALon a hard coding error is not good practice and should
probably be removed from the DMA-buf subsystem in general.Would you say to just return 0 then? I don't think that having the dereference is also good..
No, just run into the dereference.
Passing NULL as the core object you are working on is a hard coding error and not something we should bubble up as recoverable error.
Quoted 1 line
I used
-EINVALto be coherent with the rest of the code.
I rather suggest to remove the check elsewhere as well.
Christian.
Quoted 33 lines
- Nuno Sá
Quoted 30 lines
Christian.
Am 18.08.21 um 13:58 schrieb Nuno Sá:
Quoted 2 lines
On top of warning about a NULL object, we also want to return with a proper error code (as done in '
dma_buf_begin_cpu_access()').Otherwise,
drivers/dma-buf/dma-
Quoted 9 lines
we will get a NULL pointer dereference.
Fixes fc13020e086b ("dma-buf: add support for kernel cpu access")Signed-off-by Nuno Sá <[email protected]>--- drivers/dma-buf/dma-buf.c | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-)drivers/dma-buf/dma- renamed from drivers/dma-buf/dma-buf.c +0
-0
buf.cdrivers/dma-buf/dma-buf.c int dma_buf_end_cpu_access(struct
Quoted 4 lines
index
63d32261b63f..8ec7876dd523100644drivers/dma-buf/dma-buf.c +0
-0@@ -1231,7 +1231,8 @@ int dma_buf_end_cpu_access(struct
dma_buf*dmabuf,Quoted 9 lines
drivers/dma-buf/dma-buf.c +2
-1{int ret =0 ; -WARN_ON (!dmabuf); +if (WARN_ON (!dmabuf)) +return -EINVAL ;might_lock (&dmabuf->resv->lock.base);
Quoted 22 lines · Christian König
Am 18.08.21 um 14:17 schrieb Sa, Nuno:
Quoted 15 lines
Quoted 15 lines
From: Christian König <[email protected]>
Sent: Wednesday, August 18, 2021 2:10 PM
To: Sa, Nuno <[email protected]>; [email protected]; [email protected]; [email protected]
Cc: Rob Clark <[email protected]>; Sumit Semwal <[email protected]>
Subject: Re: [PATCH] dma-buf: return-EINVALif dmabuf object is NULL[External]
To be honest I think the if(WARN_ON(!dmabuf)) return
-EINVALhandling
here is misleading in the first place.Quoted 5 lines
Quoted 3 lines
Returning
-EINVALon a hard coding error is not good practice and should
probably be removed from the DMA-buf subsystem in general.Would you say to just return 0 then? I don't think that having the dereference is also good..
Quoted 8 lines
No, just run into the dereference.
Passing NULL as the core object you are working on is a hard coding error and not something we should bubble up as recoverable error.
Quoted 1 line
I used
-EINVALto be coherent with the rest of the code.I rather suggest to remove the check elsewhere as well.
It's a lot more complicated, and WARN_ON + bail out is rather well-established code-pattern. There's been plenty of discussions in the past that a BUG_ON is harmful since it makes debugging a major pain, e.g.
https://lore.kernel.org/lkml/CA+55aFwyNTLuZgOWMTRuabWobF27ygskuxvFd-P0n-3UNT=0Og@mail.gmail.com/
There's also a checkpatch check for this.
commit 9d3e3c705eb395528fd8f17208c87581b134da48
Author: Joe Perches <[email protected]> Date: Wed Sep 9 15:37:27 2015 -0700
checkpatch: add warning on BUG/BUG_ON use
Anyone who is paranoid about security crashes their machine on any WARNING anyway (like syzkaller does).
My rule of thumb is that if the WARN_ON + bail-out code is just an if (WARN_ON()) return; then it's fine, if it's more then BUG_ON is the better choice perhaps.
I think the worst choice is just removing all these checks, because a few code reorgs later you might not Oops immediately afterwards anymore, and then we'll merge potentially very busted new code. Which is no good. -Daniel
Quoted 41 lines
Christian.
Quoted 27 lines
- Nuno Sá
Quoted 24 lines
Christian.
Am 18.08.21 um 13:58 schrieb Nuno Sá:
Quoted 2 lines
On top of warning about a NULL object, we also want to return with a proper error code (as done in '
dma_buf_begin_cpu_access()').Otherwise,
drivers/dma-buf/dma-
Quoted 9 lines
we will get a NULL pointer dereference.
Fixes fc13020e086b ("dma-buf: add support for kernel cpu access")Signed-off-by Nuno Sá <[email protected]>--- drivers/dma-buf/dma-buf.c | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-)drivers/dma-buf/dma- renamed from drivers/dma-buf/dma-buf.c +0
-0
buf.cdrivers/dma-buf/dma-buf.c int dma_buf_end_cpu_access(struct
Quoted 4 lines
index
63d32261b63f..8ec7876dd523100644drivers/dma-buf/dma-buf.c +0
-0@@ -1231,7 +1231,8 @@ int dma_buf_end_cpu_access(struct
dma_buf*dmabuf,Quoted 3 lines
drivers/dma-buf/dma-buf.c +0
-0{int ret =0 ;Quoted 6 lines
Quoted 6 lines
drivers/dma-buf/dma-buf.c int dma_buf_end_cpu_access(struct dma_buf *dmabuf, · line 1238
Quoted 6 lines
drivers/dma-buf/dma-buf.c +2
-1-WARN_ON (!dmabuf); +if (WARN_ON (!dmabuf)) +return -EINVAL ;might_lock (&dmabuf->resv->lock.base);_______________________________________________
Linaro-mm-sig mailing list
[email protected]
https://lists.linaro.org/mailman/listinfo/linaro-mm-sig
Signature · 3 lines
Daniel Vetter Software Engineer, Intel Corporation http://blog.ffwll.ch
Christian König
maintainerAm 18.08.21 um 14:46 schrieb Daniel Vetter:
Quoted 46 lines · Christian König
Quoted 21 lines
Am 18.08.21 um 14:17 schrieb Sa, Nuno:
Quoted 15 lines
Quoted 15 lines
From: Christian König <[email protected]>
Sent: Wednesday, August 18, 2021 2:10 PM
To: Sa, Nuno <[email protected]>; [email protected]; [email protected]; [email protected]
Cc: Rob Clark <[email protected]>; Sumit Semwal <[email protected]>
Subject: Re: [PATCH] dma-buf: return-EINVALif dmabuf object is NULL[External]
To be honest I think the if(WARN_ON(!dmabuf)) return
-EINVALhandling
here is misleading in the first place.Quoted 5 lines
Quoted 3 lines
Returning
-EINVALon a hard coding error is not good practice and should
probably be removed from the DMA-buf subsystem in general.Would you say to just return 0 then? I don't think that having the dereference is also good..
Quoted 7 lines
No, just run into the dereference.
Passing NULL as the core object you are working on is a hard coding error and not something we should bubble up as recoverable error.
Quoted 1 line
I used
-EINVALto be coherent with the rest of the code.I rather suggest to remove the check elsewhere as well.
It's a lot more complicated, and
WARN_ON+ bail out is rather well-established code-pattern. There's been plenty of discussions in the past that aBUG_ONis harmful since it makes debugging a major pain, e.g.There's also a checkpatch check for this.
commit
9d3e3c705eb395528fd8f17208c87581b134da48Author: Joe Perches <[email protected]> Date: Wed Sep 9 15:37:27 2015 -0700checkpatch: add warning on BUG/BUG_ON use
Anyone who is paranoid about security crashes their machine on any WARNING anyway (like syzkaller does).
Quoted 7 lines
My rule of thumb is that if the
WARN_ON+ bail-out code is just an if (WARN_ON()) return; then it's fine, if it's more thenBUG_ONis the better choice perhaps.I think the worst choice is just removing all these checks, because a few code reorgs later you might not Oops immediately afterwards anymore, and then we'll merge potentially very busted new code. Which is no good.
Well BUG_ON(some_codition) is a different problem which I agree on with Linus that this is problematic.
But "if (WARN_ON(!dmabuf)) return -EINVAL;" is really bad coding style as well since it hides real problems which are hard errors behind warnings.
Returning -EINVAL indicates a recoverable error which is usually caused by userspace giving invalid parameters and should never be abused to indicate a driver coding error.
Functions are either intended to take NULL as valid parameter, e.g. like kfree(NULL). Or they are intended to work on an object which is mandatory to provide.
Christian.
Quoted 42 lines
-Daniel
Quoted 38 lines
Christian.
Quoted 26 lines
- Nuno Sá
Quoted 24 lines
Christian.
Am 18.08.21 um 13:58 schrieb Nuno Sá:
Quoted 2 lines
On top of warning about a NULL object, we also want to return with a proper error code (as done in '
dma_buf_begin_cpu_access()').Otherwise,
drivers/dma-buf/dma-
Quoted 9 lines
we will get a NULL pointer dereference.
Fixes fc13020e086b ("dma-buf: add support for kernel cpu access")Signed-off-by Nuno Sá <[email protected]>--- drivers/dma-buf/dma-buf.c | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-)drivers/dma-buf/dma- renamed from drivers/dma-buf/dma-buf.c +0
-0
buf.cdrivers/dma-buf/dma-buf.c int dma_buf_end_cpu_access(struct
Quoted 4 lines
index
63d32261b63f..8ec7876dd523100644drivers/dma-buf/dma-buf.c +0
-0@@ -1231,7 +1231,8 @@ int dma_buf_end_cpu_access(struct
dma_buf*dmabuf,Quoted 3 lines
drivers/dma-buf/dma-buf.c +0
-0{int ret =0 ;Quoted 6 lines
Quoted 6 lines
drivers/dma-buf/dma-buf.c int dma_buf_end_cpu_access(struct dma_buf *dmabuf, · line 1238
Quoted 6 lines
drivers/dma-buf/dma-buf.c +2
-1-WARN_ON (!dmabuf); +if (WARN_ON (!dmabuf)) +return -EINVAL ;might_lock (&dmabuf->resv->lock.base);_______________________________________________
Linaro-mm-sig mailing list
[email protected]
https://nam11.safelinks.protection.outlook.com/?url=https%3A%2F%2Flists.linaro.org%2Fmailman%2Flistinfo%2Flinaro-mm-sig&data=04%7C01%7Cchristian.koenig%40amd.com%7C19f53e2a2d1843b65adc08d962463b78%7C3dd8961fe4884e608e11a82d994e183d%7C0%7C0%7C637648876076613233%7CUnknown%7CTWFpbGZsb3d8eyJWIjoiMC4wLjAwMDAiLCJQIjoiV2luMzIiLCJBTiI6Ik1haWwiLCJXVCI6Mn0%3D%7C1000&sdata=0E5L4Kid5ZPeKT8Uxx7K61fBXmI4TOsz%2F5ILsFpLB%2Fo%3D&reserved=0
Quoted 87 lines
From: Christian König <[email protected]>
Sent: Wednesday, August 18, 2021 2:58 PM
To: Daniel Vetter <[email protected]>
Cc: Sa, Nuno <[email protected]>; [email protected]; [email protected]; [email protected]; Rob Clark <[email protected]>
Subject: Re: [Linaro-mm-sig] [PATCH] dma-buf: return-EINVALif dmabuf object is NULL[External]
Am 18.08.21 um 14:46 schrieb Daniel Vetter:
Quoted 5 lines · Christian König
Quoted 4 lines
Am 18.08.21 um 14:17 schrieb Sa, Nuno:
Quoted 3 lines
Quoted 3 lines
From: Christian König <[email protected]>
Sent: Wednesday, August 18, 2021 2:10 PM
To: Sa, Nuno <[email protected]>; linaro-mm-Quoted 4 lines
Quoted 4 lines
Quoted 4 lines
Quoted 4 lines
[email protected]; [email protected]
Cc: Rob Clark <[email protected]>; Sumit Semwal <[email protected]>
Subject: Re: [PATCH] dma-buf: return-EINVALif dmabuf objectis
Quoted 8 lines
Quoted 8 lines
Quoted 8 lines
Quoted 8 lines
NULL
[External]
To be honest I think the if(WARN_ON(!dmabuf)) return
-EINVALhandling
here is misleading in the first place.Quoted 8 lines
Quoted 8 lines
Quoted 5 lines
Quoted 3 lines
Returning
-EINVALon a hard coding error is not good practice and should
probably be removed from the DMA-buf subsystem in general.Would you say to just return 0 then? I don't think that having the dereference is also good..
No, just run into the dereference.
Passing NULL as the core object you are working on is a hard coding
error
Quoted 6 lines
Quoted 4 lines
and not something we should bubble up as recoverable error.
Quoted 1 line
I used
-EINVALto be coherent with the rest of the code.I rather suggest to remove the check elsewhere as well.
It's a lot more complicated, and
WARN_ON+ bail out is rather well-established code-pattern. There's been plenty of discussions inthe
Quoted 1 line
past that a
BUG_ONis harmful since it makes debugging a majorpain, e.g.
Quoted 2 lines
https://urldefense.com/v3/__https://nam11.safelinks.protection.outl
ook.com/?url=https*3A*2F*2Flore.kernel.org*2Flkml*2FCA*2B55aFw yNTLuZgOWMTRuabWobF27ygskuxvFd-P0n- 3UNT*3D0Og*40mail.gmail.com*2F&data=04*7C01*7Cchristian.k oenig*40amd.com*7C19f53e2a2d1843b65adc08d962463b78*7C3dd896 1fe4884e608e11a82d994e183d*7C0*7C0*7C637648876076613233*7CU nknown*7CTWFpbGZsb3d8eyJWIjoiMC4wLjAwMDAiLCJQIjoiV2luMzIiL CJBTiI6Ik1haWwiLCJXVCI6Mn0*3D*7C1000&sdata=ajyBnjePRak3 o7ObpBAuJNd08HgkANM9C*2BgzOAeHrMk*3D&reserved=0__;J SUlJSUlJSUlJSUlJSUlJSUlJSUlJSU!!A3Ni8CS0y2Y!qiDegx4svPUMZrvnzUo X7VKvvFpDcedH9gYbRCiWfe_N3fw4zpmA54qxefvMiQ$Quoted 10 lines
There's also a checkpatch check for this.
commit
9d3e3c705eb395528fd8f17208c87581b134da48Author: Joe Perches <[email protected]> Date: Wed Sep 9 15:37:27 2015 -0700checkpatch: add warning on BUG/BUG_ON use
Anyone who is paranoid about security crashes their machine on any
WARNING
Quoted 4 lines
anyway (like syzkaller does).
My rule of thumb is that if the
WARN_ON+ bail-out code is just an if (WARN_ON()) return; then it's fine, if it's more thenBUG_ONis thebetter
Quoted 3 lines
choice perhaps.
I think the worst choice is just removing all these checks, because a
few
Quoted 1 line
code reorgs later you might not Oops immediately afterwards
anymore, and
Quoted 1 line
then we'll merge potentially very busted new code. Which is no
good.
Quoted 8 lines
Well
BUG_ON(some_codition)is a different problem which I agree on with
Linus that this is problematic.But "if (
WARN_ON(!dmabuf)) return-EINVAL;" is really bad coding style
as well since it hides real problems which are hard errors behind warnings.
I agree that doing these kind of checks in the core object of an API is abusing parameter "validation". I guess a good pattern is having the warning and let the code flow. But since these checks are already all over the place I'm not sure the way to go. I'm very new to dma-buf and I was just checking the code and saw this was not be coherent with the rest of the API so I thought it would be a straight easy patch... Well, I could not be more wrong :)
Anyways, depending on what's decided, I can send another patch trying to make these stuff more coherent. At this point, my feeling is that this patch is to be dropped...
- Nuno Sá
Quoted 66 lines
Returning
-EINVALindicates a recoverable error which is usually caused by userspace giving invalid parameters and should never be abused to indicate a driver coding error.Functions are either intended to take NULL as valid parameter, e.g. like kfree(NULL). Or they are intended to work on an object which is mandatory to provide.
Christian.
Quoted 12 lines
-Daniel
Quoted 8 lines
Christian.
Quoted 6 lines
- Nuno Sá
Quoted 4 lines
Christian.
Am 18.08.21 um 13:58 schrieb Nuno Sá:
Quoted 1 line
On top of warning about a NULL object, we also want to return
with a
Quoted 5 lines
Quoted 5 lines
Quoted 5 lines
Quoted 5 lines
Quoted 1 line
proper error code (as done in '
dma_buf_begin_cpu_access()').Otherwise,
Quoted 3 lines
we will get a NULL pointer dereference.
Fixes fc13020e086b ("dma-buf: add support for kernel cpuaccess")
Quoted 6 lines
Quoted 6 lines
Quoted 6 lines
Quoted 6 lines
drivers/dma-
Quoted 6 lines
Signed-off-by Nuno Sá <[email protected]>--- drivers/dma-buf/dma-buf.c | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-)drivers/dma- renamed from drivers/dma-buf/dma-buf.c +0
-0buf/dma-
Quoted 13 lines
Quoted 13 lines
Quoted 13 lines
Quoted 13 lines
buf.cdrivers/dma-buf/dma-buf.c int dma_buf_end_cpu_access(struct
Quoted 4 lines
index
63d32261b63f..8ec7876dd523100644drivers/dma-buf/dma-buf.c +0
-0@@ -1231,7 +1231,8 @@ int dma_buf_end_cpu_access(struct
dma_buf*dmabuf,Quoted 7 lines
drivers/dma-buf/dma-buf.c +2
-1{int ret =0 ; -WARN_ON (!dmabuf); +if (WARN_ON (!dmabuf)) +return -EINVAL ;Quoted 6 lines
Quoted 6 lines
Quoted 2 lines
Quoted 2 lines
drivers/dma-buf/dma-buf.c int dma_buf_end_cpu_access(struct dma_buf *dmabuf, · line 1238
Quoted 2 lines
drivers/dma-buf/dma-buf.c +0
-0might_lock (&dmabuf->resv->lock.base);_______________________________________________
Linaro-mm-sig mailing list
[email protected]https://urldefense.com/v3/__https://nam11.safelinks.protection.outl
ook.com/?url=https*3A*2F*2Flists.linaro.org*2Fmailman*2Flistinfo*2 Flinaro-mm- sig&data=04*7C01*7Cchristian.koenig*40amd.com*7C19f53e2a2 d1843b65adc08d962463b78*7C3dd8961fe4884e608e11a82d994e183d* 7C0*7C0*7C637648876076613233*7CUnknown*7CTWFpbGZsb3d8eyJ WIjoiMC4wLjAwMDAiLCJQIjoiV2luMzIiLCJBTiI6Ik1haWwiLCJXVCI6Mn0 *3D*7C1000&sdata=0E5L4Kid5ZPeKT8Uxx7K61fBXmI4TOsz*2F5IL sFpLB*2Fo*3D&reserved=0__;JSUlJSUlJSUlJSUlJSUlJSUlJSUl!!A3N i8CS0y2Y!qiDegx4svPUMZrvnzUoX7VKvvFpDcedH9gYbRCiWfe_N3fw4z pmA54oQstzSNA$
Christian König
maintainerAm 18.08.21 um 15:13 schrieb Sa, Nuno:
Quoted 93 lines
Quoted 85 lines
From: Christian König <[email protected]>
Sent: Wednesday, August 18, 2021 2:58 PM
To: Daniel Vetter <[email protected]>
Cc: Sa, Nuno <[email protected]>; [email protected]; [email protected]; [email protected]; Rob Clark <[email protected]>
Subject: Re: [Linaro-mm-sig] [PATCH] dma-buf: return-EINVALif dmabuf object is NULL[External]
Am 18.08.21 um 14:46 schrieb Daniel Vetter:
Quoted 5 lines · Christian König
Quoted 4 lines
Am 18.08.21 um 14:17 schrieb Sa, Nuno:
Quoted 3 lines
Quoted 3 lines
From: Christian König <[email protected]>
Sent: Wednesday, August 18, 2021 2:10 PM
To: Sa, Nuno <[email protected]>; linaro-mm-Quoted 4 lines
Quoted 4 lines
Quoted 4 lines
Quoted 4 lines
[email protected]; [email protected]
Cc: Rob Clark <[email protected]>; Sumit Semwal <[email protected]>
Subject: Re: [PATCH] dma-buf: return-EINVALif dmabuf objectis
Quoted 8 lines
Quoted 8 lines
Quoted 8 lines
Quoted 8 lines
NULL
[External]
To be honest I think the if(WARN_ON(!dmabuf)) return
-EINVALhandling
here is misleading in the first place.Quoted 8 lines
Quoted 8 lines
Quoted 5 lines
Quoted 3 lines
Returning
-EINVALon a hard coding error is not good practice and should
probably be removed from the DMA-buf subsystem in general.Would you say to just return 0 then? I don't think that having the dereference is also good..
No, just run into the dereference.
Passing NULL as the core object you are working on is a hard coding
error
Quoted 6 lines
Quoted 4 lines
and not something we should bubble up as recoverable error.
Quoted 1 line
I used
-EINVALto be coherent with the rest of the code.I rather suggest to remove the check elsewhere as well.
It's a lot more complicated, and
WARN_ON+ bail out is rather well-established code-pattern. There's been plenty of discussions inthe
Quoted 1 line
past that a
BUG_ONis harmful since it makes debugging a majorpain, e.g.
Quoted 1 line
https://nam11.safelinks.protection.outlook.com/?url=https%3A%2F%2Furldefense.com%2Fv3%2F__https%3A%2F%2Fnam11.safelinks.protection.outl&data=04%7C01%7Cchristian.koenig%40amd.com%7C6355660e526b4da23fa408d9624a0160%7C3dd8961fe4884e608e11a82d994e183d%7C0%7C0%7C637648892261202104%7CUnknown%7CTWFpbGZsb3d8eyJWIjoiMC4wLjAwMDAiLCJQIjoiV2luMzIiLCJBTiI6Ik1haWwiLCJXVCI6Mn0%3D%7C1000&sdata=pkZg9vDm4RTgmAD6vtugsLmUuL0fG9ExgTWedxOxCW8%3D&reserved=0
ook.com/?url=https*3A*2F*2Flore.kernel.org*2Flkml*2FCA*2B55aFw yNTLuZgOWMTRuabWobF27ygskuxvFd-P0n- 3UNT*3D0Og*40mail.gmail.com*2F&data=04*7C01*7Cchristian.k oenig*40amd.com*7C19f53e2a2d1843b65adc08d962463b78*7C3dd896 1fe4884e608e11a82d994e183d*7C0*7C0*7C637648876076613233*7CU nknown*7CTWFpbGZsb3d8eyJWIjoiMC4wLjAwMDAiLCJQIjoiV2luMzIiL CJBTiI6Ik1haWwiLCJXVCI6Mn0*3D*7C1000&sdata=ajyBnjePRak3 o7ObpBAuJNd08HgkANM9C*2BgzOAeHrMk*3D&reserved=0__;J SUlJSUlJSUlJSUlJSUlJSUlJSUlJSU!!A3Ni8CS0y2Y!qiDegx4svPUMZrvnzUo X7VKvvFpDcedH9gYbRCiWfe_N3fw4zpmA54qxefvMiQ$Quoted 9 lines
There's also a checkpatch check for this.
commit
9d3e3c705eb395528fd8f17208c87581b134da48Author: Joe Perches <[email protected]> Date: Wed Sep 9 15:37:27 2015 -0700checkpatch: add warning on BUG/BUG_ON use
Anyone who is paranoid about security crashes their machine on any
WARNING
Quoted 4 lines
anyway (like syzkaller does).
My rule of thumb is that if the
WARN_ON+ bail-out code is just an if (WARN_ON()) return; then it's fine, if it's more thenBUG_ONis thebetter
Quoted 3 lines
choice perhaps.
I think the worst choice is just removing all these checks, because a
few
Quoted 1 line
code reorgs later you might not Oops immediately afterwards
anymore, and
Quoted 1 line
then we'll merge potentially very busted new code. Which is no
good.
Quoted 8 lines
Well
BUG_ON(some_codition)is a different problem which I agree on with
Linus that this is problematic.But "if (
WARN_ON(!dmabuf)) return-EINVAL;" is really bad coding style
as well since it hides real problems which are hard errors behind warnings.
Quoted 7 lines
I agree that doing these kind of checks in the core object of an API is abusing parameter "validation". I guess a good pattern is having the warning and let the code flow. But since these checks are already all over the place I'm not sure the way to go. I'm very new to dma-buf and I was just checking the code and saw this was not be coherent with the rest of the API so I thought it would be a straight easy patch... Well, I could not be more wrong :)
Well that existing stuff might actually depend on this is a really good argument to keep it for now or at least until we have a consent on what to do.
Quoted 3 lines
Anyways, depending on what's decided, I can send another patch trying to make these stuff more coherent. At this point, my feeling is that this patch is to be dropped...
At least for now I would hold it back.
Thanks,
Christian.
Quoted 69 lines
- Nuno Sá
Quoted 66 lines
Returning
-EINVALindicates a recoverable error which is usually caused by userspace giving invalid parameters and should never be abused to indicate a driver coding error.Functions are either intended to take NULL as valid parameter, e.g. like kfree(NULL). Or they are intended to work on an object which is mandatory to provide.
Christian.
Quoted 12 lines
-Daniel
Quoted 8 lines
Christian.
Quoted 6 lines
- Nuno Sá
Quoted 4 lines
Christian.
Am 18.08.21 um 13:58 schrieb Nuno Sá:
Quoted 1 line
On top of warning about a NULL object, we also want to return
with a
Quoted 5 lines
Quoted 5 lines
Quoted 5 lines
Quoted 5 lines
Quoted 1 line
proper error code (as done in '
dma_buf_begin_cpu_access()').Otherwise,
Quoted 3 lines
we will get a NULL pointer dereference.
Fixes fc13020e086b ("dma-buf: add support for kernel cpuaccess")
Quoted 6 lines
Quoted 6 lines
Quoted 6 lines
Quoted 6 lines
drivers/dma-
Quoted 6 lines
Signed-off-by Nuno Sá <[email protected]>--- drivers/dma-buf/dma-buf.c | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-)drivers/dma- renamed from drivers/dma-buf/dma-buf.c +0
-0buf/dma-
Quoted 13 lines
Quoted 13 lines
Quoted 13 lines
Quoted 13 lines
buf.cdrivers/dma-buf/dma-buf.c int dma_buf_end_cpu_access(struct
Quoted 4 lines
index
63d32261b63f..8ec7876dd523100644drivers/dma-buf/dma-buf.c +0
-0@@ -1231,7 +1231,8 @@ int dma_buf_end_cpu_access(struct
dma_buf*dmabuf,Quoted 7 lines
drivers/dma-buf/dma-buf.c +2
-1{int ret =0 ; -WARN_ON (!dmabuf); +if (WARN_ON (!dmabuf)) +return -EINVAL ;Quoted 6 lines
Quoted 6 lines
Quoted 2 lines
Quoted 2 lines
drivers/dma-buf/dma-buf.c int dma_buf_end_cpu_access(struct · line 1238
Quoted 2 lines
drivers/dma-buf/dma-buf.c +0
-0might_lock (&dmabuf->resv->lock.base);_______________________________________________
Linaro-mm-sig mailing list
[email protected]https://nam11.safelinks.protection.outlook.com/?url=https%3A%2F%2Furldefense.com%2Fv3%2F__https%3A%2F%2Fnam11.safelinks.protection.outl&data=04%7C01%7Cchristian.koenig%40amd.com%7C6355660e526b4da23fa408d9624a0160%7C3dd8961fe4884e608e11a82d994e183d%7C0%7C0%7C637648892261212099%7CUnknown%7CTWFpbGZsb3d8eyJWIjoiMC4wLjAwMDAiLCJQIjoiV2luMzIiLCJBTiI6Ik1haWwiLCJXVCI6Mn0%3D%7C1000&sdata=%2B7ORg3ZL932Gf%2FQzZdgcJTb02dm5dIL0YaAR6mtAQ2c%3D&reserved=0
ook.com/?url=https*3A*2F*2Flists.linaro.org*2Fmailman*2Flistinfo*2 Flinaro-mm- sig&data=04*7C01*7Cchristian.koenig*40amd.com*7C19f53e2a2 d1843b65adc08d962463b78*7C3dd8961fe4884e608e11a82d994e183d* 7C0*7C0*7C637648876076613233*7CUnknown*7CTWFpbGZsb3d8eyJ WIjoiMC4wLjAwMDAiLCJQIjoiV2luMzIiLCJBTiI6Ik1haWwiLCJXVCI6Mn0 *3D*7C1000&sdata=0E5L4Kid5ZPeKT8Uxx7K61fBXmI4TOsz*2F5IL sFpLB*2Fo*3D&reserved=0__;JSUlJSUlJSUlJSUlJSUlJSUlJSUl!!A3N i8CS0y2Y!qiDegx4svPUMZrvnzUoX7VKvvFpDcedH9gYbRCiWfe_N3fw4z pmA54oQstzSNA$