From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from mail-ed2-f35.google.com (mail-ed2-f35.google.com [74.125.228.99]) (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 116333B14DE for ; Mon, 21 Sep 2026 22:07:58 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=74.125.228.99 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1790028480; cv=none; b=R9wUftpN/JQAb9gRBsPdog6BC7y3g52QmuKZp9G2Auk82bYcrOO52NTF/bU7S65Gnw9SICpiCVqhaPcZOOXm1I/Y/GXVNZUjQs0UYuUyjpthk9SUq90+Pj2nTDlO8MNxpBj9ZPuzj3kBaivcGesGPJGrK4z0XjJNgUN+MEI4VEw= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1790028480; c=relaxed/simple; bh=ddn3hw42wG26XWdsFpmJBgiUOAHN1Wosbj+AD/5UoQ4=; h=Message-ID:Date:MIME-Version:Subject:To:Cc:References:From: In-Reply-To:Content-Type; b=NX4wH/ngv+rvDlir4u8Z/TKek88PK8LDV8NdK/5l99ZZQ5OUrU65astmeL1cXaqcxRaoqR4YtJ3Cd27FsJbXRsVb0QnU/ADDMO0MkzD64LUtaOLNAm9oRa1xYBNZseMdxthxMYZ9H77Ub0+QcNdgEFgBv1HuTkFHgX5KXyts0Qw= 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=S5hdUmUp; arc=none smtp.client-ip=74.125.228.99 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="S5hdUmUp" Received: by mail-ed2-f35.google.com with SMTP id 4fb4d7f45d1cf-6aa06e51bc3so5719104a12.2 for ; Mon, 21 Sep 2026 15:07:58 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20251104; t=1790028477; x=1790633277; darn=vger.kernel.org; h=content-transfer-encoding:content-type:in-reply-to:from :content-language:references:cc:to:subject:user-agent:mime-version :date:message-id:from:to:cc:subject:date:message-id:reply-to :content-type; bh=C1pgNsBmK2/dFKUlz3XZGd+vlj9HEQ93howCfc/y5AE=; b=S5hdUmUpEolJFbB9H0nwC75SIF2fFegeM/odLBRgUfeB+/5iMrVZIffDL3DW83K9Np my9cLVhpyEZH3cvwaJj4Qqc/2hGOD/sPn8yxc5s3TVNA2JcqXjnNOyhxL56KRIpkOFuz G3tQsrEdO1StXys0UPjsIZPYJL0OXf3P6N08qXtL9uAxNOjjDtcngCd5UudGziraMP8E GjiGaKRLH0d9rlWzAf2jc0rVoaG3vCuFeoqhLO3usIrg6g+t9VbM6D3qOkZeLAMUgT2W QykGWtj8d7eZqn1BQQ1f1Rv6E9K/Bkj213yPD2iA3Zq0EhkdHBmC02JjMdIQjAczA5jl BP4Q== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20260707; t=1790028477; x=1790633277; h=content-transfer-encoding:content-type:in-reply-to:from :content-language:references:cc:to:subject:user-agent:mime-version :date:message-id:x-gm-gg:x-gm-message-state:from:to:cc:subject:date :message-id:reply-to:content-type; bh=C1pgNsBmK2/dFKUlz3XZGd+vlj9HEQ93howCfc/y5AE=; b=0WbcoI3JjD0arCRaF+4nYdxDnECU3At7Y9LmCAY01fQ10tRwGoZ9SeTJMHAs/r3UmY 5f0DJGNGIbOEy58Eb/ayzIieJVnMoUjPDRvcuaUcV4LYIW/6efK2gyUslwmlogF7yHVF 18chrLvJI5AYNsnNNhNtuppaVgYlLQrjUQ4q2BbUTL2ThSb70tDXTpRbAd7UYsQiWQ9/ Fm6elxm6g012NBYlB+ZkqWGW52qG0/tuBS1QeMkRZcVbdQ0i10nxsFsdSZhOI+9AL9Kr iNmO8TRIh7Mk6hW1Hk1qJho62Zo3gVhqItzyQhq1sY1dCSpoeixr8YK6NT+JOfY854XI Fuuw== X-Forwarded-Encrypted: i=1; AKwUvBxUwCfSaXrkzADFSsbkXbemCQnVc1J7SDuSU5kLJNhP7lmNZwwniu+UHwss+/Xzc4YgjioSPd1K7aglxlo=@vger.kernel.org X-Gm-Message-State: AFuF++muXKqLg4oB0VdE/2Wp76XiEp5z3JuIWI3uecMnmLx6IRwBqcw1 lY7fJdUCeI3KfU19xAIgF9Rr39i3qzadX3Omy2wctgOE79O3rN7Ny6gY X-Gm-Gg: AYBFou2gcOW+7He7rLYIUcFn8V9LPGZHEcbtT4AXa5Hr3ZPT+vy8R6jd1Z6rEgMca+K Bcfl9IIo1Ba9StxXvGUS3f/9QuCX7t7dDHo/xiEGNeKetLz51GrR8CWUc/CfVTDGnSEQFI965Fy DqVpsphBxrcrKPQraNQGT/m2lFOjZsBsQ95Qk1nopNK1WzfRg3BtPqflp8a+4pAIl+TC1bk7yRW GEL4668lJhpl4au1MF80KchdHTaQTtJrpKlxtzSuCNfsIfn94dS62mkEQG5l/xrecuBFjQEMmCF j80rFuUJU47UHKGTEiPm5R636rex/C29YZO3Nc8yB9r3lX1TbdyUFmkk8Qurwexl75y5QYILCUC fBldLE6ScMbGAJISrhZPoQRM3+MMuylC8MgjmPxEra49VbF8QUY84JqYIBvqtUH+6AIn1zXB282 f+aptoOZQBi84eKdStM7IhtHcECjxKdl/0GBsXQsDAvEPdL2a6+IIeL+vsahO1NAjAq1t7eeklo +J8ckc6T9ivx12cAcqQIk7Qv/HyeuUMrsFeuIZBpWLDpUcjsDwc X-Received: by 2002:a05:6402:24c9:b0:6aa:2:97b5 with SMTP id 4fb4d7f45d1cf-6aa56890b40mr7853797a12.32.1790028477306; Mon, 21 Sep 2026 15:07:57 -0700 (PDT) Received: from ?IPV6:2a02:a03f:a75e:9a00:f474:15bf:74b7:bee4? ([2a02:a03f:a75e:9a00:f474:15bf:74b7:bee4]) by smtp.gmail.com with ESMTPSA id 4fb4d7f45d1cf-6aaa0f7bfe8sm282195a12.2.2026.09.21.15.07.56 (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Mon, 21 Sep 2026 15:07:56 -0700 (PDT) Message-ID: <6a083020-71d5-4302-8eef-af4c99d2ee81@gmail.com> Date: Tue, 22 Sep 2026 00:07:56 +0200 Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 User-Agent: Mozilla Thunderbird Subject: Re: [PATCH net v2] ipv6: sr: enforce exact attribute length for SEG6_ATTR_DST To: Hui Peng , Andrea Mayer , "David S . Miller" , Eric Dumazet , Jakub Kicinski , Paolo Abeni Cc: Hangbin Liu , Simon Horman , David Lebrun , netdev@vger.kernel.org, linux-kernel@vger.kernel.org, stable@vger.kernel.org References: <20260921044025.1535982-1-benquike@gmail.com> Content-Language: en-US From: Justin Iurman In-Reply-To: <20260921044025.1535982-1-benquike@gmail.com> Content-Type: text/plain; charset=UTF-8; format=flowed Content-Transfer-Encoding: 7bit On 9/21/26 06:40, Hui Peng wrote: > In seg6_genl_policy, SEG6_ATTR_DST is defined with .type = NLA_BINARY and > .len = sizeof(struct in6_addr). For NLA_BINARY, .len only enforces the > maximum payload length and permits shorter payloads (e.g., 0 bytes). > When seg6_genl_set_tunsrc() copies sizeof(struct in6_addr) bytes via > kmemdup(val, sizeof(*val), GFP_KERNEL), a short SEG6_ATTR_DST attribute > triggers a 16-byte out-of-bounds read past skb->tail into uninitialized > skb->head memory, which is stored in sdata->tun_src and leaked back to > userspace via SEG6_CMD_GET_TUNSRC. > > Switch SEG6_ATTR_DST in seg6_genl_policy to > NLA_POLICY_EXACT_LEN(sizeof(struct in6_addr)) so that generic netlink > validation rejects any attribute whose length is not exactly > sizeof(struct in6_addr) with -ERANGE. > > Tested in QEMU against Linux 7.3.0-rc3 by sending a SEG6_CMD_SET_TUNSRC > Generic Netlink message with a 0-byte SEG6_ATTR_DST attribute followed > by SEG6_CMD_GET_TUNSRC. On the unfixed kernel, SEG6_CMD_SET_TUNSRC > succeeds (err = 0) and SEG6_CMD_GET_TUNSRC leaks 16 bytes of > uninitialized kernel heap memory (tun_src = > 836a61ecc4d25a1042a8d60411cfb378); with this patch applied, > SEG6_CMD_SET_TUNSRC is rejected by netlink policy validation with > -ERANGE (-34) and tun_src remains zeroed. > > Fixes: 915d7e5e5930 ("ipv6: sr: add code base for control plane support of SR-IPv6") > Cc: stable@vger.kernel.org > Assisted-by: LLM > Signed-off-by: Hui Peng > --- > Changes in v2: > - Drop the redundant nla_len(info->attrs[SEG6_ATTR_DST]) != > sizeof(struct in6_addr) check in seg6_genl_set_tunsrc() since > NLA_POLICY_EXACT_LEN() in seg6_genl_policy already enforces the exact > length, as pointed out by Hangbin Liu. > > net/ipv6/seg6.c | 4 ++-- > 1 file changed, 2 insertions(+), 2 deletions(-) > > diff --git a/net/ipv6/seg6.c b/net/ipv6/seg6.c > index 62a7eb779202..8c2b156c227a 100644 > --- a/net/ipv6/seg6.c > +++ b/net/ipv6/seg6.c > @@ -138,8 +138,8 @@ void seg6_icmp_srh(struct sk_buff *skb, struct inet6_skb_parm *opt) > static struct genl_family seg6_genl_family; > > static const struct nla_policy seg6_genl_policy[SEG6_ATTR_MAX + 1] = { > - [SEG6_ATTR_DST] = { .type = NLA_BINARY, > - .len = sizeof(struct in6_addr) }, > + [SEG6_ATTR_DST] = > + NLA_POLICY_EXACT_LEN(sizeof(struct in6_addr)), > [SEG6_ATTR_DSTLEN] = { .type = NLA_S32, }, > [SEG6_ATTR_HMACKEYID] = { .type = NLA_U32, }, > [SEG6_ATTR_SECRET] = { .type = NLA_BINARY, }, Reviewed-by: Justin Iurman