From patchwork Mon Feb 12 05:25:09 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jason Xing X-Patchwork-Id: 13552705 X-Patchwork-Delegate: kuba@kernel.org Received: from mail-pg1-f180.google.com (mail-pg1-f180.google.com [209.85.215.180]) (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 177FD6FA7 for ; Mon, 12 Feb 2024 05:25:38 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.215.180 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1707715540; cv=none; b=EfDiqu1mUyuNeBkVM3lAmdk/yUWzxy6iDuxKf2O81/9d2Z+G67Fcd7CulvK5kPmRDzDVoHewOAyeW4Sq7AyF+iT1wlAKEHU4LI+0KgiMmHZeVXC4eBVaALhbNfLCBJMH5gDb2dEBBYhYpjof7ZtLzg8U/2bPo5JbRP0Y9cbGrOw= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1707715540; c=relaxed/simple; bh=JW/5J2iAOjTAEBaHinRWRnzJW3QPBLMKfqS+lcKAHsA=; h=From:To:Cc:Subject:Date:Message-Id:In-Reply-To:References: MIME-Version; b=vBtAf10+XNqpY/g9BsfdNtuzzwAFLwnNr0xrhQmpyVHtWNuUUAoHA6r2CRASX2WSmbaVD7Eu220nfugT6IJmN5Q0xZOM5+y+QSRTU/dQn4gG0wZVZsE6KlezVChPde0OqCQumP6QHcLKEakmBxjmsM8yRsPUOBqilszk7a6Tyl8= 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=mtP+vZAE; arc=none smtp.client-ip=209.85.215.180 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="mtP+vZAE" Received: by mail-pg1-f180.google.com with SMTP id 41be03b00d2f7-5d3907ff128so2328117a12.3 for ; Sun, 11 Feb 2024 21:25:38 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1707715538; x=1708320338; 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=Ic0yF8IFXpCCRvKYAPqREiXbogel5udRXcjEQOQT0fE=; b=mtP+vZAE9ub7oajLko3TbSn9EJXm/YoyXB2xLHI+P1i44/kyWCtl6v7RVPRdeQF6Mo 7fijou79WrxCBPV3ZZsVKfM+Ji2vXhxCDd3tt8pWKsCPjeNedCA6apgWL2DQxgMekX5U RCl5yOjVHqlYgShB+d5mNyojxnwJPaKiSJtAxiyYn86tTHUX2bKTAawh5VTxPiXbB0iX U/gsmlDtNayov+5UqYTigiZ4Syav6YywBtILd/DVPqq8ZnscD4ICrKARNuNMO24GDSdX +iQbhpN7zzJdbLFuCXX5XNjY+j7lLCjAQ5CfhMTbhk90Apzync2g4kRZjRlOdQ1Bod7M 2CKQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1707715538; x=1708320338; 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=Ic0yF8IFXpCCRvKYAPqREiXbogel5udRXcjEQOQT0fE=; b=WWiwQ/B7hl7Q0sMCKnsadqDy1cwrgCWD8z0xtjF5Zn4MgMpn42xC2iNk3hb66XQ2NQ L6trr3D3qwfvTMHJu4SG9xgStmeaCGKDhBum7Uqqd0Wm0lqdXQqrmYx/iHDbsSnqNJqg TGEZoBMn/caALO9ZhYzKXZufp0v2a9oFxtp0JsjLVbOlfu/Y2PX+mC/JlWxwjDfNJm1g s72Nhm8vu9kq0znGM+3F9ga5Kh5u6O1Ebo/Iigieit/hcsiOz0Fs303FoqW8L87g8aHD 4IPNwBT7fpiqlEbCcUpBPtbNwhNQfmRI5umqEj6LQCSgt0q8X/GPRp8YbGT0kbkpVZM5 eZxg== X-Gm-Message-State: AOJu0YwbK5PGjTTVtQkKsA4XwjGgGeiA8W8TKDSGMFY4w82A3RSBvFkR LkBuoRhW27V9sU3SPimzX4fWDnK8OlP/wq2OcSomeAdYzwZwWYew X-Google-Smtp-Source: AGHT+IFiUXdhOpgZBcSVdC41/rJ3q3xARC5/xD5/EKilxb+oWleGQJgJAJCM0vn7f0nUei6RL/xzvA== X-Received: by 2002:a05:6a21:3115:b0:19e:aaa5:7b52 with SMTP id yz21-20020a056a21311500b0019eaaa57b52mr8594551pzb.0.1707715538324; Sun, 11 Feb 2024 21:25:38 -0800 (PST) X-Forwarded-Encrypted: i=1; AJvYcCWckaKR7mfO56bho5FO8+xZSdpYixWfIbTUxbTkT7Hk3LYKJzeDLSvQZojTRwodV3BjxpgTZsN8egoEIj837PkSsBElm433x8e2fHArn58DJStbS2T0wlI62l1gGit9EYtLIALy4rioRH1cW9tKT8FJM57gVqvzm+Ly6qqp/WPAlzAn0HCtJIp4hRDBBjSeMXDKlLPnM613ehO7JJzF8VcIuZH7HyQkZR1cF0ECyOY= Received: from KERNELXING-MB0.tencent.com ([14.108.143.251]) by smtp.gmail.com with ESMTPSA id f10-20020a056a001aca00b006da2aad58adsm4725291pfv.176.2024.02.11.21.25.34 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sun, 11 Feb 2024 21:25:37 -0800 (PST) From: Jason Xing To: davem@davemloft.net, edumazet@google.com, kuba@kernel.org, pabeni@redhat.com, dsahern@kernel.org Cc: netdev@vger.kernel.org, kerneljasonxing@gmail.com, Jason Xing Subject: [PATCH net-next v3 1/5] tcp: add dropreasons definitions and prepare for cookie check Date: Mon, 12 Feb 2024 13:25:09 +0800 Message-Id: <20240212052513.37914-2-kerneljasonxing@gmail.com> X-Mailer: git-send-email 2.33.0 In-Reply-To: <20240212052513.37914-1-kerneljasonxing@gmail.com> References: <20240212052513.37914-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 --- 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..7cedece5dbbb 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_INVALIDDST: look-up dst entry error */ + SKB_DROP_REASON_INVALID_DST, /** * @SKB_DROP_REASON_IP_INADDRERRORS: host unreachable, corresponding to * IPSTATS_MIB_INADDRERRORS From patchwork Mon Feb 12 05:25:10 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jason Xing X-Patchwork-Id: 13552706 X-Patchwork-Delegate: kuba@kernel.org Received: from mail-yb1-f174.google.com (mail-yb1-f174.google.com [209.85.219.174]) (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 143E915AB for ; Mon, 12 Feb 2024 05:25:45 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.219.174 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1707715547; cv=none; b=Vr/Nwa/IB286+T2eImOLrXEBqgm8krrXJCRO0C9Wu80I+50uaqYEDdG6BAknNCCDUkVqtozcSZNZmdOOuqO7Spjyhq/gZ76w24034G2SQCLy/RKo7vU3iwfJ3YtDiSylcwLXBdWvxGUgNVr1GE4Da0QHe5mhrlOSvf2tpnH0jTo= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1707715547; c=relaxed/simple; bh=beTa8kvuVAR1xuuwoOtkmKnK0Wn7xIsrcdGr8CPSjQQ=; h=From:To:Cc:Subject:Date:Message-Id:In-Reply-To:References: MIME-Version; b=jgETQ1uNNxCz3RWZtJx9WFbcIpyxQvwzFchksf8hRQpgj7ZLCKZMX8iKGWC/RWF54KZicd231jfH/vTs84W9vUOS3SslRkCb6XuUfrj8w2NigOQF0sIMoRQyfZO4r+YD5v0aUBaP1/+9YA5MCNj4an9giJ1bQDMB8wc7rAcrqW4= 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=PZ7REjPL; arc=none smtp.client-ip=209.85.219.174 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="PZ7REjPL" Received: by mail-yb1-f174.google.com with SMTP id 3f1490d57ef6-dc6d9a8815fso2822529276.3 for ; Sun, 11 Feb 2024 21:25:45 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1707715545; x=1708320345; 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=PZ7REjPL6R/MYBX/uiiplYc94tEuXVeo/xygO8wbrugcySRJq4dYwbF++0v32x3C8T UWvIMy8f4V8K29NVzN3gk5uYaloYg1302kRWYcGNs3iN6mPivdQWyuJbx9JfdZYw9p+e vVeTxEzq/3eHXLaMZL3V0UNsUVgF0dFVD3Ke6/pxc0/jemrbVQWKMevRL1K8QYTdFflw aguV26j7e3vb83vFLp0XT5VqhiPKtsWJpDpcfB4p8TdGO8siy55CeOfBu3xPoHyZFHYu FlPG+r/JPJCNIM+U/rE06WF8SQlOzbXCBZXfcT7GEXSPaFghKTtxwwjHXaJ1jWZY5Z2H odEw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1707715545; x=1708320345; 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=MqUgoyTNH7NpuHx1VttocZS67wz3puy/xFX3Dtb53yObYOP4oQD2UQnv2e7byiiFDT 2ZZQED6mBHCLFDRyVyS78OGCiPeOScAs2ODvQIWVBbqd6bZjbNSJHP6ajvOehVLz4wNI /rqSfik9X78jmriCDQfdN7MPp241yFch8pjtboMQl6w7sH6ub4fN7ioI614ev5fUyNGm 1OWNX7VoMzC9VePWFBoNtj8HNDbemr+t7CS5gtjIIpU7lKY4UNbeks0QtvkXhh8Umn+o UXd1BUaB4rC0iIHXaIv7pOtWCGEVrZeUoxsmk1U0pHoIEHDxC2GvCFJNg5Sw13u0z9Ae Rm0Q== X-Gm-Message-State: AOJu0YxSlF8pCSTX/No9HvAeGrivDUDfCnoxvjva+qNEYFl1Xj3jFGKH exw7sWmipeamA+aruoGxVmsjPeJ/ZAfYCwFhLkJxM8SwbI39h1vO X-Google-Smtp-Source: AGHT+IFlD+6dRsvXMLmSXUxyNVNsK5ZOfXEyEOWie6NsfyqpkCilbBOnwhXTyFWiSH494gI7mTt+jw== X-Received: by 2002:a25:ef47:0:b0:dc9:51d8:d72c with SMTP id w7-20020a25ef47000000b00dc951d8d72cmr1787092ybm.63.1707715544939; Sun, 11 Feb 2024 21:25:44 -0800 (PST) X-Forwarded-Encrypted: i=1; AJvYcCUil0QBuOcyYMcGMtYplP0v5nEQAJ1hEu+UQJdh8vSJbQOwVU+zkZMqe5id2oEjCT4lAJHe+AieOz2ZyL+rfNozrbn1dGjanZChQjAj48av+so5Nlj4n8hPqt0uwP0E6QOEXx0n8dkhJDHvZ1FJd76acghF2C3+UzA66zfk3lyaTeqocvBIw4nHWOv4/Tvbq46Un+yrzialBrYckGG8GTbrWKUIyBeTiXqgvb9SJrA= Received: from KERNELXING-MB0.tencent.com ([14.108.143.251]) by smtp.gmail.com with ESMTPSA id f10-20020a056a001aca00b006da2aad58adsm4725291pfv.176.2024.02.11.21.25.40 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sun, 11 Feb 2024 21:25:44 -0800 (PST) From: Jason Xing To: davem@davemloft.net, edumazet@google.com, kuba@kernel.org, pabeni@redhat.com, dsahern@kernel.org Cc: netdev@vger.kernel.org, kerneljasonxing@gmail.com, Jason Xing Subject: [PATCH net-next v3 2/5] tcp: directly drop skb in cookie check for ipv4 Date: Mon, 12 Feb 2024 13:25:10 +0800 Message-Id: <20240212052513.37914-3-kerneljasonxing@gmail.com> X-Mailer: git-send-email 2.33.0 In-Reply-To: <20240212052513.37914-1-kerneljasonxing@gmail.com> References: <20240212052513.37914-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 Mon Feb 12 05:25:11 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jason Xing X-Patchwork-Id: 13552707 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 0D2D86FCC for ; Mon, 12 Feb 2024 05:25:51 +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=1707715553; cv=none; b=O9vMcbCRxIcZbqQVJtl9EWzt+OAbQG06qZofHd8slDRBu3kXuB5Ce34hf1zpS+dCyGyReInhke6PDZ///FSyWZKTmPE5vHqNvXMnyPhcFA7ONLkrE0GH2B6ti7M6pVwDUVoOfyMr+8E8HzawbRgGZXROaol0tsCafUbQLzulIrI= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1707715553; c=relaxed/simple; bh=yw9I8eGn8fij3hXGVhqq+QyJ/i6Xtww0dNZKPdMaFzA=; h=From:To:Cc:Subject:Date:Message-Id:In-Reply-To:References: MIME-Version; b=I64ntUBbnB8bX7jw9kGhWl7WFDe+bq5eavP1o+7xO/iCUFjO5VgnTMZiWjYwXzqVcwqUBCN9ryGwIcFsx5m2/t6ZR5MU13PP1sHHDc4V7uBj5Jxf0skxjvHlqOiCkArsfMSgOs6SWfbM+om2xfxLZhi6KPP6IDbaUyNDti4+yFs= 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=Tak9pXDo; 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="Tak9pXDo" Received: by mail-pf1-f179.google.com with SMTP id d2e1a72fcca58-6e0a4823881so569061b3a.0 for ; Sun, 11 Feb 2024 21:25:51 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1707715551; x=1708320351; 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=Tak9pXDoQNFc2u5ZgVzcxzIBlis+OnTMHT7HgVzfTN4U99CtUkzAbpoYUyyW2G8ee/ mfmL07hTj+zmRmCtPG4Sq2AME5UgG0QVZ4qG8ZUbI1WCVUAAGNk9Pifm1xuHRiidf7Q5 UW9YGU39vInbz1jcP2JMwTkMN1rlcG6UvvErLUqmhCNmPio1RVujo3zingapoqp/3UaR 1ogmOUTYlEK7xmU64KHmEMQp6NDljIpcHdH1QEVJeCS47X32QfFxwz/tTDSNh1aKAMuE UHRSIqd1C+S5ndjJQwWO4Gti8PrSF98ff3/UEVxVdItryz4ZQZfVIID3XI2SRgMgz2CK KHxA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1707715551; x=1708320351; 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=LzGmM4kkEAeoktotMcib1n1166c6cmVPIoRS1KpwcxFRSqt9+3Ndf9IHxzLdDJF68n NIzzS16MXJfobdHpTwEzJX2nzKzNofSRaOO/eJEtfbsICk45DKpc6Bu1Yyc10Ki86Zpk oVFdY5EE6PNB5OIhQEcMKB8vb7YMdNtIEAVgeoU7Myg7iCMteJNogeqZfETFhLbRuBsE v+2TAmxkV8ow6kqBRNpg3AgwGLFPReZsC30cxrEVS83/U4IaQnOwMZMPjlSSjbAPSGZb FmyHOLlOPYx9gIcwS4U3oIE4BNHE4jH/G9FI8ZOf6OKkitqUCXHWByXnqMLAOtptmn/D ce6w== X-Gm-Message-State: AOJu0YxvS7djnpnOTFEKMrDZTe/F03CEcdkzJ5K/1p0sWkAgwoGSfT+J pVy6yPAf3HpY1+um40onsjjJ30bM6ld9qoF+E27EbOkm1U083qCJ X-Google-Smtp-Source: AGHT+IHXQZodQpi446ybjhDdvaqQX5tOIYwBDAkL+MLXGW6W3zEAUT5wB25k9ZjPENBxdBmwAjKjSw== X-Received: by 2002:a05:6a00:9384:b0:6e0:9da7:8cfd with SMTP id ka4-20020a056a00938400b006e09da78cfdmr6255176pfb.5.1707715551146; Sun, 11 Feb 2024 21:25:51 -0800 (PST) X-Forwarded-Encrypted: i=1; AJvYcCU0IBdMComcxENuIg95YkFSH3GDFR/PiQg1au1W/v3g2Sn2S5dlIDFDUUkPkOhjU3WkDO2iQfTpERScwSzLusMN2SvXymLuR9pWZbwdKVboEvv8+bjARUkWzNmmc20iXTtb3ZDQCJd1U123UvHBdwGcPfSWrnvjYnGZadpfasA03IDR1xq0YFKxaODwt+sxKzQ8yknxZt/W/kHhR3zUKw5i0qNusNXZjww07dAd8ws= Received: from KERNELXING-MB0.tencent.com ([14.108.143.251]) by smtp.gmail.com with ESMTPSA id f10-20020a056a001aca00b006da2aad58adsm4725291pfv.176.2024.02.11.21.25.47 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sun, 11 Feb 2024 21:25:50 -0800 (PST) From: Jason Xing To: davem@davemloft.net, edumazet@google.com, kuba@kernel.org, pabeni@redhat.com, dsahern@kernel.org Cc: netdev@vger.kernel.org, kerneljasonxing@gmail.com, Jason Xing Subject: [PATCH net-next v3 3/5] tcp: use drop reasons in cookie check for ipv4 Date: Mon, 12 Feb 2024 13:25:11 +0800 Message-Id: <20240212052513.37914-4-kerneljasonxing@gmail.com> X-Mailer: git-send-email 2.33.0 In-Reply-To: <20240212052513.37914-1-kerneljasonxing@gmail.com> References: <20240212052513.37914-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 Mon Feb 12 05:25:12 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jason Xing X-Patchwork-Id: 13552708 X-Patchwork-Delegate: kuba@kernel.org Received: from mail-oo1-f42.google.com (mail-oo1-f42.google.com [209.85.161.42]) (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 DAD3A6FB2 for ; Mon, 12 Feb 2024 05:25:57 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.161.42 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1707715559; cv=none; b=p7QEYg6ITox1bLGr/iAjmvoccZnf0rsr3sdIdjxY1be1e6mBgW4ctR+N2wx0qvFa2CDG+XaUo+M1PWiAcHK+kPcYkG71UCPsRLeMCGt+AsHWFB8dHIaDDI8si2bOgBOf1gn58UIDELwnVSxXxvT5dKyVW+e3lViG4UC39CcMxLE= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1707715559; c=relaxed/simple; bh=eYcG00HxId5qCSyCPor9f11Ao0XyPy9N2cF4K2RNvrE=; h=From:To:Cc:Subject:Date:Message-Id:In-Reply-To:References: MIME-Version; b=MObl5L0A5hrrHaRGovmYl0E7hR7ZmuOa8e0pnwonLRbUoTVKbT/PWKHsBnmjJ5rxphg8lcS3/ykh9CQs79EneHG7kjt8P3GqNgA3B+SibhVjJG9EjDpD+jLME91vPQGA7V/xvkFH3ztgMhucX9qMLTXsP9GnFCzgNp4KNlERaSI= 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=PczQVilX; arc=none smtp.client-ip=209.85.161.42 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="PczQVilX" Received: by mail-oo1-f42.google.com with SMTP id 006d021491bc7-59d11e0b9e1so1834234eaf.1 for ; Sun, 11 Feb 2024 21:25:57 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1707715557; x=1708320357; 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=PczQVilXYNNgYsKvbGyDuBIchOEbz91hlEZID/UndKSEJZtX5iAJ3oGPx+qbEXclLN HcV/pvxFegA2kgGvqc3n4Nz2QHB+X53hRHD70ZUxcug5NKj2a7xT6OMMDDSDaz96dNGm Uwl5RdFtkvniFEAQbGfoKxssZXQePsSfFInpGtf4HPHX8NRYt2giZIwpCUqismx5Aesb cz6lJue9ycYFT6h+k1KS0dQ6RiPnrpVI12S4+1ui4A1jMix2RDZKN/xav9LY+GX+10ZM PHVFn/2bERBfjnn1Vny9XloPBxeGK1xFanxJZmZu88uKtDoBSheva8QnsLcNIMjMQeDx LK/A== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1707715557; x=1708320357; 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=sNxIxOtCP6WA41lm7Hcd+YQJ0UA88zFmWNuZDK0YrBnynCDBbLlceIPTIP9Ce9sCtR ftwfVHOUJ/3vvLUjQ0CaNZ0IzppmYuU/aqPgUSACFh5DNeeM9Zc17WlP3Y885InxKKDV qiZ8U2gd/7d4m/WCMYlZ8Ydl5J8zFhcYIw00GpgKqFBQWg1gVQQQcKwcD5Z8RMgVR8jC /4GtWjm1OuRHdMC6JmdS3+IZiA9Iz9HFe9h1FtNFU2EadsKy6Z+XVWcMGsGUMEGBPOJD wGbNVe4Ycx5C+iRAyM2XHQeLIVGoZQ5tWXdPyXyzRVE0C/SbLTMeFjZaY+gZCqKEejFJ cUqw== X-Gm-Message-State: AOJu0Yx+IP3h4/znbWn4WQ8PYqweZvxy6LOsBfWfnidMZsl/zJ76Bsf5 lqALe428NyOm4z3SL8p7zS59+EnvqGtX5ynX/+Nv154aUirlHn8m X-Google-Smtp-Source: AGHT+IE7nlF781/3cP2AEMQ2hLDiraedSpVUoqd56eiwW3vglDP6ysY2FevRR4ng5fIFkiMbadtMAQ== X-Received: by 2002:a05:6358:d1e:b0:176:5a5e:4d85 with SMTP id v30-20020a0563580d1e00b001765a5e4d85mr7609401rwj.4.1707715556888; Sun, 11 Feb 2024 21:25:56 -0800 (PST) X-Forwarded-Encrypted: i=1; AJvYcCVobU8xSi5DZ2fCttIuBg/JPFbWLqM6rf9HPBxsooUp2p5RTyMBBrejdRahHoxVBs5HuSXvQ+UKOl7YOlaDbN2F6TYsbGGT7/SaKucepn0STUYagb11esvd/PP8otUoJ8ggTsflSLPnfTZyEZ9dUc6A/s7l7e6JjekDemSkFYS0ZlHlrFd2IaBJrEB54d9inj9FExdY3X58BGCYG7apzg4pmcU7FCIZRE2sMCfdISc= Received: from KERNELXING-MB0.tencent.com ([14.108.143.251]) by smtp.gmail.com with ESMTPSA id f10-20020a056a001aca00b006da2aad58adsm4725291pfv.176.2024.02.11.21.25.52 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sun, 11 Feb 2024 21:25:56 -0800 (PST) From: Jason Xing To: davem@davemloft.net, edumazet@google.com, kuba@kernel.org, pabeni@redhat.com, dsahern@kernel.org Cc: netdev@vger.kernel.org, kerneljasonxing@gmail.com, Jason Xing Subject: [PATCH net-next v3 4/5] tcp: directly drop skb in cookie check for ipv6 Date: Mon, 12 Feb 2024 13:25:12 +0800 Message-Id: <20240212052513.37914-5-kerneljasonxing@gmail.com> X-Mailer: git-send-email 2.33.0 In-Reply-To: <20240212052513.37914-1-kerneljasonxing@gmail.com> References: <20240212052513.37914-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 Mon Feb 12 05:25:13 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jason Xing X-Patchwork-Id: 13552709 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 076F35C9A for ; Mon, 12 Feb 2024 05:26:03 +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=1707715564; cv=none; b=moXFtqGxexKFkYEJsslcK2kMtwB0q1Gg3Rvpg7uoaopIBcWlyjaBtw/E0s8Qk19Vr17JANzwC/6OgLnG3qdfmGYpYo00XyUh9EcXPXft+EA8nKqJ04SA8hiuIQlH11nSMZ/i2UHQQUfiv8/YXFloFSepE1rad8d35M9fRYTjiO8= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1707715564; c=relaxed/simple; bh=tBBpCX1d2PEb9XWT8hX3Z997z59wdwOgyuiSWDYJPhI=; h=From:To:Cc:Subject:Date:Message-Id:In-Reply-To:References: MIME-Version; b=qQJlC8UUVdsPhcSaVEOhFsVhC6vAtPEp3wOowptkOpqv/Ox8mK+PRZt4D13JWKzFXjsC+J979R9B12LDXNltl2DW1GklcufXresg3wEMaiEwKHA3CqYTkhYJ2c+FahJDcl5qYho6yUHQdvmGcDCSGGzT3WNfjWHpP3BgnjPgGik= 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=mOEIb8hw; 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="mOEIb8hw" Received: by mail-pf1-f179.google.com with SMTP id d2e1a72fcca58-6e0eacc5078so7638b3a.0 for ; Sun, 11 Feb 2024 21:26:03 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1707715562; x=1708320362; 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=mOEIb8hwyiNaMvH6Ehvv/6w/4kWHG2QsW7CSiczthcUfjSs+nSYn4XZe7L1rs6aKMZ YXbFvDdCBHJegeYl4em73WSz4xKx9t1cwv1/8cqQM4jAFgsrFbEeGAqkwyl+b1Z8wuZk E4YNL5Vycnwd9bqvePK5a3dvOC++drmMksOGZG9Uv1wt1scf2X8SFaAqVoe7dN6JHk/L Ruu3pcptqUk864dPSothW5RoHja7vFio0YOL+XPJnmcZIu2CBx3w5YTJymYb1RImVV61 bIZYr3LTCTD6QLlf0FQKxf0aYzI+OH0LzU32was1AThqTjDvgIu2iUiFb9wvSdND84Ax BVFw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1707715562; x=1708320362; 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=TrOC1ijs1Iw2326AqBXXlF5oxDNv7wTCZcd8gTob2ePh+16AzUggMdHgleJ+FKTzF1 jz0+DzZyEppENTAhhelMxssGzbVz6KxjKlT2VVmyubQMJVExhI7JPEb8Ps7T7HX0Tejy P0Hqon3G1YlMmh5bzYBEQm17R8atJMhYM4Pqqy80kC/U79g/kflooeQh7ENzKc7+k21C j4zON4JuA1yTsZa4Q+CDFFfbGHJajJ5doN782jfaA1PgcQSs65zzF4wUUyhgEq071VWg TgqIXqmo07DF0kLdQitNOMqxkXu1j42PKaWj/tg/VFtMnV0fYIWRHkIxUsAOJhAc9WDt MDDQ== X-Gm-Message-State: AOJu0YzE7xXIpzFeRZuORvpvG8IkG6EyC+s8CHysP0KDX1halRD6leK2 ukLKows76A5XMopei666N/wac8eVuxBlySb3c9oosabx5cYaMKvQ X-Google-Smtp-Source: AGHT+IFvqRu7SNAC7okXsRO/ARAOMnUywAGcAQhYvX9rflP8o8jtKF1qbkc8D3qMyUQ7nyrjUtNrKA== X-Received: by 2002:a05:6a00:1251:b0:6dd:8767:2fa1 with SMTP id u17-20020a056a00125100b006dd87672fa1mr6022979pfi.0.1707715562501; Sun, 11 Feb 2024 21:26:02 -0800 (PST) X-Forwarded-Encrypted: i=1; AJvYcCUH7wPrTZYtxGontbUlAY4XQZ2h8ukOkEVSMbbDYKCG7inK1wNXEdkx9f14Jttf/A0udmITg8VN4kX9JPe3b3949XpniyBBECVf+zeCJVbaJR+cYGJWe1+GwCwmWIcqjDcszdeagkbTGhdqawiRg7jSW6n/N+saLwigHRgCM5TluFGTWt5ZtyvldjVWDof/DXnROsSyE/ThtD+s/7VYcu8wVP0opnybw4LCx+XRYww= Received: from KERNELXING-MB0.tencent.com ([14.108.143.251]) by smtp.gmail.com with ESMTPSA id f10-20020a056a001aca00b006da2aad58adsm4725291pfv.176.2024.02.11.21.25.58 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sun, 11 Feb 2024 21:26:02 -0800 (PST) From: Jason Xing To: davem@davemloft.net, edumazet@google.com, kuba@kernel.org, pabeni@redhat.com, dsahern@kernel.org Cc: netdev@vger.kernel.org, kerneljasonxing@gmail.com, Jason Xing Subject: [PATCH net-next v3 5/5] tcp: use drop reasons in cookie check for ipv6 Date: Mon, 12 Feb 2024 13:25:13 +0800 Message-Id: <20240212052513.37914-6-kerneljasonxing@gmail.com> X-Mailer: git-send-email 2.33.0 In-Reply-To: <20240212052513.37914-1-kerneljasonxing@gmail.com> References: <20240212052513.37914-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: