Received: by 2002:a25:8b91:0:0:0:0:0 with SMTP id j17csp4821799ybl; Wed, 22 Jan 2020 05:24:08 -0800 (PST) X-Google-Smtp-Source: APXvYqwqK26BsNy24BpHCYJSSxXouLL669pbtZgyfJyA9Y/R46ksDMTYdKNymxNg5DsTWO0C71q7 X-Received: by 2002:a05:6808:191:: with SMTP id w17mr6649091oic.29.1579699448134; Wed, 22 Jan 2020 05:24:08 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1579699448; cv=none; d=google.com; s=arc-20160816; b=Yp88tLu6Gi/PBEtQO1GsHyGT2EkDsG8up7ReIgPb719OYYwG4WEdkumDoM+muF8SYh IpziMSPUblm+tGla/fMgkIU5Kg7srS/sFJmk5TsPNpwR7yiOm3CQTZuar07DHoCpBkDT 7hS35YjiEjLnMRbPNxnaSLkSfQACx5Nu0sFXDBTOyzHSSFW+EP8ATD5eb76E1+ZoDlsD rKBll9i5BHr14nvzNvrjIwK1cMJzfd4tm1k+TFhRLRMUDQKJH0RSgVDR/x7GMRnJD9Dy izcv4E069EjemdTUYtGukTGP++nnlYnMZOe/l+em1dOO+Jjg8OuXw1wSS2AQ83fpaNOK a86Q== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:content-transfer-encoding:mime-version :user-agent:references:in-reply-to:message-id:date:subject:cc:to :from:dkim-signature; bh=ujkxMRDNIC7EFL/ufE+gjb8mERSCApweZjoKaRjNwu4=; b=aGWiCS3ZPrLZSskJ6ULhJWCaByOQjJR0Jess4WDEryIbJTbDHzDdxJDbwZplJpUlms nhhfIO5gK01WCBWnGnu19BENTbWKRYWfNh0bBi3So0vq5CCdVZXM+hJaRWX11iHwigPL VEsX8iGgpvKUCcHTo7A+INO/1kTowcZ6w6/QcqbYPk8hOv/ztqwrFOyWzsxDVKpwEsQ7 LTOZuhso8C3D2TYdy6bDHhHVEwV+S+H7CgeZV/j97CN4l/J5W2185/zjKikWVzVyM7Ia hD07Hwf9imwaQ5NTShxB48Yum20fJsqoGnuGixbB0+0LZ49qQ5W3s4k2Oo4H9b9wiliU 1nTQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=default header.b=B6udAx1c; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id u21si20864536oiv.267.2020.01.22.05.23.55; Wed, 22 Jan 2020 05:24:08 -0800 (PST) Received-SPF: pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; dkim=pass header.i=@kernel.org header.s=default header.b=B6udAx1c; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1730202AbgAVNWp (ORCPT + 99 others); Wed, 22 Jan 2020 08:22:45 -0500 Received: from mail.kernel.org ([198.145.29.99]:40540 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1729425AbgAVNWo (ORCPT ); Wed, 22 Jan 2020 08:22:44 -0500 Received: from localhost (unknown [84.241.205.26]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPSA id 943092468C; Wed, 22 Jan 2020 13:22:43 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1579699364; bh=WIPgcYVel5Lu2LNj4yXGRvKdS6d4CZSmTNWXIeratHs=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=B6udAx1c0Xe3M8ypDmxf+kJhzXvqLkpMhxvhuBQjcRj7RdQqLO63AnD+aJOYplWtT eo4MsIC4vdd+m/erxTFR5a/apK+ZHKs0eWgkHDU73hvJGFAXya8F0sNDGGUuBDoQZx 4QtCe+tc2qOidY5wYmyZUzV48pdMiHdfoVZGKjTc= From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , stable@vger.kernel.org, Arika Chen , Lingpeng Chen , John Fastabend , Daniel Borkmann , Song Liu Subject: [PATCH 5.4 122/222] bpf/sockmap: Read psock ingress_msg before sk_receive_queue Date: Wed, 22 Jan 2020 10:28:28 +0100 Message-Id: <20200122092842.486164236@linuxfoundation.org> X-Mailer: git-send-email 2.25.0 In-Reply-To: <20200122092833.339495161@linuxfoundation.org> References: <20200122092833.339495161@linuxfoundation.org> User-Agent: quilt/0.66 MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org From: Lingpeng Chen commit e7a5f1f1cd0008e5ad379270a8657e121eedb669 upstream. Right now in tcp_bpf_recvmsg, sock read data first from sk_receive_queue if not empty than psock->ingress_msg otherwise. If a FIN packet arrives and there's also some data in psock->ingress_msg, the data in psock->ingress_msg will be purged. It is always happen when request to a HTTP1.0 server like python SimpleHTTPServer since the server send FIN packet after data is sent out. Fixes: 604326b41a6fb ("bpf, sockmap: convert to generic sk_msg interface") Reported-by: Arika Chen Suggested-by: Arika Chen Signed-off-by: Lingpeng Chen Signed-off-by: John Fastabend Signed-off-by: Daniel Borkmann Acked-by: Song Liu Link: https://lore.kernel.org/bpf/20200109014833.18951-1-forrest0579@gmail.com Signed-off-by: Greg Kroah-Hartman --- net/ipv4/tcp_bpf.c | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) --- a/net/ipv4/tcp_bpf.c +++ b/net/ipv4/tcp_bpf.c @@ -121,14 +121,14 @@ int tcp_bpf_recvmsg(struct sock *sk, str struct sk_psock *psock; int copied, ret; - if (unlikely(flags & MSG_ERRQUEUE)) - return inet_recv_error(sk, msg, len, addr_len); - if (!skb_queue_empty(&sk->sk_receive_queue)) - return tcp_recvmsg(sk, msg, len, nonblock, flags, addr_len); - psock = sk_psock_get(sk); if (unlikely(!psock)) return tcp_recvmsg(sk, msg, len, nonblock, flags, addr_len); + if (unlikely(flags & MSG_ERRQUEUE)) + return inet_recv_error(sk, msg, len, addr_len); + if (!skb_queue_empty(&sk->sk_receive_queue) && + sk_psock_queue_empty(psock)) + return tcp_recvmsg(sk, msg, len, nonblock, flags, addr_len); lock_sock(sk); msg_bytes_ready: copied = __tcp_bpf_recvmsg(sk, psock, msg, len, flags); @@ -139,7 +139,7 @@ msg_bytes_ready: timeo = sock_rcvtimeo(sk, nonblock); data = tcp_bpf_wait_data(sk, psock, flags, timeo, &err); if (data) { - if (skb_queue_empty(&sk->sk_receive_queue)) + if (!sk_psock_queue_empty(psock)) goto msg_bytes_ready; release_sock(sk); sk_psock_put(sk, psock);