netdev.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH 3/5] net: Set fput_needed iff FDPUT_FPUT is set
@ 2020-08-06 11:53 linmiaohe
  2020-08-06 11:59 ` Al Viro
  2020-08-08 21:22 ` David Miller
  0 siblings, 2 replies; 5+ messages in thread
From: linmiaohe @ 2020-08-06 11:53 UTC (permalink / raw)
  To: davem, kuba, viro; +Cc: netdev, linux-kernel, linmiaohe

From: Miaohe Lin <linmiaohe@huawei.com>

We should fput() file iff FDPUT_FPUT is set. So we should set fput_needed
accordingly.

Fixes: 00e188ef6a7e ("sockfd_lookup_light(): switch to fdget^W^Waway from fget_light")
Signed-off-by: Miaohe Lin <linmiaohe@huawei.com>
---
 net/socket.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/net/socket.c b/net/socket.c
index 6aff5aeb6728..ee9c9dac4728 100644
--- a/net/socket.c
+++ b/net/socket.c
@@ -500,7 +500,7 @@ static struct socket *sockfd_lookup_light(int fd, int *err, int *fput_needed)
 	if (f.file) {
 		sock = sock_from_file(f.file, err);
 		if (likely(sock)) {
-			*fput_needed = f.flags;
+			*fput_needed = f.flags & FDPUT_FPUT;
 			return sock;
 		}
 		fdput(f);
-- 
2.19.1


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

* Re: [PATCH 3/5] net: Set fput_needed iff FDPUT_FPUT is set
  2020-08-06 11:53 [PATCH 3/5] net: Set fput_needed iff FDPUT_FPUT is set linmiaohe
@ 2020-08-06 11:59 ` Al Viro
  2020-08-06 12:08   ` Al Viro
  2020-08-08 21:22 ` David Miller
  1 sibling, 1 reply; 5+ messages in thread
From: Al Viro @ 2020-08-06 11:59 UTC (permalink / raw)
  To: linmiaohe; +Cc: davem, kuba, netdev, linux-kernel

On Thu, Aug 06, 2020 at 07:53:16PM +0800, linmiaohe wrote:
> From: Miaohe Lin <linmiaohe@huawei.com>
> 
> We should fput() file iff FDPUT_FPUT is set. So we should set fput_needed
> accordingly.
> 
> Fixes: 00e188ef6a7e ("sockfd_lookup_light(): switch to fdget^W^Waway from fget_light")

Explain, please.  We are getting it from fdget(); what else can we get in flags there?

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

* Re: [PATCH 3/5] net: Set fput_needed iff FDPUT_FPUT is set
  2020-08-06 11:59 ` Al Viro
@ 2020-08-06 12:08   ` Al Viro
  0 siblings, 0 replies; 5+ messages in thread
From: Al Viro @ 2020-08-06 12:08 UTC (permalink / raw)
  To: linmiaohe; +Cc: davem, kuba, netdev, linux-kernel

On Thu, Aug 06, 2020 at 12:59:16PM +0100, Al Viro wrote:
> On Thu, Aug 06, 2020 at 07:53:16PM +0800, linmiaohe wrote:
> > From: Miaohe Lin <linmiaohe@huawei.com>
> > 
> > We should fput() file iff FDPUT_FPUT is set. So we should set fput_needed
> > accordingly.
> > 
> > Fixes: 00e188ef6a7e ("sockfd_lookup_light(): switch to fdget^W^Waway from fget_light")
> 
> Explain, please.  We are getting it from fdget(); what else can we get in flags there?

FWIW, struct fd ->flags may have two bits set: FDPUT_FPUT and FDPUT_POS_UNLOCK.
The latter is set only by __fdget_pos() and its callers, and that only for
regular files and directories.

Nevermind that sockfd_lookup_light() does *not* use ..._pos() family of
primitives, even if it started to use e.g. fdget_pos() it *still* would
not end up with anything other than FDPUT_FPUT to deal with on that
path - it checks that what it got is a socket.  Anything else is dropped
right there, without leaving fput() to caller.

So could you explain what exactly the bug is - if you are seeing some
breakage and this patch fixes it, something odd is definitely going on
and it would be nice to figure out what that something is.


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

* Re: [PATCH 3/5] net: Set fput_needed iff FDPUT_FPUT is set
  2020-08-06 11:53 [PATCH 3/5] net: Set fput_needed iff FDPUT_FPUT is set linmiaohe
  2020-08-06 11:59 ` Al Viro
@ 2020-08-08 21:22 ` David Miller
  1 sibling, 0 replies; 5+ messages in thread
From: David Miller @ 2020-08-08 21:22 UTC (permalink / raw)
  To: linmiaohe; +Cc: kuba, viro, netdev, linux-kernel

From: linmiaohe <linmiaohe@huawei.com>
Date: Thu, 6 Aug 2020 19:53:16 +0800

> From: Miaohe Lin <linmiaohe@huawei.com>
> 
> We should fput() file iff FDPUT_FPUT is set. So we should set fput_needed
> accordingly.
> 
> Fixes: 00e188ef6a7e ("sockfd_lookup_light(): switch to fdget^W^Waway from fget_light")
> Signed-off-by: Miaohe Lin <linmiaohe@huawei.com>

Applied.

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

* Re: [PATCH 3/5] net: Set fput_needed iff FDPUT_FPUT is set
@ 2020-08-07  9:48 linmiaohe
  0 siblings, 0 replies; 5+ messages in thread
From: linmiaohe @ 2020-08-07  9:48 UTC (permalink / raw)
  To: Al Viro; +Cc: davem, kuba, netdev, linux-kernel

Al Viro <viro@zeniv.linux.org.uk> wrote:
>On Thu, Aug 06, 2020 at 12:59:16PM +0100, Al Viro wrote:
>> On Thu, Aug 06, 2020 at 07:53:16PM +0800, linmiaohe wrote:
>> > From: Miaohe Lin <linmiaohe@huawei.com>
>> > 
>> > We should fput() file iff FDPUT_FPUT is set. So we should set 
>> > fput_needed accordingly.
>> > 
>> > Fixes: 00e188ef6a7e ("sockfd_lookup_light(): switch to fdget^W^Waway 
>> > from fget_light")
>> 
>> Explain, please.  We are getting it from fdget(); what else can we get in flags there?
>
>FWIW, struct fd ->flags may have two bits set: FDPUT_FPUT and FDPUT_POS_UNLOCK.
>The latter is set only by __fdget_pos() and its callers, and that only for regular files and directories.
>
>Nevermind that sockfd_lookup_light() does *not* use ..._pos() family of primitives, even if it started to use e.g. fdget_pos() it *still* would not end up with anything other than FDPUT_FPUT to deal with on that path - it checks that what it got is a socket.  Anything else is dropped right there, without leaving fput() to caller.
>
>So could you explain what exactly the bug is - if you are seeing some breakage and this patch fixes it, something odd is definitely going on and it would be nice to figure out what that something is.

I'am sorry, but I did not find something odd. I do this because this would make code more clear and consistent. It's pure a clean up patch.
Maybe Fixes tag makes this looks like a bugfix.

Thanks for your reply and detailed explaination. :)

And sorry for my rookie mistake, I wasn't meant to make these as a patch set...


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

end of thread, other threads:[~2020-08-08 21:22 UTC | newest]

Thread overview: 5+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2020-08-06 11:53 [PATCH 3/5] net: Set fput_needed iff FDPUT_FPUT is set linmiaohe
2020-08-06 11:59 ` Al Viro
2020-08-06 12:08   ` Al Viro
2020-08-08 21:22 ` David Miller
2020-08-07  9:48 linmiaohe

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