All of lore.kernel.org
 help / color / mirror / Atom feed
* [PATCH net] net/packet: fix packet_sock xmit return value checking
@ 2022-04-14  8:49 Hangbin Liu
  2022-04-15 10:20 ` patchwork-bot+netdevbpf
  0 siblings, 1 reply; 2+ messages in thread
From: Hangbin Liu @ 2022-04-14  8:49 UTC (permalink / raw)
  To: netdev
  Cc: Jakub Kicinski, Paolo Abeni, Eric Dumazet, David S . Miller,
	Hangbin Liu, Flavio Leitner

packet_sock xmit could be dev_queue_xmit, which also returns negative
errors. So only checking positive errors is not enough, or userspace
sendmsg may return success while packet is not send out.

Move the net_xmit_errno() assignment in the braces as checkpatch.pl said
do not use assignment in if condition.

Fixes: 1da177e4c3f4 ("Linux-2.6.12-rc2")
Reported-by: Flavio Leitner <fbl@redhat.com>
Signed-off-by: Hangbin Liu <liuhangbin@gmail.com>
---
 net/packet/af_packet.c | 13 +++++++++----
 1 file changed, 9 insertions(+), 4 deletions(-)

diff --git a/net/packet/af_packet.c b/net/packet/af_packet.c
index c39c09899fd0..002d2b9c69dd 100644
--- a/net/packet/af_packet.c
+++ b/net/packet/af_packet.c
@@ -2858,8 +2858,9 @@ static int tpacket_snd(struct packet_sock *po, struct msghdr *msg)
 
 		status = TP_STATUS_SEND_REQUEST;
 		err = po->xmit(skb);
-		if (unlikely(err > 0)) {
-			err = net_xmit_errno(err);
+		if (unlikely(err != 0)) {
+			if (err > 0)
+				err = net_xmit_errno(err);
 			if (err && __packet_get_status(po, ph) ==
 				   TP_STATUS_AVAILABLE) {
 				/* skb was destructed already */
@@ -3060,8 +3061,12 @@ static int packet_snd(struct socket *sock, struct msghdr *msg, size_t len)
 		skb->no_fcs = 1;
 
 	err = po->xmit(skb);
-	if (err > 0 && (err = net_xmit_errno(err)) != 0)
-		goto out_unlock;
+	if (unlikely(err != 0)) {
+		if (err > 0)
+			err = net_xmit_errno(err);
+		if (err)
+			goto out_unlock;
+	}
 
 	dev_put(dev);
 
-- 
2.35.1


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

* Re: [PATCH net] net/packet: fix packet_sock xmit return value checking
  2022-04-14  8:49 [PATCH net] net/packet: fix packet_sock xmit return value checking Hangbin Liu
@ 2022-04-15 10:20 ` patchwork-bot+netdevbpf
  0 siblings, 0 replies; 2+ messages in thread
From: patchwork-bot+netdevbpf @ 2022-04-15 10:20 UTC (permalink / raw)
  To: Hangbin Liu; +Cc: netdev, kuba, pabeni, edumazet, davem, fbl

Hello:

This patch was applied to netdev/net.git (master)
by David S. Miller <davem@davemloft.net>:

On Thu, 14 Apr 2022 16:49:25 +0800 you wrote:
> packet_sock xmit could be dev_queue_xmit, which also returns negative
> errors. So only checking positive errors is not enough, or userspace
> sendmsg may return success while packet is not send out.
> 
> Move the net_xmit_errno() assignment in the braces as checkpatch.pl said
> do not use assignment in if condition.
> 
> [...]

Here is the summary with links:
  - [net] net/packet: fix packet_sock xmit return value checking
    https://git.kernel.org/netdev/net/c/29e8e659f984

You are awesome, thank you!
-- 
Deet-doot-dot, I am a bot.
https://korg.docs.kernel.org/patchwork/pwbot.html



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

end of thread, other threads:[~2022-04-15 10:20 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2022-04-14  8:49 [PATCH net] net/packet: fix packet_sock xmit return value checking Hangbin Liu
2022-04-15 10:20 ` patchwork-bot+netdevbpf

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.