Received: from n169-110.mail.139.com (n169-110.mail.139.com [120.232.169.110]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 2E9D537AA71 for ; Thu, 26 Feb 2026 11:48:24 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=120.232.169.110 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1772106509; cv=none; b=MPH6JjxXhtYflVG3SW4iujKDSmyhv4zAQr4vvRJz+FUatzMu5mJRY1Ncwjrv3gx7gXXoGkrf49g+wLhoQaKl5zDY4tHGIXba+UAFi6ycW354aBLJR5AZqbBknAMfQ+gqlY1MOYn79GbuyhdwmeSpcbh6qpLN9FVr+qezDV6ecag= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1772106509; c=relaxed/simple; bh=ydIPhacnom3AyCd9ZFOC5uuzuo+0sR2C54ifALnosLM=; h=From:To:Cc:Subject:Date:Message-ID:MIME-Version; b=cSy1725I2GD1+a5ziJ+cWgDIh1p9NP+t+M3xcVno4YabFoaqNwgVuuqMVghFeLtX8+Q7KGwABGHnGgmd/XgIis2p7pdKibAZUY2qoB0N08XkQwsKzQC/uPNpaz0GTK1xlGkOyVPc7CNaGjqnSW6MgRSJ47nMElhfuKo8cKrUwdY= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dmarc=none (p=none dis=none) header.from=139.com; spf=pass smtp.mailfrom=139.com; dkim=pass (1024-bit key) header.d=139.com header.i=@139.com header.b=h//j+8QP; arc=none smtp.client-ip=120.232.169.110 Authentication-Results: smtp.subspace.kernel.org; dmarc=none (p=none dis=none) header.from=139.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=139.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=139.com header.i=@139.com header.b="h//j+8QP" DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=139.com; s=dkim; l=0; h=from:subject:message-id:to:cc:mime-version; bh=47DEQpj8HBSa+/TImW+5JCeuQeRkm5NMpJWZG3hSuFU=; b=h//j+8QPMhWjVu8IPOCO+JhdoifUCOU+mj8wLF+kjZQhfqPsjw/6uiM6Ak+Lo69XS9btyEHQn73P1 DUZCC7e6ndfgcnrBq6XCkCsPOtcwLJl/H89ZKDddKURQpuaddPlqx4F5F7bSxG/arjxqSNJxgUNtqM RcOtfkzXTT2JjXVc= X-RM-TagInfo: emlType=0 X-RM-SPAM: X-RM-SPAM-FLAG:00000000 Received:from ubuntu24.corp.ad.wrs.com (unknown[120.244.194.215]) by rmsmtp-lg-appmail-04-12082 (RichMail) with SMTP id 2f3269a032ff8ac-18017; Thu, 26 Feb 2026 19:48:18 +0800 (CST) X-RM-TRANSID:2f3269a032ff8ac-18017 From: Bin Lan To: gregkh@linuxfoundation.org, stable@vger.kernel.org Cc: Eric Dumazet , Jakub Kicinski , Bin Lan Subject: [PATCH 5.15.y 1/2] net: add skb_header_pointer_careful() helper Date: Thu, 26 Feb 2026 19:48:09 +0800 Message-ID: <20260226114810.4142-1-lanbincn@139.com> X-Mailer: git-send-email 2.43.0 Precedence: bulk X-Mailing-List: stable@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: 8bit From: Eric Dumazet [ Upstream commit 13e00fdc9236bd4d0bff4109d2983171fbcb74c4 ] This variant of skb_header_pointer() should be used in contexts where @offset argument is user-controlled and could be negative. Negative offsets are supported, as long as the zone starts between skb->head and skb->data. Signed-off-by: Eric Dumazet Link: https://patch.msgid.link/20260128141539.3404400-2-edumazet@google.com Signed-off-by: Jakub Kicinski [ Adjust context ] Signed-off-by: Bin Lan --- include/linux/skbuff.h | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/include/linux/skbuff.h b/include/linux/skbuff.h index a8d6e976507e..24ceeab1b509 100644 --- a/include/linux/skbuff.h +++ b/include/linux/skbuff.h @@ -3869,6 +3869,18 @@ skb_header_pointer(const struct sk_buff *skb, int offset, int len, void *buffer) skb_headlen(skb), buffer); } +/* Variant of skb_header_pointer() where @offset is user-controlled + * and potentially negative. + */ +static inline void * __must_check +skb_header_pointer_careful(const struct sk_buff *skb, int offset, + int len, void *buffer) +{ + if (unlikely(offset < 0 && -offset > skb_headroom(skb))) + return NULL; + return skb_header_pointer(skb, offset, len, buffer); +} + /** * skb_needs_linearize - check if we need to linearize a given skb * depending on the given device features. -- 2.43.0