From patchwork Wed Mar 2 16:17:22 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Eric Dumazet X-Patchwork-Id: 12766259 X-Patchwork-Delegate: kuba@kernel.org Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 5C67EC433FE for ; Wed, 2 Mar 2022 16:17:34 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S240656AbiCBQSP (ORCPT ); Wed, 2 Mar 2022 11:18:15 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:34480 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S241289AbiCBQSO (ORCPT ); Wed, 2 Mar 2022 11:18:14 -0500 Received: from mail-pg1-x52f.google.com (mail-pg1-x52f.google.com [IPv6:2607:f8b0:4864:20::52f]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id C54BADFF6; Wed, 2 Mar 2022 08:17:30 -0800 (PST) Received: by mail-pg1-x52f.google.com with SMTP id z4so2029171pgh.12; Wed, 02 Mar 2022 08:17:30 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20210112; h=from:to:cc:subject:date:message-id:mime-version :content-transfer-encoding; bh=NEIR/7K1s5SDBS74dA3+Y+CfCaE7Ky5QycYBnqqINX0=; b=Ha+XagQsMacjhkbXnL64JKc+CZBwxnYxmXFTox8j+vtCx6mMcSdUrx/nunnzr3GKrJ aswA8xCKNLW8R79BwUzLvnrcG+QeASYfeSYk5hl4AlycJqGREAUqXae1nhMW3AU6+N4e DoODIgvR6VfBGmU+Eex59FweaJlVTBBKcQf8VAv2AV4MRGPdPukMJUoqepNeYIGeXEmx +oIsiMJqXt+1wJF5yS+63YhiGNdOzMMJTAsmNIljzYhadrxLADevHSVOjZij8YYcBusH JhmUVPhdeR3k1N4ETiBKmwmL+9d/dKdSmLtaddBparxepmra6iV24sudQBtc954ff8gp Jtrg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:from:to:cc:subject:date:message-id:mime-version :content-transfer-encoding; bh=NEIR/7K1s5SDBS74dA3+Y+CfCaE7Ky5QycYBnqqINX0=; b=EvEyUyHyXhzIo8EkpYB5FYABCZR7I6ZxoOzQRurAvS05APDiGYnDN1qteUv7EvJTZ1 pR6BE49SUhFIZdLMkFQZtoXEaoi9yXo2RcmKh0zDTuvvUfzZD7BP5BgANcNpZsKF5R4D RSa8c9pNoo1vmbam3IQxTGmC/mOq3eEZoMP9pIo0TeKwngxmGXrVaNUC+/2PTG1EI0cV UKy0WYGoTcMSDA06uJBtJTOghudG2/VCeB+joJyIagZXStSH8MSq/VaDBpC5nE3rFd9j VjVLUln/n1rdcY6bSpNEF98U4g9MznFMo2Ch0LFuFTsd0yhx/+b4bdn0upyR2VZ8CzkL Uczg== X-Gm-Message-State: AOAM533QqISlDnUO2fNHROTJgEDNxJbGpx4xGS6qGtpZBz5Ue0ZMpNs6 0RFAkVZiwKxlvxHIexJmLVv8LH9oz2Y= X-Google-Smtp-Source: ABdhPJzIcUsRPPvxop3yyNgUUT2Wrry/q9exPCghkTe3ylpYlLe+sowBJqGGcANUGkZO1W0j8uoJvw== X-Received: by 2002:a05:6a00:1a8b:b0:4e1:4151:6637 with SMTP id e11-20020a056a001a8b00b004e141516637mr33883387pfv.23.1646237850250; Wed, 02 Mar 2022 08:17:30 -0800 (PST) Received: from edumazet1.svl.corp.google.com ([2620:15c:2c4:201:7e41:847f:4bb0:a922]) by smtp.gmail.com with ESMTPSA id w17-20020a056a0014d100b004f1063290basm21771704pfu.15.2022.03.02.08.17.28 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 02 Mar 2022 08:17:29 -0800 (PST) From: Eric Dumazet To: "David S . Miller" , Jakub Kicinski , Alexei Starovoitov , Daniel Borkmann , John Fastabend Cc: netdev , bpf , Jakub Sitnicki , Andrii Nakryiko , Martin KaFai Lau , Song Liu , Yonghong Song , KP Singh , Eric Dumazet , Neal Cardwell , Eric Dumazet , syzbot Subject: [PATCH net 1/2] bpf, sockmap: Do not ignore orig_len parameter Date: Wed, 2 Mar 2022 08:17:22 -0800 Message-Id: <20220302161723.3910001-1-eric.dumazet@gmail.com> X-Mailer: git-send-email 2.35.1.574.g5d30c73bfb-goog MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: netdev@vger.kernel.org X-Patchwork-Delegate: kuba@kernel.org From: Eric Dumazet Currently, sk_psock_verdict_recv() returns skb->len This is problematic because tcp_read_sock() might have passed orig_len < skb->len, due to the presence of TCP urgent data. This causes an infinite loop from tcp_read_sock() Followup patch will make tcp_read_sock() more robust vs bad actors. Fixes: ef5659280eb1 ("bpf, sockmap: Allow skipping sk_skb parser program") Reported-by: syzbot Signed-off-by: Eric Dumazet Acked-by: John Fastabend Acked-by: Jakub Sitnicki Tested-by: Jakub Sitnicki Acked-by: Daniel Borkmann --- net/core/skmsg.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/net/core/skmsg.c b/net/core/skmsg.c index 8eb671c827f90f1f3d2514163fc82998c9906cb6..929a2b096b04e01b85bff0a69209413abe86102d 100644 --- a/net/core/skmsg.c +++ b/net/core/skmsg.c @@ -1153,7 +1153,7 @@ static int sk_psock_verdict_recv(read_descriptor_t *desc, struct sk_buff *skb, struct sk_psock *psock; struct bpf_prog *prog; int ret = __SK_DROP; - int len = skb->len; + int len = orig_len; /* clone here so sk_eat_skb() in tcp_read_sock does not drop our data */ skb = skb_clone(skb, GFP_ATOMIC); From patchwork Wed Mar 2 16:17:23 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Eric Dumazet X-Patchwork-Id: 12766260 X-Patchwork-Delegate: kuba@kernel.org Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 09917C433EF for ; Wed, 2 Mar 2022 16:17:43 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S241220AbiCBQSY (ORCPT ); Wed, 2 Mar 2022 11:18:24 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:34694 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S241440AbiCBQSS (ORCPT ); Wed, 2 Mar 2022 11:18:18 -0500 Received: from mail-pj1-x1034.google.com (mail-pj1-x1034.google.com [IPv6:2607:f8b0:4864:20::1034]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 0CB5A11A2F; Wed, 2 Mar 2022 08:17:35 -0800 (PST) Received: by mail-pj1-x1034.google.com with SMTP id v4so2202499pjh.2; Wed, 02 Mar 2022 08:17:35 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20210112; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=oub+iKZ2LUr5ud/wkqRk/erUc2bROrYBkUR2gSNDvSg=; b=kWE9GGx2pWlySjXXKxGqXf6V09YM09ZAe1iw+vzNuuAOTkK636oYfutUZDyw+C/Vus eUyk4tY6kEpKze+1MNE42hvv3b9DYuzwXlkonrX8/oZD33keIdusLhKyxkFfpXojRMzq XbhmiO6Oc00raQHEdukkFFrMqY1PMayvI1jL9uuNlD7xmCz8mRmR4DhUvOKTCqPrtqNz KO3hrrsrh1OLkZKkP5Jzd3Kup2VupX6tSGZkJZKqH5S+AjO5NDP+wXsFQQeVPJ3pLkfm FLS2YTLGzwWy+oSPyw6+yv/CBDlg9eqKNOQAuQF+d+Nq3nl25KcLZfg6DZYUTdnWgGPW +goQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=oub+iKZ2LUr5ud/wkqRk/erUc2bROrYBkUR2gSNDvSg=; b=NEgXB4GaTdPvGf6yaZVQPullYb/syWOYbxOSj9T9AtZHe3ApChaZwh1RwlMOEtApSO cyC+h2EUmMGISFKWu3JQF2twoQnyUXPXkm/ijmYMP+nOb7fSkyhs5CseYPpnSJgeuuWr hFXs73UmEOBdkkONpuUiUFoQNlBD6SB9Da2tYfJI7q3Sq2qOBTBWkL9+OCi2s019tRua cvR3nNypZQIP3n/3X6lOVEi1IJpjlNeiz4jY96uim/xEYxI6DThju/qUJLLkPgbYQbei +okZx4HMEA71OrmcfktudpB+KyEVSxzeeG3qOE2Baq3TQHqjK1L2kAN8Qt1QbioceC4p i36A== X-Gm-Message-State: AOAM532HMxjCt4T4WmaZnr1vatAcYjhqdKeyYz3ap4iTYdOX5z2BsYkq D75ZKNQii+eqNoVYxFN/SPA= X-Google-Smtp-Source: ABdhPJyEOlKJIvzdVTV4NumljRsK8W9uPFhd9lAOmPgyLipbBG1nnsvCbz/Wsr//WUpb7I8NQAh9rg== X-Received: by 2002:a17:90b:1104:b0:1b8:b90b:22c7 with SMTP id gi4-20020a17090b110400b001b8b90b22c7mr547182pjb.45.1646237854560; Wed, 02 Mar 2022 08:17:34 -0800 (PST) Received: from edumazet1.svl.corp.google.com ([2620:15c:2c4:201:7e41:847f:4bb0:a922]) by smtp.gmail.com with ESMTPSA id w17-20020a056a0014d100b004f1063290basm21771704pfu.15.2022.03.02.08.17.33 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 02 Mar 2022 08:17:34 -0800 (PST) From: Eric Dumazet To: "David S . Miller" , Jakub Kicinski , Alexei Starovoitov , Daniel Borkmann , John Fastabend Cc: netdev , bpf , Jakub Sitnicki , Andrii Nakryiko , Martin KaFai Lau , Song Liu , Yonghong Song , KP Singh , Eric Dumazet , Neal Cardwell , Eric Dumazet Subject: [PATCH net 2/2] tcp: make tcp_read_sock() more robust Date: Wed, 2 Mar 2022 08:17:23 -0800 Message-Id: <20220302161723.3910001-2-eric.dumazet@gmail.com> X-Mailer: git-send-email 2.35.1.574.g5d30c73bfb-goog In-Reply-To: <20220302161723.3910001-1-eric.dumazet@gmail.com> References: <20220302161723.3910001-1-eric.dumazet@gmail.com> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: netdev@vger.kernel.org X-Patchwork-Delegate: kuba@kernel.org From: Eric Dumazet If recv_actor() returns an incorrect value, tcp_read_sock() might loop forever. Instead, issue a one time warning and make sure to make progress. Signed-off-by: Eric Dumazet Acked-by: John Fastabend Acked-by: Jakub Sitnicki Acked-by: Daniel Borkmann --- net/ipv4/tcp.c | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) diff --git a/net/ipv4/tcp.c b/net/ipv4/tcp.c index 02cb275e5487d98b3e124ee102163aac47b2ad6d..28ff2a820f7c935234e5ab7ecd4ed95fb7c5712a 100644 --- a/net/ipv4/tcp.c +++ b/net/ipv4/tcp.c @@ -1684,11 +1684,13 @@ int tcp_read_sock(struct sock *sk, read_descriptor_t *desc, if (!copied) copied = used; break; - } else if (used <= len) { - seq += used; - copied += used; - offset += used; } + if (WARN_ON_ONCE(used > len)) + used = len; + seq += used; + copied += used; + offset += used; + /* If recv_actor drops the lock (e.g. TCP splice * receive) the skb pointer might be invalid when * getting here: tcp_collapse might have deleted it