From patchwork Tue Feb 13 13:42:01 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jason Xing X-Patchwork-Id: 13555121 X-Patchwork-Delegate: kuba@kernel.org Received: from mail-pf1-f179.google.com (mail-pf1-f179.google.com [209.85.210.179]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 63CDA56770 for ; Tue, 13 Feb 2024 13:42:33 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.210.179 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1707831754; cv=none; b=cBC1M6tOJUAAGK9cV7tYX1sgepgnXffYzlL14LGsO80Qfd1GddOHrE922r6X75Lmxlcyn1wMPZ6Dp84O+aBftFgAtFYYOCpxRRhNN1jWzdwv8m0IVBg5X0AaIRIu95BsvNfm+9PDN7em/L0jvih84mWJmnAx0P0p2rc8PsDIT+o= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1707831754; c=relaxed/simple; bh=lNpztHeIhP+vU/AniXahwg6keOcyHVunVsd8/2UgXGA=; h=From:To:Cc:Subject:Date:Message-Id:In-Reply-To:References: MIME-Version; b=P/w3kOdKk6KC31rJLB3kWAox7yYrAkR3cwwUxm/EvjDU5uLiGktXOFX8gT0ZyWc23iZHXpWzxt/aeWBVM5lw7jA2XnIf6bfv8S0fpm8jZX7fh8uc1wLMB0eNdmI2mKR1dwznlw6KLqFCa4H/trt0hjdaYGWDNvlBK1xKXcl7SiY= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com; spf=pass smtp.mailfrom=gmail.com; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b=STj3DJm0; arc=none smtp.client-ip=209.85.210.179 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=gmail.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b="STj3DJm0" Received: by mail-pf1-f179.google.com with SMTP id d2e1a72fcca58-6e0ac91e1e9so1776745b3a.3 for ; Tue, 13 Feb 2024 05:42:33 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1707831753; x=1708436553; darn=vger.kernel.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=ZayGKMf3TQ9OEvyTjyQA0cAKI964OfzpOO+MSIxTKs8=; b=STj3DJm07SwpgOrVYz1r6ft0cnV25/MfN+XItVyiusJwdKv2bn5IGDPwfuq7O3HVlI L18vWIghDwzSDtLopFQDiulT7NKnunUbiWf7dsu+4BAxNygaRfggExC4ndw5XmZ+RyoQ IJzwTtF85zQ095uC2AIeOGzE+iYJCU+DiAK4G00CWR6kA6aVqHYXVuoiK40s/3zWcOGr IdfGutNsENVGlqeQIG3oxbBgQWfndrRhbdG0cftrYA/JWqmzUfvwH6C5+Py+xqBNRCoN Txp7YxRZwXaNqOhCdLlV54BY7xnnb+3YTQlLBLxzdJKBzl9g8tvXoDZq/Dgizflx5qvX p2WQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1707831753; x=1708436553; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=ZayGKMf3TQ9OEvyTjyQA0cAKI964OfzpOO+MSIxTKs8=; b=SCHu9cwNgl0FJC1kWJFkAuX1hzB7MdOZcHLD3aRtOGk+UaJaODODejYrFW5KTI8QuN V3XSk+XWYRXOj23VCy/pbrXQcv6FOpDHtG+vC5mTcG3y8FzFdXiJ/iz7v8SA3evNDAmd q5xq+Z/fuvpR/1CedG4RJW7okQ8z0RnjqoBGB5oi4akSyLkeOpykujL4LrYUldK0JzyH TTyshJM7+s4fe3kaV2/FScRnhUVINHqHxmwj6FeLiovAsFQyLg315Zs4Sm4lk47FGZpv D9lYf220VCgd8L76mqOUqpMGzZ2um/2Ub1xK8nEmR8tQ38WNhrXCgnTchJmOhJcrrCqR yy6Q== X-Gm-Message-State: AOJu0YzabLVW5ZbnBvJt7B8Ao8XzNrewjKFjNT3kxPdPHBdtQzey3qUZ ekZqQFr5wPZ8UUr2iE3p57D9lnhkPb2AOdjDG2BBfxi6favQU7o1wZ7EiGb36rE= X-Google-Smtp-Source: AGHT+IGc5uCa1qtjQlxhgyP2/Cw6OZmlZW5RnBS3ZXEGjNLlO2OsrEUHa5NKA1PBsQvLv+okSpkIJg== X-Received: by 2002:a05:6a21:8ccc:b0:19e:9af8:40e3 with SMTP id ta12-20020a056a218ccc00b0019e9af840e3mr8857973pzb.16.1707831752620; Tue, 13 Feb 2024 05:42:32 -0800 (PST) X-Forwarded-Encrypted: i=1; AJvYcCXSqB1Nca69wbVoQp1t48Cer29iDLwXPLwLuZT4HQ9hCijLRCqQLgJjoeHFK9H1zICe3u9VzqdwK2hTQoNFOXkA5f6Sy6Z2VtCLiYrOaOsfMS/a5niqsGgHKsSAiDjQ4XcMOaOB+U0L0KmIN7t5+kf/AA11L0RnxyImg1sLwfQu1oUTe35Ruq2gF22ZWRj2ZYf+QZCnZ4sjLr0SWQ5VBxAl9JpSLT45qLwv3zx6cKraWHYIxuRElyrD6+fwqh5xp/we Received: from KERNELXING-MB0.tencent.com ([14.108.143.251]) by smtp.gmail.com with ESMTPSA id fa3-20020a056a002d0300b006e042e15589sm7323041pfb.133.2024.02.13.05.42.28 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 13 Feb 2024 05:42:32 -0800 (PST) From: Jason Xing To: davem@davemloft.net, edumazet@google.com, kuba@kernel.org, pabeni@redhat.com, dsahern@kernel.org, kuniyu@amazon.com Cc: netdev@vger.kernel.org, kerneljasonxing@gmail.com, Jason Xing Subject: [PATCH net-next v4 1/5] tcp: add dropreasons definitions and prepare for cookie check Date: Tue, 13 Feb 2024 21:42:01 +0800 Message-Id: <20240213134205.8705-2-kerneljasonxing@gmail.com> X-Mailer: git-send-email 2.33.0 In-Reply-To: <20240213134205.8705-1-kerneljasonxing@gmail.com> References: <20240213134205.8705-1-kerneljasonxing@gmail.com> Precedence: bulk X-Mailing-List: netdev@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 X-Patchwork-Delegate: kuba@kernel.org From: Jason Xing Only add five drop reasons to detect the condition of skb dropped in cookie check for later use. Signed-off-by: Jason Xing --- v2 Link: https://lore.kernel.org/netdev/20240212172302.3f95e454@kernel.org/ 1. fix misspelled name in kdoc as Jakub said --- include/net/dropreason-core.h | 21 +++++++++++++++++++++ 1 file changed, 21 insertions(+) diff --git a/include/net/dropreason-core.h b/include/net/dropreason-core.h index 6d3a20163260..065caba42b0b 100644 --- a/include/net/dropreason-core.h +++ b/include/net/dropreason-core.h @@ -6,6 +6,7 @@ #define DEFINE_DROP_REASON(FN, FNe) \ FN(NOT_SPECIFIED) \ FN(NO_SOCKET) \ + FN(NO_REQSK_ALLOC) \ FN(PKT_TOO_SMALL) \ FN(TCP_CSUM) \ FN(SOCKET_FILTER) \ @@ -43,10 +44,12 @@ FN(TCP_FASTOPEN) \ FN(TCP_OLD_ACK) \ FN(TCP_TOO_OLD_ACK) \ + FN(COOKIE_NOCHILD) \ FN(TCP_ACK_UNSENT_DATA) \ FN(TCP_OFO_QUEUE_PRUNE) \ FN(TCP_OFO_DROP) \ FN(IP_OUTNOROUTES) \ + FN(IP_ROUTEOUTPUTKEY) \ FN(BPF_CGROUP_EGRESS) \ FN(IPV6DISABLED) \ FN(NEIGH_CREATEFAIL) \ @@ -54,6 +57,7 @@ FN(NEIGH_QUEUEFULL) \ FN(NEIGH_DEAD) \ FN(TC_EGRESS) \ + FN(SECURITY_HOOK) \ FN(QDISC_DROP) \ FN(CPU_BACKLOG) \ FN(XDP) \ @@ -71,6 +75,7 @@ FN(TAP_TXFILTER) \ FN(ICMP_CSUM) \ FN(INVALID_PROTO) \ + FN(INVALID_DST) \ FN(IP_INADDRERRORS) \ FN(IP_INNOROUTES) \ FN(PKT_TOO_BIG) \ @@ -107,6 +112,11 @@ enum skb_drop_reason { SKB_DROP_REASON_NOT_SPECIFIED, /** @SKB_DROP_REASON_NO_SOCKET: socket not found */ SKB_DROP_REASON_NO_SOCKET, + /** + * @SKB_DROP_REASON_NO_REQSK_ALLOC: request socket allocation failed + * probably because of no available memory for now + */ + SKB_DROP_REASON_NO_REQSK_ALLOC, /** @SKB_DROP_REASON_PKT_TOO_SMALL: packet size is too small */ SKB_DROP_REASON_PKT_TOO_SMALL, /** @SKB_DROP_REASON_TCP_CSUM: TCP checksum error */ @@ -243,6 +253,11 @@ enum skb_drop_reason { SKB_DROP_REASON_TCP_OLD_ACK, /** @SKB_DROP_REASON_TCP_TOO_OLD_ACK: TCP ACK is too old */ SKB_DROP_REASON_TCP_TOO_OLD_ACK, + /** + * @SKB_DROP_REASON_COOKIE_NOCHILD: no child socket in cookie mode + * reason could be the failure of child socket allocation + */ + SKB_DROP_REASON_COOKIE_NOCHILD, /** * @SKB_DROP_REASON_TCP_ACK_UNSENT_DATA: TCP ACK for data we haven't * sent yet @@ -254,6 +269,8 @@ enum skb_drop_reason { SKB_DROP_REASON_TCP_OFO_DROP, /** @SKB_DROP_REASON_IP_OUTNOROUTES: route lookup failed */ SKB_DROP_REASON_IP_OUTNOROUTES, + /** @SKB_DROP_REASON_IP_ROUTEOUTPUTKEY: route output key failed */ + SKB_DROP_REASON_IP_ROUTEOUTPUTKEY, /** * @SKB_DROP_REASON_BPF_CGROUP_EGRESS: dropped by BPF_PROG_TYPE_CGROUP_SKB * eBPF program @@ -271,6 +288,8 @@ enum skb_drop_reason { SKB_DROP_REASON_NEIGH_DEAD, /** @SKB_DROP_REASON_TC_EGRESS: dropped in TC egress HOOK */ SKB_DROP_REASON_TC_EGRESS, + /** @SKB_DROP_REASON_SECURITY_HOOK: dropped due to security HOOK */ + SKB_DROP_REASON_SECURITY_HOOK, /** * @SKB_DROP_REASON_QDISC_DROP: dropped by qdisc when packet outputting ( * failed to enqueue to current qdisc) @@ -333,6 +352,8 @@ enum skb_drop_reason { * such as a broadcasts ICMP_TIMESTAMP */ SKB_DROP_REASON_INVALID_PROTO, + /** @SKB_DROP_REASON_INVALID_DST: look-up dst entry error */ + SKB_DROP_REASON_INVALID_DST, /** * @SKB_DROP_REASON_IP_INADDRERRORS: host unreachable, corresponding to * IPSTATS_MIB_INADDRERRORS From patchwork Tue Feb 13 13:42:02 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jason Xing X-Patchwork-Id: 13555122 X-Patchwork-Delegate: kuba@kernel.org Received: from mail-pf1-f175.google.com (mail-pf1-f175.google.com [209.85.210.175]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 580EC56469 for ; Tue, 13 Feb 2024 13:42:39 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.210.175 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1707831760; cv=none; b=JOQXI6RbH2QoWjTlOjkICBbMWpyM+WbKwB734Z0/YDiSX08/oBK+OMhGKqqkrUzq2O016P2MJrxwei6fzga4L4cI5FI33wy+pWkLGrvOMNutRFvlUsHpYcNoUmi3UjzryCPnm858S+Mc+9V9rms15MHsXZi0E9AitO9HmsKsGHg= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1707831760; c=relaxed/simple; bh=beTa8kvuVAR1xuuwoOtkmKnK0Wn7xIsrcdGr8CPSjQQ=; h=From:To:Cc:Subject:Date:Message-Id:In-Reply-To:References: MIME-Version; b=NP0ftC7/UdxQ/MwyXQg2K1m1PzQ1cX3p4ycqUmK8/58cWnfgei5SwtB6iyqILc+cCsRiu0lI1YohzwXq9NL9wRCx/IGmwN8c4IHwDK/2gwYkmmm1xr7LGNw0SRQ5upsbJfnzvfpEkzIA76h/ZgWfjm2XWovQAn3ohmYZ0S2Q6vE= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com; spf=pass smtp.mailfrom=gmail.com; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b=fKXh3ffD; arc=none smtp.client-ip=209.85.210.175 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=gmail.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b="fKXh3ffD" Received: by mail-pf1-f175.google.com with SMTP id d2e1a72fcca58-6e0dcf0a936so1056456b3a.0 for ; Tue, 13 Feb 2024 05:42:39 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1707831758; x=1708436558; darn=vger.kernel.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=UiHRSiDQCWhkRJWyWtx70sVdTRuKjyaav9BVyuxi7cY=; b=fKXh3ffD+IAyykMZq57xpefc6s3dd5g62ChJUFasxFEKMWWGYiGPfSBwKRImuDu/B+ nqhKgianxBrxgXsThPdzLk5ERuKtEbaMH3SKhP6wVT9gTCu96py/xtQwyy1hFLS/a4Bj z30uPOzNr70LsV0CWzHYYmT8xizQuHPQW5XpSMLBDHeavmmVfnI1UR5qJ9ikMRGimOZE 4o1Byjpj9sP5x6GUZWbTowv47xCvhducuokQitCTRM880y18K51rUnAOx44fkYrQFmJP iyXS1RztvXzyB/DbIrzEw6JnR1DZvRXkxoDlH6pjWv3Pd+B0Jl6kUH7oSWYm9DuzujgF J6zw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1707831758; x=1708436558; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=UiHRSiDQCWhkRJWyWtx70sVdTRuKjyaav9BVyuxi7cY=; b=XIc1C9zVSAwI5xBnnmHgKvtM5oj9p6AvAU6EW5BhSbn6vGXW2scNux6f3LUpZnSTVU ZRlTuPuROaK6ndhmD8lAwH8VWQ/YcImZo2/XYTnn4jreDM1tEovOXUOpw8Uc+zjm3pci m1os40aDJpzRB+63yiKYgv8EEdzgRiAzUmcZBXXQC9wqeRzdbyukZt9tSXfNEi2L+DW8 d/NmOtxIEwZFncidX+jxzxr23s1J/8/v2gTYRNzEL5vkWV9w6yXLbUryaYbzsGWgwbpY m64dUTEZs113+5i7yx15HzEbW6Jx44nGn0OcLLrgjbNZUpDr9DHZsotV3HOJgCSlt/+r 4byQ== X-Gm-Message-State: AOJu0Ywi6thEOeW6Q+9hwQWorqK04mXJ2ISQVvmt+6vAd65YoVbpNvKv vs1HnUIN3H0y53l3Pr0wqsTB+MDZZI9whSTPKEHUwpufIEYYkKJ5 X-Google-Smtp-Source: AGHT+IFL+I8JQdX4Nm0I0xRU89aCCRBFUN+VfKPg0jli3Jhh7gASrBfVrypvaFA/UGPYi8Kw9xt90w== X-Received: by 2002:a05:6a00:1394:b0:6e0:4e0f:62a8 with SMTP id t20-20020a056a00139400b006e04e0f62a8mr3446952pfg.2.1707831758563; Tue, 13 Feb 2024 05:42:38 -0800 (PST) X-Forwarded-Encrypted: i=1; AJvYcCU8BAGSWh9y5v/bH/d3rIvh3B1fBcwlMVb6gkvmrmdSUtjk2aYfGLG4aRXLNtdHvLhzo+U9X04c+CPNb/wwmwPew5c0Z3NCjLDcgyntXhv6CsMj7PM8Htyy7EWlXPBp1Rbf+dxiCVTnySjOI1+F+t2YV3NTqMBbul6ufzwec+lRj3DziFsl10aUIWf845fuN7fMLQ3EiwJ5kFh/oZ7v6ee59p8j2uK6x140LEfGlJTNt9I8m1ejBYn/NmgMOGAcJRQt Received: from KERNELXING-MB0.tencent.com ([14.108.143.251]) by smtp.gmail.com with ESMTPSA id fa3-20020a056a002d0300b006e042e15589sm7323041pfb.133.2024.02.13.05.42.33 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 13 Feb 2024 05:42:38 -0800 (PST) From: Jason Xing To: davem@davemloft.net, edumazet@google.com, kuba@kernel.org, pabeni@redhat.com, dsahern@kernel.org, kuniyu@amazon.com Cc: netdev@vger.kernel.org, kerneljasonxing@gmail.com, Jason Xing Subject: [PATCH net-next v4 2/5] tcp: directly drop skb in cookie check for ipv4 Date: Tue, 13 Feb 2024 21:42:02 +0800 Message-Id: <20240213134205.8705-3-kerneljasonxing@gmail.com> X-Mailer: git-send-email 2.33.0 In-Reply-To: <20240213134205.8705-1-kerneljasonxing@gmail.com> References: <20240213134205.8705-1-kerneljasonxing@gmail.com> Precedence: bulk X-Mailing-List: netdev@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 X-Patchwork-Delegate: kuba@kernel.org From: Jason Xing Only move the skb drop from tcp_v4_do_rcv() to cookie_v4_check() itself, no other changes made. It can help us refine the specific drop reasons later. Signed-off-by: Jason Xing --- net/ipv4/syncookies.c | 4 ++++ net/ipv4/tcp_ipv4.c | 2 +- 2 files changed, 5 insertions(+), 1 deletion(-) diff --git a/net/ipv4/syncookies.c b/net/ipv4/syncookies.c index be88bf586ff9..38f331da6677 100644 --- a/net/ipv4/syncookies.c +++ b/net/ipv4/syncookies.c @@ -408,6 +408,7 @@ struct sock *cookie_v4_check(struct sock *sk, struct sk_buff *skb) struct rtable *rt; __u8 rcv_wscale; int full_space; + SKB_DR(reason); if (!READ_ONCE(net->ipv4.sysctl_tcp_syncookies) || !th->ack || th->rst) @@ -477,10 +478,13 @@ struct sock *cookie_v4_check(struct sock *sk, struct sk_buff *skb) */ if (ret) inet_sk(ret)->cork.fl.u.ip4 = fl4; + else + goto out_drop; out: return ret; out_free: reqsk_free(req); out_drop: + kfree_skb_reason(skb, reason); return NULL; } diff --git a/net/ipv4/tcp_ipv4.c b/net/ipv4/tcp_ipv4.c index 0c50c5a32b84..0a944e109088 100644 --- a/net/ipv4/tcp_ipv4.c +++ b/net/ipv4/tcp_ipv4.c @@ -1915,7 +1915,7 @@ int tcp_v4_do_rcv(struct sock *sk, struct sk_buff *skb) struct sock *nsk = tcp_v4_cookie_check(sk, skb); if (!nsk) - goto discard; + return 0; if (nsk != sk) { if (tcp_child_process(sk, nsk, skb)) { rsk = nsk; From patchwork Tue Feb 13 13:42:03 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jason Xing X-Patchwork-Id: 13555123 X-Patchwork-Delegate: kuba@kernel.org Received: from mail-oo1-f43.google.com (mail-oo1-f43.google.com [209.85.161.43]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 01E175646C for ; Tue, 13 Feb 2024 13:42:44 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.161.43 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1707831766; cv=none; b=X/dUIJRDDxjbgg0jMe4UXHb6Z7v5XxG4Iwlk+e0UD4WfpNtv5YjCNSeJFxbxkUHX5xnb/w91dbuG17Du6uk1WMvtVK4SkRA5ycusUM7hAkblmR8L88tnqEqVURau+3+sgZUQwS9OhUBJRroR9VQx95m0bWayEim/cK37wBiwPws= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1707831766; c=relaxed/simple; bh=yw9I8eGn8fij3hXGVhqq+QyJ/i6Xtww0dNZKPdMaFzA=; h=From:To:Cc:Subject:Date:Message-Id:In-Reply-To:References: MIME-Version; b=l5iU4pZ2CgdeD/3jWlkJoblXqDpg7Cj6mfvT0aJlDnDfRUe69slZBG/HgpL4A31iRnLal1DP55UVcoOq17bOF9v7hZa2TlPLsH0oi3isXxoCjOBVgcB+JfHXIAH5143TXd64DHDjdDLmg9XvFQJY2+ieKLcN+KD2bAdZVjBCcno= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com; spf=pass smtp.mailfrom=gmail.com; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b=KblNF2r3; arc=none smtp.client-ip=209.85.161.43 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=gmail.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b="KblNF2r3" Received: by mail-oo1-f43.google.com with SMTP id 006d021491bc7-59d84559ffdso315eaf.0 for ; Tue, 13 Feb 2024 05:42:44 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1707831764; x=1708436564; darn=vger.kernel.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=gCokI4QitffRE95xC4BZDly8mc3aT2cSBYL5RktaTi8=; b=KblNF2r3TVfjs7sHtnhe7h0mRhAPM05DrbkejkDQ5DSfdbI3lA7L9/q++OI1uxJDzz aVZHiUd2T3TgCQwpHA+D4qFaqE6O6wMr9+FDM5p9NmPThgIsILJd15RuuGzUQLl2+ply W4ckE4JeBREwiKFTlp05MzAv4/E+so95dnnPspKYg/uuHyROocAZHEKXz3Szc2xGwAOt J3/oOHPnGJsVpwFBbEgwLZxN9AGiIefc+krbU0IYXrLwDLVbeRFfov698hkUkskHAQTr GTcgcilqCGzTOu3B6sFoWEG5NHjq8JxVvn005+mUqjkvqLwVLl+KwnYZsluURTZG2pFe bwsA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1707831764; x=1708436564; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=gCokI4QitffRE95xC4BZDly8mc3aT2cSBYL5RktaTi8=; b=eMjfXe6kuOIT3Mg6MVyOvTSvuKzTndZJBJrlaS9Xxw8VXrae9xgUN7DiiRcDDCJdtC 41mswV2Eq1InEL2PPkEONweRkcuzSVmjcX27UWIES3XXDWlwZUSlY4x4JQC+UAIXfrvx +fc73VYQb18ZOLN1V4c/7JrTAERI9dPr2zHMKjQuxxowxG2kwwn1dkW3jKm21I0VYabX YlOW8ZVvXOkiC72Q7EzE1zETdLa007Z6beGnXz/A60e8Psfdz7o+QziY6qaTVjG5Woy/ srh0wpF9NCQD1fzDNeEpAsbUPZLqErp/OeSMD0ERenkYNbnjJFSBJX51VxRFbFdE7VHO QR4g== X-Gm-Message-State: AOJu0YxnI1SGelJdT9UKT8IwwGh/vBqPjRyMgGGi6vGkb01oDoBr1dC3 Rs4CFtkjYR/QBual4sDQ2fy6qJZ+WMtct2CUOdzuXi1IhxsUcAjM X-Google-Smtp-Source: AGHT+IE2IjzwVX6uCT+J9St0CuIB8KnSOoCVQcbaIR8sHteR+p8NG2GRmcByYLMA3kNGpKkAZpweZg== X-Received: by 2002:a05:6358:5985:b0:178:76f8:e626 with SMTP id c5-20020a056358598500b0017876f8e626mr14081051rwf.6.1707831764060; Tue, 13 Feb 2024 05:42:44 -0800 (PST) X-Forwarded-Encrypted: i=1; AJvYcCWeZAt72NtoejavccIFHQJXO/Dd7snq2VWvmYhxCLTkdiMTVJLj5XK6o1/RpS4w8AI04g9AfMt41xS5oVdn/SbJjva7doZcbqiLqvMxl5ZBGakPwhaPicD4jfC1XN6B3dksggl3qB6ZVzKRBRs9Rpun+GBiO20ui3aiH8YS4JfVOe40h+6Bo31oQXZYeq/n/XvAnh+Nd82iNRCKKxzgh5mFkJ+T+dXnFKVsxSh+1K/x/S9fA/infTc9OHSrk4IBKeaT Received: from KERNELXING-MB0.tencent.com ([14.108.143.251]) by smtp.gmail.com with ESMTPSA id fa3-20020a056a002d0300b006e042e15589sm7323041pfb.133.2024.02.13.05.42.39 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 13 Feb 2024 05:42:43 -0800 (PST) From: Jason Xing To: davem@davemloft.net, edumazet@google.com, kuba@kernel.org, pabeni@redhat.com, dsahern@kernel.org, kuniyu@amazon.com Cc: netdev@vger.kernel.org, kerneljasonxing@gmail.com, Jason Xing Subject: [PATCH net-next v4 3/5] tcp: use drop reasons in cookie check for ipv4 Date: Tue, 13 Feb 2024 21:42:03 +0800 Message-Id: <20240213134205.8705-4-kerneljasonxing@gmail.com> X-Mailer: git-send-email 2.33.0 In-Reply-To: <20240213134205.8705-1-kerneljasonxing@gmail.com> References: <20240213134205.8705-1-kerneljasonxing@gmail.com> Precedence: bulk X-Mailing-List: netdev@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 X-Patchwork-Delegate: kuba@kernel.org From: Jason Xing Now it's time to use the prepared definitions to refine this part. Four reasons used might enough for now, I think. Signed-off-by: Jason Xing --- net/ipv4/syncookies.c | 18 +++++++++++++----- 1 file changed, 13 insertions(+), 5 deletions(-) diff --git a/net/ipv4/syncookies.c b/net/ipv4/syncookies.c index 38f331da6677..07e201cc3d6a 100644 --- a/net/ipv4/syncookies.c +++ b/net/ipv4/syncookies.c @@ -421,8 +421,10 @@ struct sock *cookie_v4_check(struct sock *sk, struct sk_buff *skb) if (IS_ERR(req)) goto out; } - if (!req) + if (!req) { + SKB_DR_SET(reason, NO_REQSK_ALLOC); goto out_drop; + } ireq = inet_rsk(req); @@ -434,8 +436,10 @@ struct sock *cookie_v4_check(struct sock *sk, struct sk_buff *skb) */ RCU_INIT_POINTER(ireq->ireq_opt, tcp_v4_save_options(net, skb)); - if (security_inet_conn_request(sk, skb, req)) + if (security_inet_conn_request(sk, skb, req)) { + SKB_DR_SET(reason, SECURITY_HOOK); goto out_free; + } tcp_ao_syncookie(sk, skb, req, AF_INET); @@ -452,8 +456,10 @@ struct sock *cookie_v4_check(struct sock *sk, struct sk_buff *skb) ireq->ir_loc_addr, th->source, th->dest, sk->sk_uid); security_req_classify_flow(req, flowi4_to_flowi_common(&fl4)); rt = ip_route_output_key(net, &fl4); - if (IS_ERR(rt)) + if (IS_ERR(rt)) { + SKB_DR_SET(reason, IP_ROUTEOUTPUTKEY); goto out_free; + } /* Try to redo what tcp_v4_send_synack did. */ req->rsk_window_clamp = tp->window_clamp ? :dst_metric(&rt->dst, RTAX_WINDOW); @@ -476,10 +482,12 @@ struct sock *cookie_v4_check(struct sock *sk, struct sk_buff *skb) /* ip_queue_xmit() depends on our flow being setup * Normal sockets get it right from inet_csk_route_child_sock() */ - if (ret) + if (ret) { inet_sk(ret)->cork.fl.u.ip4 = fl4; - else + } else { + SKB_DR_SET(reason, COOKIE_NOCHILD); goto out_drop; + } out: return ret; out_free: From patchwork Tue Feb 13 13:42:04 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jason Xing X-Patchwork-Id: 13555124 X-Patchwork-Delegate: kuba@kernel.org Received: from mail-pf1-f173.google.com (mail-pf1-f173.google.com [209.85.210.173]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 8303F5647D for ; Tue, 13 Feb 2024 13:42:51 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.210.173 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1707831772; cv=none; b=IzxLbalIPEXOGy+IczmwasmX8Om7H9HgTn3mP8rAxvyV49YAtjN0pK7CfQaXl/GmlHli235f0hYQ18Sziip/5/tnMTlC8fqRMHk0DuqyE9SlZxtLBInDDGWjzbc/2xsjNHhGjQAnAzI+mtKiOBpZ+6XVlYUGgTuZAHrP4o+WWg8= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1707831772; c=relaxed/simple; bh=eYcG00HxId5qCSyCPor9f11Ao0XyPy9N2cF4K2RNvrE=; h=From:To:Cc:Subject:Date:Message-Id:In-Reply-To:References: MIME-Version; b=DpdVeoKthH7iIjo0T9UwVge5d7dJty1YUFFe5zoxQ16S4FY2sGYfc2xlEHieWNtpldq3l9u04OXygr+toRur/ZO0NswzVt/An9EybZouFsgzVVk9BovW4eqaDRJmTWnN8tfkTH1CSj1X6t0f9h9Vs2//+rZLUPaRyAI2Q2e4g/4= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com; spf=pass smtp.mailfrom=gmail.com; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b=EFoIPTJf; arc=none smtp.client-ip=209.85.210.173 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=gmail.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b="EFoIPTJf" Received: by mail-pf1-f173.google.com with SMTP id d2e1a72fcca58-6e104a8e3f7so98966b3a.1 for ; Tue, 13 Feb 2024 05:42:51 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1707831771; x=1708436571; darn=vger.kernel.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=qrkG6KKFmZqUyW8+kFpwqVtyXKxWI4aCH2q1MB9xVcU=; b=EFoIPTJfjVcFg4f3+giaZy1pHAbIhOukDFUUPQ5SBbPGDiJ5zTQoGzZMd1NAEmgfuY YVPjwyKxQo3FsOB9R9PxANZqXrWZlvH0BYgoPu99Wy0qaL2jQcLgLWo9GJIdDFzg0As0 jXgzRrbNouuRca9zNgNk/hva5oxd3w5To67mwyTqRgU7xV3/f9b0PtBe8Bz7O4hpAGkh 0vkqXDmXniqv2QJwb1L0h0VWG4v3FhwAnv5BAes9CFHyW10bjrH5cbdVG1mJGX535T5W PFEE1BfIcQRtm/Wvqa1DS+BnI3jpjjjPkuFth2wHMMp+Koe/gdiJ9SzUnAUJybOOVgz/ J9GA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1707831771; x=1708436571; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=qrkG6KKFmZqUyW8+kFpwqVtyXKxWI4aCH2q1MB9xVcU=; b=ZZ73O4GEtnOyCKGhDe2ZIeJM8wkPsF2GqCQgeebaID+udJTusCNuSTejg8EUlNDkC6 5FgQSZ5Fy+Q7FfIMFYTABPci3XTjq8IkaPF+fJtNxWw/pmnz10LsXEvSiGu10+UXlC/n 7hp9pQYHqesW0e+5T0djaMswZJe5modCcQcsf0nyv9dDDQED3YvQXeMYwPyCpebw4Q95 7zm6wGsQOZZ6TU+26DVqM5qWCm+8OKFykqBC2DNTui9BXoNbqz7tkv5UVCdSO850NwN4 C8/n8PJK+HkzQBx0jZwG8b4xWCWHvf+2kY744EEXzMwV+KneOj1luT3UnGj04667R/At 8h2A== X-Gm-Message-State: AOJu0YzBGt27rn7c1XjkFJYoJ13qyTNxCQHu5DthAjPoDynKZZtE/81M jqUxv/w0m/UdKNjvxjuzxFoW3NKFcMJF4H/KEU7+mfeNKgy1IAi4 X-Google-Smtp-Source: AGHT+IGfGSAQA8fQBr3tk+yI6SHsYMnloJi+62+yFZo78NX9/+NGeK36WEP5z0ttonQQ5Aczom5lcw== X-Received: by 2002:a05:6a00:b4e:b0:6e0:4717:7a0d with SMTP id p14-20020a056a000b4e00b006e047177a0dmr12842688pfo.5.1707831770778; Tue, 13 Feb 2024 05:42:50 -0800 (PST) X-Forwarded-Encrypted: i=1; AJvYcCU7pheFsA5tRaDABZWbzMaxkgM777Zq6oG4Ms0XCmtLFOcFFnnXit9XPuLlkc8D7wdwgXvrEKXK+1yXxeCn7sW98pFPnQDnW3CK35fkz3EUClY3UeCL+0HxWYfjJw3GN0megEN59PhpkQD2H3ePt+UksajPkhhhn4KGrqPPjsipoAeTyd/8xcf3ugslO7TFLTgWSHwGK3xTpCyYuoTX1TV92yTOxaaXRFxHA0eIc2kRpR6b5cHqw8pVOGFASzj4D0Dn Received: from KERNELXING-MB0.tencent.com ([14.108.143.251]) by smtp.gmail.com with ESMTPSA id fa3-20020a056a002d0300b006e042e15589sm7323041pfb.133.2024.02.13.05.42.45 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 13 Feb 2024 05:42:49 -0800 (PST) From: Jason Xing To: davem@davemloft.net, edumazet@google.com, kuba@kernel.org, pabeni@redhat.com, dsahern@kernel.org, kuniyu@amazon.com Cc: netdev@vger.kernel.org, kerneljasonxing@gmail.com, Jason Xing Subject: [PATCH net-next v4 4/5] tcp: directly drop skb in cookie check for ipv6 Date: Tue, 13 Feb 2024 21:42:04 +0800 Message-Id: <20240213134205.8705-5-kerneljasonxing@gmail.com> X-Mailer: git-send-email 2.33.0 In-Reply-To: <20240213134205.8705-1-kerneljasonxing@gmail.com> References: <20240213134205.8705-1-kerneljasonxing@gmail.com> Precedence: bulk X-Mailing-List: netdev@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 X-Patchwork-Delegate: kuba@kernel.org From: Jason Xing Like previous patch does, only moving skb drop logical code to cookie_v6_check() for later refinement. Signed-off-by: Jason Xing --- net/ipv6/syncookies.c | 4 ++++ net/ipv6/tcp_ipv6.c | 7 +++++-- 2 files changed, 9 insertions(+), 2 deletions(-) diff --git a/net/ipv6/syncookies.c b/net/ipv6/syncookies.c index 6b9c69278819..ea0d9954a29f 100644 --- a/net/ipv6/syncookies.c +++ b/net/ipv6/syncookies.c @@ -177,6 +177,7 @@ struct sock *cookie_v6_check(struct sock *sk, struct sk_buff *skb) struct sock *ret = sk; __u8 rcv_wscale; int full_space; + SKB_DR(reason); if (!READ_ONCE(net->ipv4.sysctl_tcp_syncookies) || !th->ack || th->rst) @@ -256,10 +257,13 @@ struct sock *cookie_v6_check(struct sock *sk, struct sk_buff *skb) ireq->ecn_ok &= cookie_ecn_ok(net, dst); ret = tcp_get_cookie_sock(sk, skb, req, dst); + if (!ret) + goto out_drop; out: return ret; out_free: reqsk_free(req); out_drop: + kfree_skb_reason(skb, reason); return NULL; } diff --git a/net/ipv6/tcp_ipv6.c b/net/ipv6/tcp_ipv6.c index 57b25b1fc9d9..27639ffcae2f 100644 --- a/net/ipv6/tcp_ipv6.c +++ b/net/ipv6/tcp_ipv6.c @@ -1653,8 +1653,11 @@ int tcp_v6_do_rcv(struct sock *sk, struct sk_buff *skb) if (sk->sk_state == TCP_LISTEN) { struct sock *nsk = tcp_v6_cookie_check(sk, skb); - if (!nsk) - goto discard; + if (!nsk) { + if (opt_skb) + __kfree_skb(opt_skb); + return 0; + } if (nsk != sk) { if (tcp_child_process(sk, nsk, skb)) From patchwork Tue Feb 13 13:42:05 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jason Xing X-Patchwork-Id: 13555126 X-Patchwork-Delegate: kuba@kernel.org Received: from mail-pf1-f176.google.com (mail-pf1-f176.google.com [209.85.210.176]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 12E8256B65 for ; Tue, 13 Feb 2024 13:42:56 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.210.176 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1707831778; cv=none; b=QTkxLH18RKY1KWBZTGkJfGUfJlZ3nKonvFAtHx4I5T/Q5xYuEgzEsebkaeOSxLMxnMfaMiEXUC6vBz/1s75CaZUhh1QIAMGg7EpRYqZxmgdk1wtnlKQTniNSKwn9URwG43AS1DQpN9KFXkFRfRNuc+dZZp1Ac/4xxRpck+3bTQw= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1707831778; c=relaxed/simple; bh=tBBpCX1d2PEb9XWT8hX3Z997z59wdwOgyuiSWDYJPhI=; h=From:To:Cc:Subject:Date:Message-Id:In-Reply-To:References: MIME-Version; b=a8Exrnz6iD/rY2+iRbVdTs7/PTHCubDS5/Gvmve7YIGd6/Ztej01C3MfBiqJ2RJiFzALwm4bHpB5R/Shlogs+bD8nGsWN64uZYz6F70eB28lSfi6TofuBbGY9YMBXcnzEL9OA5c2OhMsAZDhyT+0Ibfvf3wNEqjUNchl+4U6wBs= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com; spf=pass smtp.mailfrom=gmail.com; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b=NuL4YeWv; arc=none smtp.client-ip=209.85.210.176 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=gmail.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b="NuL4YeWv" Received: by mail-pf1-f176.google.com with SMTP id d2e1a72fcca58-6e06c06c0f6so3078141b3a.0 for ; Tue, 13 Feb 2024 05:42:56 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1707831776; x=1708436576; darn=vger.kernel.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=UcnR3wwRFZ0uVl2rER3U5hYQXkGCv0h0x2STc3oL9yU=; b=NuL4YeWv9qvxZs/hgwD4UzPN4Y0iIse42zGQ3apqLwDwrtNeWPkgrWGp7BgAyfmBHW GM5CUiQPSJn5opmz9oSuJMXbcv8qfMDhwP7/Wlx7TFWlUdqnb2piwfE8CiVKjnrMQEa6 S+hlx7dIehlJtXL1hb2xLTGXY4RcGyRsz34Qb6ZqqPtUE7i8NLLU/wo94V9wQJAsX3IJ WPfwMcuZBJA9/T20+urVpRCpQmUTaQQMic5pZShFWNSTIP3ZypCKyAh4ICNyNFJrzM7/ dIbce+MIGYFonOE9z9eIcOmLnWbG2XCNrkCS2BIOqhl1xyu7vvn8uslKwTQDyKUZRPSu wiHg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1707831776; x=1708436576; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=UcnR3wwRFZ0uVl2rER3U5hYQXkGCv0h0x2STc3oL9yU=; b=LGKzcpcvKBJv+ghz8hZxdzDZkXgSuk4+to/Xn4eAQPR/lPrLAohZ3a8Rz1wHVYGhHf EtoRevcm7XaS+6uISrRgUsIKTJodPROBmjqTsAlnKSiw3ZgVQpbK7nwR2OJRhvSNYCAb 0gX3DPCohqswDiFgi/F8UJmpHS05ZqJ/lgZ4zjTP6oIbStS3sBRX1ByG6BWvPnXdOl1W VRx5M7apPjKpGSUTzz0Dfr6LZJkebvP3BIigNk/Jt0aGFKyWFRydA6EpYuUic4ajSgC1 1xkQWw6fxtz3oUMTf1LOGJrHTXUIbT9OOQqF0WS32xZNMjyFSpojCnU7CJIDq1wZWMQh NMpw== X-Gm-Message-State: AOJu0YwNMmK2I4oLPl2Q1eY5PNvj2MGKy6N0+Oy8gVR0lNY07kvyo5ZG qVkbSIAshYZRC4ocrhy38RKInkYGe2FSVRCfH2gpARPsvd5PtlPo X-Google-Smtp-Source: AGHT+IF7O3zLSQa0oaAcD7XybobgNwL90vUAT1P0QCfqroPWUs7uGP5n+kL5RP1ITbb5UpyWV4vBlg== X-Received: by 2002:a05:6a20:9585:b0:19e:5e0c:3bb8 with SMTP id iu5-20020a056a20958500b0019e5e0c3bb8mr4177752pzb.7.1707831776463; Tue, 13 Feb 2024 05:42:56 -0800 (PST) X-Forwarded-Encrypted: i=1; AJvYcCWoBvygFNmKUjykj1h+8lesQ2cYYpd9EqyG+BhFDka0+HCe5fvdhgIGTUxMdzc43qjfvQ0IOiIjynSiZMt0XPngAaFYVLAaev0kwEOeBiVsb7YFG8Nwk4yFpgKTpUUBFYNDqNrjes7enEjm50UFAbuCSxiIJDUVekZCKvhSpfut4uHIIm2rFFxUd5u9Vec4BBlzxhDJHtOpAPL3KDEiq1/dxbX7KiXs/LIViFGLm4hhFcqMx7r0qeH5ZRbPLZ5Ugtg6 Received: from KERNELXING-MB0.tencent.com ([14.108.143.251]) by smtp.gmail.com with ESMTPSA id fa3-20020a056a002d0300b006e042e15589sm7323041pfb.133.2024.02.13.05.42.52 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 13 Feb 2024 05:42:55 -0800 (PST) From: Jason Xing To: davem@davemloft.net, edumazet@google.com, kuba@kernel.org, pabeni@redhat.com, dsahern@kernel.org, kuniyu@amazon.com Cc: netdev@vger.kernel.org, kerneljasonxing@gmail.com, Jason Xing Subject: [PATCH net-next v4 5/5] tcp: use drop reasons in cookie check for ipv6 Date: Tue, 13 Feb 2024 21:42:05 +0800 Message-Id: <20240213134205.8705-6-kerneljasonxing@gmail.com> X-Mailer: git-send-email 2.33.0 In-Reply-To: <20240213134205.8705-1-kerneljasonxing@gmail.com> References: <20240213134205.8705-1-kerneljasonxing@gmail.com> Precedence: bulk X-Mailing-List: netdev@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 X-Patchwork-Delegate: kuba@kernel.org From: Jason Xing Like what I did to ipv4 mode, refine this part: adding more drop reasons for better tracing. Signed-off-by: Jason Xing --- net/ipv6/syncookies.c | 16 ++++++++++++---- 1 file changed, 12 insertions(+), 4 deletions(-) diff --git a/net/ipv6/syncookies.c b/net/ipv6/syncookies.c index ea0d9954a29f..f5d7c91abe74 100644 --- a/net/ipv6/syncookies.c +++ b/net/ipv6/syncookies.c @@ -190,16 +190,20 @@ struct sock *cookie_v6_check(struct sock *sk, struct sk_buff *skb) if (IS_ERR(req)) goto out; } - if (!req) + if (!req) { + SKB_DR_SET(reason, NO_REQSK_ALLOC); goto out_drop; + } ireq = inet_rsk(req); ireq->ir_v6_rmt_addr = ipv6_hdr(skb)->saddr; ireq->ir_v6_loc_addr = ipv6_hdr(skb)->daddr; - if (security_inet_conn_request(sk, skb, req)) + if (security_inet_conn_request(sk, skb, req)) { + SKB_DR_SET(reason, SECURITY_HOOK); goto out_free; + } if (ipv6_opt_accepted(sk, skb, &TCP_SKB_CB(skb)->header.h6) || np->rxopt.bits.rxinfo || np->rxopt.bits.rxoinfo || @@ -236,8 +240,10 @@ struct sock *cookie_v6_check(struct sock *sk, struct sk_buff *skb) security_req_classify_flow(req, flowi6_to_flowi_common(&fl6)); dst = ip6_dst_lookup_flow(net, sk, &fl6, final_p); - if (IS_ERR(dst)) + if (IS_ERR(dst)) { + SKB_DR_SET(reason, INVALID_DST); goto out_free; + } } req->rsk_window_clamp = tp->window_clamp ? :dst_metric(dst, RTAX_WINDOW); @@ -257,8 +263,10 @@ struct sock *cookie_v6_check(struct sock *sk, struct sk_buff *skb) ireq->ecn_ok &= cookie_ecn_ok(net, dst); ret = tcp_get_cookie_sock(sk, skb, req, dst); - if (!ret) + if (!ret) { + SKB_DR_SET(reason, COOKIE_NOCHILD); goto out_drop; + } out: return ret; out_free: