netdev.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH]nfc: replace improper check device_is_registered() in nfc_se_io()
@ 2025-04-14 14:11 Chen Yufeng
  2025-04-14 14:55 ` Krzysztof Kozlowski
  0 siblings, 1 reply; 6+ messages in thread
From: Chen Yufeng @ 2025-04-14 14:11 UTC (permalink / raw)
  To: krzk; +Cc: davem, edumazet, kuba, pabeni, horms, netdev, Chen Yufeng

A patch similar to commit da5c0f119203 ("nfc: replace improper check device_is_registered() in netlink related functions")

The nfc_se_io() function in the NFC subsystem suffers from a race 
condition similar to previously reported issues in other netlink-related 
functions. The function checks device status using device_is_registered(),
but this check can race with device unregistration despite being protected
by device_lock.

This patch also uses bool variable dev->shutting_down instead of
device_is_registered() to judge whether the nfc device is registered,
which is well synchronized.

Signed-off-by: Chen Yufeng <chenyufeng@iie.ac.cn>
---
 net/nfc/netlink.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/net/nfc/netlink.c b/net/nfc/netlink.c
index 6a40b8d0350d..6de0f5a18a87 100644
--- a/net/nfc/netlink.c
+++ b/net/nfc/netlink.c
@@ -1426,7 +1426,7 @@ static int nfc_se_io(struct nfc_dev *dev, u32 se_idx,
 
 	device_lock(&dev->dev);
 
-	if (!device_is_registered(&dev->dev)) {
+	if (dev->shutting_down) {
 		rc = -ENODEV;
 		goto error;
 	}
-- 
2.34.1


^ permalink raw reply related	[flat|nested] 6+ messages in thread

* Re: [PATCH]nfc: replace improper check device_is_registered() in nfc_se_io()
  2025-04-14 14:11 [PATCH]nfc: replace improper check device_is_registered() in nfc_se_io() Chen Yufeng
@ 2025-04-14 14:55 ` Krzysztof Kozlowski
  2025-04-15  2:54   ` Chen Yufeng
  0 siblings, 1 reply; 6+ messages in thread
From: Krzysztof Kozlowski @ 2025-04-14 14:55 UTC (permalink / raw)
  To: Chen Yufeng; +Cc: davem, edumazet, kuba, pabeni, horms, netdev

On 14/04/2025 16:11, Chen Yufeng wrote:
> A patch similar to commit da5c0f119203 ("nfc: replace improper check device_is_registered() in netlink related functions")

Please wrap commit message according to Linux coding style / submission
process (neither too early nor over the limit):
https://elixir.bootlin.com/linux/v6.4-rc1/source/Documentation/process/submitting-patches.rst#L597


Reviewed-by: Krzysztof Kozlowski <krzysztof.kozlowski@linaro.org>


Best regards,
Krzysztof

^ permalink raw reply	[flat|nested] 6+ messages in thread

* Re: Re: [PATCH]nfc: replace improper check device_is_registered() in nfc_se_io()
  2025-04-14 14:55 ` Krzysztof Kozlowski
@ 2025-04-15  2:54   ` Chen Yufeng
  2025-04-16  0:38     ` Jakub Kicinski
  0 siblings, 1 reply; 6+ messages in thread
From: Chen Yufeng @ 2025-04-15  2:54 UTC (permalink / raw)
  To: krzk; +Cc: chenyufeng, davem, edumazet, horms, kuba, netdev, pabeni

> On 14/04/2025 16:11, Chen Yufeng wrote:
> > A patch similar to commit da5c0f119203 ("nfc: replace improper check device_is_registered() in netlink related functions")

> Please wrap commit message according to Linux coding style / submission
> process (neither too early nor over the limit):
> https://elixir.bootlin.com/linux/v6.4-rc1/source/Documentation/process/submitting-patches.rst#L597

Thanks for your reply!
I have reorganized commit message as follows.

A patch similar to commit da5c0f119203 ("nfc: replace improper check 
device_is_registered() in netlink related functions").

The nfc_se_io() function in the NFC subsystem suffers from a race 
condition similar to previously reported issues in other netlink-related 
functions. The function checks device status using device_is_registered(),
but this check can race with device unregistration despite being protected
by device_lock.

This patch also uses bool variable dev->shutting_down instead of
device_is_registered() to judge whether the nfc device is registered,
which is well synchronized.

--
Thanks, 

Chen Yufeng

^ permalink raw reply	[flat|nested] 6+ messages in thread

* Re: [PATCH]nfc: replace improper check device_is_registered() in nfc_se_io()
  2025-04-15  2:54   ` Chen Yufeng
@ 2025-04-16  0:38     ` Jakub Kicinski
  2025-04-16  2:33       ` Chen Yufeng
  2025-04-16  2:44       ` Chen Yufeng
  0 siblings, 2 replies; 6+ messages in thread
From: Jakub Kicinski @ 2025-04-16  0:38 UTC (permalink / raw)
  To: Chen Yufeng; +Cc: krzk, davem, edumazet, horms, netdev, pabeni

On Tue, 15 Apr 2025 10:54:36 +0800 Chen Yufeng wrote:
> > On 14/04/2025 16:11, Chen Yufeng wrote:  
> > > A patch similar to commit da5c0f119203 ("nfc: replace improper check device_is_registered() in netlink related functions")  
> 
> > Please wrap commit message according to Linux coding style / submission
> > process (neither too early nor over the limit):
> > https://elixir.bootlin.com/linux/v6.4-rc1/source/Documentation/process/submitting-patches.rst#L597  
> 
> Thanks for your reply!
> I have reorganized commit message as follows.
> 
> A patch similar to commit da5c0f119203 ("nfc: replace improper check 
> device_is_registered() in netlink related functions").
> 
> The nfc_se_io() function in the NFC subsystem suffers from a race 
> condition similar to previously reported issues in other netlink-related 
> functions. The function checks device status using device_is_registered(),
> but this check can race with device unregistration despite being protected
> by device_lock.
> 
> This patch also uses bool variable dev->shutting_down instead of
> device_is_registered() to judge whether the nfc device is registered,
> which is well synchronized.

You're also missing a Fixes tag
-- 
pw-bot: cr

^ permalink raw reply	[flat|nested] 6+ messages in thread

* Re: [PATCH]nfc: replace improper check device_is_registered() in nfc_se_io()
  2025-04-16  0:38     ` Jakub Kicinski
@ 2025-04-16  2:33       ` Chen Yufeng
  2025-04-16  2:44       ` Chen Yufeng
  1 sibling, 0 replies; 6+ messages in thread
From: Chen Yufeng @ 2025-04-16  2:33 UTC (permalink / raw)
  To: kuba; +Cc: chenyufeng, davem, edumazet, horms, krzk, netdev, pabeni

Thanks for your reply. I have added the Fixes tag.
Fixes: cd96db6fd0ac ("NFC: Add se_io NFC operand")
--
Thanks, 

Chen Yufeng

^ permalink raw reply	[flat|nested] 6+ messages in thread

* Re: [PATCH]nfc: replace improper check device_is_registered() in nfc_se_io()
  2025-04-16  0:38     ` Jakub Kicinski
  2025-04-16  2:33       ` Chen Yufeng
@ 2025-04-16  2:44       ` Chen Yufeng
  1 sibling, 0 replies; 6+ messages in thread
From: Chen Yufeng @ 2025-04-16  2:44 UTC (permalink / raw)
  To: kuba; +Cc: chenyufeng, davem, edumazet, horms, krzk, netdev, pabeni

> On Tue, 15 Apr 2025 10:54:36 +0800 Chen Yufeng wrote:
> > > On 14/04/2025 16:11, Chen Yufeng wrote:  
> > > > A patch similar to commit da5c0f119203 ("nfc: replace improper check device_is_registered() in netlink related functions")  
> > 
> > > Please wrap commit message according to Linux coding style / submission
> > > process (neither too early nor over the limit):
> > > https://elixir.bootlin.com/linux/v6.4-rc1/source/Documentation/process/submitting-patches.rst#L597  
> > 
> > Thanks for your reply!
> > I have reorganized commit message as follows.
> > 
> > A patch similar to commit da5c0f119203 ("nfc: replace improper check 
> > device_is_registered() in netlink related functions").
> > 
> > The nfc_se_io() function in the NFC subsystem suffers from a race 
> > condition similar to previously reported issues in other netlink-related 
> > functions. The function checks device status using device_is_registered(),
> > but this check can race with device unregistration despite being protected
> > by device_lock.
> > 
> > This patch also uses bool variable dev->shutting_down instead of
> > device_is_registered() to judge whether the nfc device is registered,
> > which is well synchronized.
> 
> You're also missing a Fixes tag

Thanks for your reply. I have added the Fixes tag.
Fixes: cd96db6fd0ac ("NFC: Add se_io NFC operand")
--
Thanks, 

Chen Yufeng

^ permalink raw reply	[flat|nested] 6+ messages in thread

end of thread, other threads:[~2025-04-16  2:45 UTC | newest]

Thread overview: 6+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2025-04-14 14:11 [PATCH]nfc: replace improper check device_is_registered() in nfc_se_io() Chen Yufeng
2025-04-14 14:55 ` Krzysztof Kozlowski
2025-04-15  2:54   ` Chen Yufeng
2025-04-16  0:38     ` Jakub Kicinski
2025-04-16  2:33       ` Chen Yufeng
2025-04-16  2:44       ` Chen Yufeng

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).