Received: by 2002:a05:6602:2086:0:0:0:0 with SMTP id a6csp4427739ioa; Wed, 27 Apr 2022 03:45:36 -0700 (PDT) X-Google-Smtp-Source: ABdhPJzYGC+h+bKRuPvRjdysXOr5UDU7ThCwseT7zYmOMeFs1gsbDV97ig94TzlFZc7kXYuYrOVm X-Received: by 2002:a17:90a:901:b0:1d9:4253:23e with SMTP id n1-20020a17090a090100b001d94253023emr22721981pjn.150.1651056336230; Wed, 27 Apr 2022 03:45:36 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1651056336; cv=none; d=google.com; s=arc-20160816; b=WEWEy3jNezznHKk6z50x63kAC3MJ17+/g8MQQ1ZCN7BzYF5065fR/Q2J1Y3B9UCHpD Q2irJl830dd693MrhbxWA0hDpC6UpuJRiStO0VIvpkNRgFjQAmFoW7jCh78ser5US40D pJLX8MHjMjUO2cGzthjwut91G6rudKm1263lSPbP86xR/p0yhQYNDyeq+VG5SIlmhV+B HqRnxzNa8ZIky/0S0h0yKukKnZGJov0Pqt3rc8Te8nenbgGW8KO7m3iVj6KIqqN8pPva ZxiU2eHucC3M9I+9iypXHclkq97T4no3KzPuMNbCI6hwsjtKcPa7nxrFnn8zzbW9Mz05 /Zcg== 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=LA0bE1TNzjqqyiBJWztWFYysNEE2zbi7Ah3YS1wUFHA=; b=UCRqW+1ed3qGSlrtoQBO21TD7B15QQz5rL9imtM1Hw0fVT5fiXTUtScIYFv3Ilmaxx Q0KIvsN5plXOQzHOQjfH4UKPEWEy0elB/mOc5PeQ7mCPyiLR/3rDJ0Bmh+3l79M5o+us +IufnScFMpT1NrodrZwHtZ7MDdSsW6WPgmn2Cw41WSK7XTMKfnHlsvHJ7XywGuGr3+4U AV4yHw/0ZAwvrcWAbTJvrelZNAxfaD2A/l0A5WUSdcFj0bivcAGbuLqRtL3gl4AZ+hCb LEDj9Gw0YzTDPawsWLtvYv5wXGDQtqJoDW0gF6F+K9r9yvu9CLtaAnqfZQGLV2cWAZIK U8Yg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b=ez3m+CZT; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:18 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. [2620:137:e000::1:18]) by mx.google.com with ESMTPS id n17-20020a170902d2d100b00153b2d16582si1398761plc.394.2022.04.27.03.45.35 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 27 Apr 2022 03:45:36 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:18 as permitted sender) client-ip=2620:137:e000::1:18; Authentication-Results: mx.google.com; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b=ez3m+CZT; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:18 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 24F26408F94; Wed, 27 Apr 2022 02:54:28 -0700 (PDT) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1346612AbiDZJLo (ORCPT + 99 others); Tue, 26 Apr 2022 05:11:44 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:55536 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1347300AbiDZIvS (ORCPT ); Tue, 26 Apr 2022 04:51:18 -0400 Received: from ams.source.kernel.org (ams.source.kernel.org [IPv6:2604:1380:4601:e00::1]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id E82F1890A6; Tue, 26 Apr 2022 01:40:07 -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 ams.source.kernel.org (Postfix) with ESMTPS id 78F83B81D0B; Tue, 26 Apr 2022 08:40:06 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id D6F75C385A4; Tue, 26 Apr 2022 08:40:04 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linuxfoundation.org; s=korg; t=1650962405; bh=G7DBDVabubEsHS3Fr6SjYXTJPuVUFXS31bzZnUqoGQY=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=ez3m+CZT8z1fujGW/Z75bEJWZK31AyeR2D426zquMQw3fFGbMD7M/P1+HOgehOhdu xDs5EkxPSvYtQY9m/ehIJBZa0bpiU9NXL7qdQyOUwYUWpsXjs5iradg9imok3S7exN pvFRRm7/eM5XBptKoYysb1FGd0x8qS3TLDOwM57s= 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.15 035/124] net/packet: fix packet_sock xmit return value checking Date: Tue, 26 Apr 2022 10:20:36 +0200 Message-Id: <20220426081748.302047454@linuxfoundation.org> X-Mailer: git-send-email 2.36.0 In-Reply-To: <20220426081747.286685339@linuxfoundation.org> References: <20220426081747.286685339@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 c0d4a65931de..88c3b5cf8d94 100644 --- a/net/packet/af_packet.c +++ b/net/packet/af_packet.c @@ -2820,8 +2820,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 */ @@ -3022,8 +3023,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