* [PATCH][linux-next] net/smc: prevent NULL dereference in smc_find_rdma_v2_device_serv()
@ 2021-10-18 18:31 Tim Gardner
2021-10-19 6:33 ` Karsten Graul
0 siblings, 1 reply; 3+ messages in thread
From: Tim Gardner @ 2021-10-18 18:31 UTC (permalink / raw)
To: linux-s390
Cc: tim.gardner, Karsten Graul, David S. Miller, Jakub Kicinski,
netdev, linux-kernel
Coverity complains of a possible NULL dereference in smc_find_rdma_v2_device_serv().
1782 smc_v2_ext = smc_get_clc_v2_ext(pclc);
CID 121151 (#1 of 1): Dereference null return value (NULL_RETURNS)
5. dereference: Dereferencing a pointer that might be NULL smc_v2_ext when calling smc_clc_match_eid. [show details]
1783 if (!smc_clc_match_eid(ini->negotiated_eid, smc_v2_ext, NULL, NULL))
1784 goto not_found;
Fix this by checking for NULL.
Fixes: e49300a6bf621 ("net/smc: add listen processing for SMC-Rv2")
Cc: Karsten Graul <kgraul@linux.ibm.com>
Cc: "David S. Miller" <davem@davemloft.net>
Cc: Jakub Kicinski <kuba@kernel.org>
Cc: linux-s390@vger.kernel.org
Cc: netdev@vger.kernel.org
Cc: linux-kernel@vger.kernel.org
Signed-off-by: Tim Gardner <tim.gardner@canonical.com>
---
net/smc/af_smc.c | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/net/smc/af_smc.c b/net/smc/af_smc.c
index 5e50e007a7da..ff23d5b40793 100644
--- a/net/smc/af_smc.c
+++ b/net/smc/af_smc.c
@@ -1780,7 +1780,7 @@ static void smc_find_rdma_v2_device_serv(struct smc_sock *new_smc,
goto not_found;
smc_v2_ext = smc_get_clc_v2_ext(pclc);
- if (!smc_clc_match_eid(ini->negotiated_eid, smc_v2_ext, NULL, NULL))
+ if (!smc_v2_ext || !smc_clc_match_eid(ini->negotiated_eid, smc_v2_ext, NULL, NULL))
goto not_found;
/* prepare RDMA check */
--
2.33.1
^ permalink raw reply related [flat|nested] 3+ messages in thread
* Re: [PATCH][linux-next] net/smc: prevent NULL dereference in smc_find_rdma_v2_device_serv()
2021-10-18 18:31 [PATCH][linux-next] net/smc: prevent NULL dereference in smc_find_rdma_v2_device_serv() Tim Gardner
@ 2021-10-19 6:33 ` Karsten Graul
2021-10-19 11:39 ` Tim Gardner
0 siblings, 1 reply; 3+ messages in thread
From: Karsten Graul @ 2021-10-19 6:33 UTC (permalink / raw)
To: Tim Gardner, linux-s390
Cc: David S. Miller, Jakub Kicinski, netdev, linux-kernel
On 18/10/2021 20:31, Tim Gardner wrote:
> Coverity complains of a possible NULL dereference in smc_find_rdma_v2_device_serv().
>
> 1782 smc_v2_ext = smc_get_clc_v2_ext(pclc);
> CID 121151 (#1 of 1): Dereference null return value (NULL_RETURNS)
> 5. dereference: Dereferencing a pointer that might be NULL smc_v2_ext when calling smc_clc_match_eid. [show details]
> 1783 if (!smc_clc_match_eid(ini->negotiated_eid, smc_v2_ext, NULL, NULL))
> 1784 goto not_found;
>
> Fix this by checking for NULL.
Hmm that's a fundamental question for me: do we want to make the code checkers happy?
While I understand that those warnings give an uneasy feeling I am not sure
if the code should have additional (unneeded) checks only to avoid them.
In this case all NULL checks are initially done in smc_listen_v2_check(),
afterwards no more NULL checks are needed. When we would like to add them
then a lot more checks are needed, e.g. 3 times in smc_find_ism_v2_device_serv()
(not sure why coverity does not complain about them, too).
Thoughts?
^ permalink raw reply [flat|nested] 3+ messages in thread
* Re: [PATCH][linux-next] net/smc: prevent NULL dereference in smc_find_rdma_v2_device_serv()
2021-10-19 6:33 ` Karsten Graul
@ 2021-10-19 11:39 ` Tim Gardner
0 siblings, 0 replies; 3+ messages in thread
From: Tim Gardner @ 2021-10-19 11:39 UTC (permalink / raw)
To: Karsten Graul, linux-s390
Cc: David S. Miller, Jakub Kicinski, netdev, linux-kernel
On 10/19/21 12:33 AM, Karsten Graul wrote:
> On 18/10/2021 20:31, Tim Gardner wrote:
>> Coverity complains of a possible NULL dereference in smc_find_rdma_v2_device_serv().
>>
>> 1782 smc_v2_ext = smc_get_clc_v2_ext(pclc);
>> CID 121151 (#1 of 1): Dereference null return value (NULL_RETURNS)
>> 5. dereference: Dereferencing a pointer that might be NULL smc_v2_ext when calling smc_clc_match_eid. [show details]
>> 1783 if (!smc_clc_match_eid(ini->negotiated_eid, smc_v2_ext, NULL, NULL))
>> 1784 goto not_found;
>>
>> Fix this by checking for NULL.
>
> Hmm that's a fundamental question for me: do we want to make the code checkers happy?
> While I understand that those warnings give an uneasy feeling I am not sure
> if the code should have additional (unneeded) checks only to avoid them.
>
Coverity produces a lot of false positives. I thought this one might be
legitimate, but if you're comfortable that its not an issue then I'm OK
with that.
> In this case all NULL checks are initially done in smc_listen_v2_check(),
> afterwards no more NULL checks are needed. When we would like to add them
> then a lot more checks are needed, e.g. 3 times in smc_find_ism_v2_device_serv()
> (not sure why coverity does not complain about them, too).
>
> Thoughts?
>
Coverity probably has produced a report from the other call sites if
you've used a similar pattern, I just hadn't gotten to them yet.
I'll just mark them all as false positives.
rtg
--
-----------
Tim Gardner
Canonical, Inc
^ permalink raw reply [flat|nested] 3+ messages in thread
end of thread, other threads:[~2021-10-19 11:39 UTC | newest]
Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2021-10-18 18:31 [PATCH][linux-next] net/smc: prevent NULL dereference in smc_find_rdma_v2_device_serv() Tim Gardner
2021-10-19 6:33 ` Karsten Graul
2021-10-19 11:39 ` Tim Gardner
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).