Received: by 2002:a05:6602:2086:0:0:0:0 with SMTP id a6csp4443362ioa; Wed, 27 Apr 2022 04:07:03 -0700 (PDT) X-Google-Smtp-Source: ABdhPJxUnxxrQQz1MqZf44wguTLTt1TXkdSglHqkqVP56ewvBjq1xywgoGMWqlpwBDTyCFH09sW3 X-Received: by 2002:a05:6a00:24cb:b0:50a:8151:9abc with SMTP id d11-20020a056a0024cb00b0050a81519abcmr29273101pfv.57.1651057623292; Wed, 27 Apr 2022 04:07:03 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1651057623; cv=none; d=google.com; s=arc-20160816; b=mWEvLPhlps3IrkCUUzgTZAEToEDzBqcu1ElSs5L6FqVFHflFrJ5D8DW0EPPfNloMFT M/SIBfWaJ6MLejEhm5U9dZEO9sTMOOfnyCcgZ5DMD14Nf1SQi1SWCOd1Ad9xZP5nC+33 kuolmrcgAV8EG+AMsiDJB8sC2EIlf6PbDW3umb86K1uMItFHVcG7jWeSJEskouJ30aa+ HXU0BGMIR+h5zPb1y/+26mT5PMiwNM8uNGmI8F1RTVnjq1ZGulItVVQ85ejeu8umWBkR hw+o5Q6UxGBwBamTR+jfSTzNECSztUY6+zDP+xu9B62tT5+d8U8WizAWZw9R022CY4Xy f6aQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :user-agent:references:in-reply-to:message-id:date:subject:cc:to :from:dkim-signature; bh=Bk2Qa9ABnGzv7YgJIiZ4nwCZfz5F3Ocg7PNBcSq5is8=; b=WTEzY3Ot/pgW00kXyLQjL21tgnXOdri1PPN9qcRZsW5P5o5smSOxe02WButc5O2P3s 5dPpJN6vCfNo/iQx8cReE4oVKeL55a3n/Yxj+OgfO7RIleO2YFQezJH1nK2xdSc/obm8 2KCd8/YG1akMr3BGgtY8Y0xtuB2LaozdVJEd5ic96X73CS74WSQYgaV+ZdmfN0gTU+yI W+pxz8OKbgrcoN6Ot6qwESxCEa2vQ1FbdYB39agSY5knRZ8jcrPSzz1hteOwOPvA/Wwk FWDQfpXTU7NNHi4JHgmxgYhEm/NXz1+x2WXqamSmnmEfaDaBHDHt/YjUcMzQz2SF2u0d esPg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b=VVgc9mpB; spf=softfail (google.com: domain of transitioning linux-kernel-owner@vger.kernel.org does not designate 23.128.96.19 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linuxfoundation.org Return-Path: Received: from lindbergh.monkeyblade.net (lindbergh.monkeyblade.net. [23.128.96.19]) by mx.google.com with ESMTPS id h131-20020a636c89000000b003c15f7f2947si298580pgc.423.2022.04.27.04.07.02 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 27 Apr 2022 04:07:03 -0700 (PDT) Received-SPF: softfail (google.com: domain of transitioning linux-kernel-owner@vger.kernel.org does not designate 23.128.96.19 as permitted sender) client-ip=23.128.96.19; Authentication-Results: mx.google.com; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b=VVgc9mpB; spf=softfail (google.com: domain of transitioning linux-kernel-owner@vger.kernel.org does not designate 23.128.96.19 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linuxfoundation.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by lindbergh.monkeyblade.net (Postfix) with ESMTP id 6A7BC7C276; Wed, 27 Apr 2022 03:01:21 -0700 (PDT) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1349092AbiDZJ0g (ORCPT + 99 others); Tue, 26 Apr 2022 05:26:36 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:54960 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1345893AbiDZJCp (ORCPT ); Tue, 26 Apr 2022 05:02:45 -0400 Received: from dfw.source.kernel.org (dfw.source.kernel.org [IPv6:2604:1380:4641:c500::1]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 4A0DDDE082; Tue, 26 Apr 2022 01:43:41 -0700 (PDT) Received: from smtp.kernel.org (relay.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by dfw.source.kernel.org (Postfix) with ESMTPS id 3D929611BB; Tue, 26 Apr 2022 08:43:41 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 4BD9EC385A4; Tue, 26 Apr 2022 08:43:40 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linuxfoundation.org; s=korg; t=1650962620; bh=Urtn68nh2cnrStwYQ2ZjZ6cnqWEIAIE1PNUgiWD29HA=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=VVgc9mpBpsriNPJYm8w8Cpker9DNrhBMOwggAPaIF3LvUNxWeBLHJpMdf6AcBtMlE S1sohlR4T5ioJSFx+GXvvbVDEKIgiTscXC73ofgAjNarbK5PDXQGjAYhR6wvr7TYIG 7NY8lA0HrifQvelyu/skr21qd3CPZJhcSXGxuaWA= From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , stable@vger.kernel.org, Flavio Leitner , Hangbin Liu , "David S. Miller" , Sasha Levin Subject: [PATCH 5.17 033/146] net/packet: fix packet_sock xmit return value checking Date: Tue, 26 Apr 2022 10:20:28 +0200 Message-Id: <20220426081750.998058054@linuxfoundation.org> X-Mailer: git-send-email 2.36.0 In-Reply-To: <20220426081750.051179617@linuxfoundation.org> References: <20220426081750.051179617@linuxfoundation.org> User-Agent: quilt/0.66 MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit X-Spam-Status: No, score=-2.5 required=5.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,HEADER_FROM_DIFFERENT_DOMAINS, MAILING_LIST_MULTI,RDNS_NONE,SPF_HELO_NONE autolearn=unavailable autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org From: Hangbin Liu [ Upstream commit 29e8e659f984be00d75ec5fef4e37c88def72712 ] 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 Signed-off-by: Hangbin Liu Signed-off-by: David S. Miller Signed-off-by: Sasha Levin --- 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 a7273af2d900..e3c60251e708 100644 --- a/net/packet/af_packet.c +++ b/net/packet/af_packet.c @@ -2856,8 +2856,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 */ @@ -3058,8 +3059,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