Received: by 2002:a05:6358:4e97:b0:b3:742d:4702 with SMTP id ce23csp2875294rwb; Mon, 15 Aug 2022 13:06:01 -0700 (PDT) X-Google-Smtp-Source: AA6agR5pqlvUWSiAQQ1H3IojJAnubU4wBlNIdQk7KZc6zDqDLih4Kb3QWc6kUKT6GwQrj0GqS/+I X-Received: by 2002:a17:907:3f23:b0:738:545f:3f29 with SMTP id hq35-20020a1709073f2300b00738545f3f29mr3688217ejc.521.1660593961247; Mon, 15 Aug 2022 13:06:01 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1660593961; cv=none; d=google.com; s=arc-20160816; b=Kcx8QYGK7RERq3n8kGZoY+8jDl9TT3EkPIppkmjDnNcK26vr0WpV2QDoG7NRE2J4+o C2wnjZ9ebPDdNTYqD9jHzTqH+VR7t911CYLwR1TLymsBg8WiWoQUsyzRocHfhLbV03qO QASOAwiOS1t9tVC6rZx672k4IkjQCPCsolJxhpi5EYrdATofFZ5LY0hb44sNUNEXbekq PyVpWW24kZW6kT5Wu8e6x5zk7ukZB1eg0ojmhfTotDevA/BFADUJSquwxZqvSH/HhY/g 1lt6DT3EazgF2ale4LCpxB0b/C3TXtv7JF9QMQ+dNz/Ch8slZK4ZXRyDRrIhKmH3Y6kk o+pQ== 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=Bzp2lyWW6S1uUBbCmHpwDiildBIw5XWjWGbesfmvXnw=; b=hMcHTKE4sDkVFUApBNLegfb3NO2HH5DoQvTHTSrWYi6yXl4h06/Mo3JOFe00EpjnP2 PyPo/bBzJK1gVH8UfTffLA+9YjsMcJyRfhyJZ8rO5G8nlTLOa2q+lCdRA5XZ6rRq1E7c qWvEWaLva/38+6dRBfz62TRmtnyM+PPXPnEgUNsZVuxuWUM6Rnp6Da5lBrV2QPtfsz0G jc5o7oFQQyRbC2iohB7TXf1wvX9gJI3XVPjLeu9ONR8XpXTh/7HFEl8Tscld+rYE0NS4 4SnfxG+Uk8ISvZu9VLWyE10RecgqdT9NeRbo7zs7qsFDZlZkSJQylHnJj/EcWwGh1Quj Gt8A== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b=YFvrVIyH; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 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 out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id bf10-20020a0564021a4a00b0043d9b5a736bsi8458779edb.482.2022.08.15.13.05.36; Mon, 15 Aug 2022 13:06:01 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) client-ip=2620:137:e000::1:20; Authentication-Results: mx.google.com; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b=YFvrVIyH; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linuxfoundation.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S232726AbiHOS6d (ORCPT + 99 others); Mon, 15 Aug 2022 14:58:33 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:34436 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S244798AbiHOSzw (ORCPT ); Mon, 15 Aug 2022 14:55:52 -0400 Received: from ams.source.kernel.org (ams.source.kernel.org [145.40.68.75]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 6942B2DF2; Mon, 15 Aug 2022 11:30:23 -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 ED9E1B8106C; Mon, 15 Aug 2022 18:30:20 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 4BDF0C433C1; Mon, 15 Aug 2022 18:30:19 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linuxfoundation.org; s=korg; t=1660588219; bh=9gl4kRdQ+WLKKQ5khPH9o29OL7Te4TCVWT384FGVGKk=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=YFvrVIyHedvj8BPGtTk2kG0HtAiSii/3i8n+6P0lX3t7dNoGUVqdCCNttjNMJu14X FgLTXNZkZ4x9Cdyv2oGMloxSmiljjhNp2w2c2BwmGwpdAQekpAzBLHjYhoyrtuPjBn 7cHC9q1zhqZ0ooJZQ3VPrNXz5CMpqzJJXMnVuA20= From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , stable@vger.kernel.org, Liu Jian , Daniel Borkmann , John Fastabend , Sasha Levin Subject: [PATCH 5.15 333/779] skmsg: Fix invalid last sg check in sk_msg_recvmsg() Date: Mon, 15 Aug 2022 19:59:37 +0200 Message-Id: <20220815180351.507977711@linuxfoundation.org> X-Mailer: git-send-email 2.37.2 In-Reply-To: <20220815180337.130757997@linuxfoundation.org> References: <20220815180337.130757997@linuxfoundation.org> User-Agent: quilt/0.67 MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit X-Spam-Status: No, score=-7.1 required=5.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,RCVD_IN_DNSWL_HI, SPF_HELO_NONE,SPF_PASS,T_SCC_BODY_TEXT_LINE autolearn=ham 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: Liu Jian [ Upstream commit 9974d37ea75f01b47d16072b5dad305bd8d23fcc ] In sk_psock_skb_ingress_enqueue function, if the linear area + nr_frags + frag_list of the SKB has NR_MSG_FRAG_IDS blocks in total, skb_to_sgvec will return NR_MSG_FRAG_IDS, then msg->sg.end will be set to NR_MSG_FRAG_IDS, and in addition, (NR_MSG_FRAG_IDS - 1) is set to the last SG of msg. Recv the msg in sk_msg_recvmsg, when i is (NR_MSG_FRAG_IDS - 1), the sk_msg_iter_var_next(i) will change i to 0 (not NR_MSG_FRAG_IDS), the judgment condition "msg_rx->sg.start==msg_rx->sg.end" and "i != msg_rx->sg.end" can not work. As a result, the processed msg cannot be deleted from ingress_msg list. But the length of all the sge of the msg has changed to 0. Then the next recvmsg syscall will process the msg repeatedly, because the length of sge is 0, the -EFAULT error is always returned. Fixes: 604326b41a6f ("bpf, sockmap: convert to generic sk_msg interface") Signed-off-by: Liu Jian Signed-off-by: Daniel Borkmann Acked-by: John Fastabend Link: https://lore.kernel.org/bpf/20220628123616.186950-1-liujian56@huawei.com Signed-off-by: Sasha Levin --- net/core/skmsg.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/net/core/skmsg.c b/net/core/skmsg.c index ede0af308f40..f50f8d95b628 100644 --- a/net/core/skmsg.c +++ b/net/core/skmsg.c @@ -462,7 +462,7 @@ int sk_msg_recvmsg(struct sock *sk, struct sk_psock *psock, struct msghdr *msg, if (copied == len) break; - } while (i != msg_rx->sg.end); + } while (!sg_is_last(sge)); if (unlikely(peek)) { msg_rx = sk_psock_next_msg(psock, msg_rx); @@ -472,7 +472,7 @@ int sk_msg_recvmsg(struct sock *sk, struct sk_psock *psock, struct msghdr *msg, } msg_rx->sg.start = i; - if (!sge->length && msg_rx->sg.start == msg_rx->sg.end) { + if (!sge->length && sg_is_last(sge)) { msg_rx = sk_psock_dequeue_msg(psock); kfree_sk_msg(msg_rx); } -- 2.35.1