Article View: linux.kernel.netdev
Article #8420Re: [PATCH net v2] cipso_v4: fail the walk on malformed options
From: Paul Moore
Date: Thu, 29 Oct 2026 01:11
Date: Thu, 29 Oct 2026 01:11
73 lines
15483 bytes
15483 bytes
On Tue, Oct 27, 2026 at 7:16 AM <omniameasunt@proton.me> wrote:
>
> cipso_v4_get_actual_opt_len() walks a compacted IP option buffer with no
> validation of the option it is standing on: it reads data[iter + 1]
> without checking that the length byte is inside the buffer, it accepts a
> zero length byte (spinning forever), and it never clamps the walked
> offset to len, so the returned length can exceed the 40-byte MAX_IPOPTLEN
> bound that every caller assumes.
>
> After cipso_v4_delopt() memmove-compacts a socket's options, the bytes
> past the compacted region are stale and attacker-controlled via
> setsockopt(IP_OPTIONS). An unprivileged user (CAP_NET_RAW in a user
> namespace, CIPSO labeling configured) can trigger the walk with
> connect(AF_UNSPEC), which reaches cipso_v4_sock_delattr() through the
> SELinux NetLabel hook. The poisoned optlen is later used in
> do_ip_getsockopt(), where it causes
>
> * an out-of-bounds read of the adjacent heap object copied back to
> userspace (kernel pointer disclosure, KASLR defeat), and
> * a stack buffer overflow when optlen exceeds the 60-byte scratch
> buffer (return-address overwrite; exploitable for privilege
> escalation on kernels built without stack protector).
>
> The same helper is also called from cipso_v4_skbuff_delattr() when a
> label is removed from output or forwarded packets; the option bytes there
> have already been validated by ip_options_compile(), so the new checks
> are defensive for that caller.
>
> Fix the defects by making the walk fail with -EINVAL as soon as an
> option header is truncated or malformed (length byte missing, zero, or
> one) or an option would run past len. cipso_v4_delopt() then drops the
> socket's entire option set (reusing the existing branch that frees the
> ip_options_rcu when CIPSO was the only option), and
> cipso_v4_skbuff_delattr() leaves a malformed packet unchanged instead
> of rewriting its header based on untrustworthy bytes.
>
> Well-formed option streams are unaffected: a socket whose options
> survive the compaction intact keeps them; only malformed streams now
> lose all options instead of carrying a partially parsed set.
>
> The function also compacted the option object in place while the
> ip_options_rcu remained published. Lockless readers such as
> getsockopt(IP_OPTIONS), UDP sendmsg(), raw sendmsg(), and ping sendmsg()
> copy the object under rcu_read_lock(), so they can observe a mixture of
> old and new offsets or option bytes. Build the compacted object in a
> replacement ip_options_rcu, modify only the replacement, publish it with
> rcu_assign_pointer(), and retire the old object with kfree_rcu(). If the
> replacement cannot be allocated, leave the old object untouched and
> return -ENOMEM.
>
> Fixes: 014ab19a69c3 ("selinux: Set socket NetLabel based on connection endpoint")
> Signed-off-by: Lucas Dupré--Rabinovici <omniameasunt@proton.me>
> ---
> Previous version:
> https://lore.kernel.org/netdev/CBLsHx48w8Bn1k_Xg6kJFliLNkxLCqi8SnkifapxYYpVtll4w-W_2JJePtbk9ssIS701IFJvi0Q2n5l-2GFFe8hNHU9Y_CgD_sdzcAbILVA=@proton.me/
Hi Lucas,
Thanks again for your help with this.
Qihang (added to the CC line) independently reported, and has been
working on a fix for some of the issues Sashiko identified in your
first patchset. I expect that Qihang will be posting their patch
publicly very soon, perhaps you can take a look once it is posted? I
suspect that basing your patch on top of Qihang's patch may simplify
some things.
--
paul-moore.com
Technical Details
Message-ID:
<CAHC9VhSNfn1=Ln3NcMC1BzW4AQiZuDvTm+H5rkY1aKc-RcKHpw@mail.gmail.com>Path:
mbox-mo1.pugleaf.net!archive.usenet.blueworldhosting.com!usenet.blueworldhosting.com!diablo1.usenet.blueworldhosting.com!usenet.network!.POSTED!vger.kernel.org!netdev+bounces-353113-linux-kernel-netdev=dewy.ruReferences:
<uOcTaW7-g5e97ng6BG_DcH5mlMnpw7KzU25SZjL69pkAVINTMiL26FryLAuYPSNowDo8qwfb9hm_I4dQ1BwpiRe62E-I2TyUkJZ_eBeuLoo=@proton.me>Show Full Headers
Complete Article Headers
Path: mbox-mo1.pugleaf.net!archive.usenet.blueworldhosting.com!usenet.blueworldhosting.com!diablo1.usenet.blueworldhosting.com!usenet.network!.POSTED!vger.kernel.org!netdev+bounces-353113-linux-kernel-netdev=dewy.ru
From: paul@paul-moore.com (Paul Moore)
Newsgroups: linux.kernel.netdev
Subject: Re: [PATCH net v2] cipso_v4: fail the walk on malformed options
Date: Wed, 28 Oct 2026 21:11:04 -0400
Organization: Usenet Network
Message-ID: <CAHC9VhSNfn1=Ln3NcMC1BzW4AQiZuDvTm+H5rkY1aKc-RcKHpw@mail.gmail.com>
References: <uOcTaW7-g5e97ng6BG_DcH5mlMnpw7KzU25SZjL69pkAVINTMiL26FryLAuYPSNowDo8qwfb9hm_I4dQ1BwpiRe62E-I2TyUkJZ_eBeuLoo=@proton.me>
MIME-Version: 1.0
Content-Type: text/plain; charset="UTF-8"
Content-Transfer-Encoding: quoted-printable
Injection-Info: usenet.network;
logging-data="1907782"; mail-complaints-to="abuse@usenet.network"
Cancel-Lock: sha1:QmVbsNvZ58rKdxP6opmJqDr/+Qg= sha256:nCHxrRuYzBt1Zjsfq2u/Zsel8Le+n3bKMTToghj7Dew=
sha1:fQPQ/eJNF0xSZiN2Zjxn0fq5ZkA= sha256:p+E7AwghdKppQN7xUUUaRm9s3OtNKne5bxeQf+9gA+g=
List-ID: <netdev.vger.kernel.org>
X-Mailpost-Empty-Hdrs: X-Spam-Level
X-Received: from localhost (localhost [127.0.0.1])
by mail.dewy.ru (Postfix) with ESMTP id E6C05125C51; Thu, 29 Oct 2026 04:13:16 +0300 (MSK)
X-Virus-Scanned: Debian amavisd-new at usenet.network
X-Spam-Flag: NO
X-Spam-Score: -3.049
X-Spam-Status: No, score=-3.049 tagged_above=-9999 required=6.31
tests=[DCC_REPUT_70_89=0.1, DKIM_SIGNED=0.1, DKIM_VALID=-0.1,
DKIM_VALID_AU=-0.1, HEADER_FROM_DIFFERENT_DOMAINS=0.25,
MAILING_LIST_MULTI=-1, RCVD_IN_DNSWL_MED=-2.3, SPF_HELO_NONE=0.001,
SPF_PASS=-0.001, URIBL_BLOCKED=0.001] autolearn=ham autolearn_force=no
X-Authentication-Results: mail.dewy.ru (amavisd-new); dkim=pass (2048-bit key)
header.d=paul-moore.com
X-Received: from mail.dewy.ru ([127.0.0.1])
by localhost (mail.dewy.ru [127.0.0.1]) (amavisd-new, port 10024)
with ESMTP id zzTxrMFOhckq;
Thu, 29 Oct 2026 04:13:14 +0300 (MSK)
X-Received-SPF: Pass (mailfrom) identity=mailfrom; client-ip=172.105.105.114; helo=tor.lore.kernel.org; envelope-from=netdev+bounces-353113-linux-kernel-netdev=dewy.ru@vger.kernel.org; receiver=<UNKNOWN>
X-Authentication-Results: OpenDMARC; dmarc=fail (p=none dis=none) header.from=paul-moore.com
X-Received: from tor.lore.kernel.org (tor.lore.kernel.org [172.105.105.114])
by mail.dewy.ru (Postfix) with ESMTPS id A8328125C4D; Thu, 29 Oct 2026 04:13:05 +0300 (MSK)
X-Received: from smtp.subspace.kernel.org (conduit.subspace.kernel.org [100.77.114.92])
by tor.lore.kernel.org (Postfix) with ESMTP id B9B5F27B67; Thu, 29 Oct 2026 01:11:21 +0000 (UTC)
X-Authentication-Results: smtp.subspace.kernel.org; arc=pass header.oldest-pass=0 smtp.remote-ip=127.0.0.1
X-ARC-Seal: i=3; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; cv=pass;
t=1793236279;
b=aTs0uwZBPVi9W4NbNc6m9e0PKXGZsToedpeygrQlC7z1lUIr6xlKBKlk69m0UOPqnKfD
ZmJ0LSVbqfVBlCz4cOnRsjtTl+OTiB5J/KSFb/FDFd2ISssAjNTCHqA+qK3wyurtnyFIH
LmAIQU/WKfQO8shkzPcU1/mGt3G9Rj4fz4qHaFAFhmDsIXqMwID13SVmKIYd3k/ZsyU+W
N3f9lB3H+POUBm444BJ1lI8b93C6ReovcDuODcFXqo/6ILGjMSKCkEpAny1OOfXQPSA7p
3nPApmfW7OSRraLCELIz08DecuctvwhQh8yfMnHuw6j4vPBUUVVbfIS7hKsOpPKzKxQ==
X-ARC-Message-Signature: i=3; d=subspace.kernel.org; s=arc20261015;
a=rsa-sha256; c=relaxed/relaxed; t=1793236279;
h=X-Original-To:Received:DMARC-Filter:Received:DKIM-Signature:
X-Google-DKIM-Signature:X-Gm-Message-State:X-Gm-Gg:X-Received:
X-Mailing-List:List-Id:List-Post:List-Help:List-Subscribe:
List-Unsubscribe:List-Owner:Precedence:MIME-Version:References:
In-Reply-To:From:Date:X-Gm-Features:Message-ID:Subject:To:Cc:
Content-Type:Content-Transfer-Encoding;
bh=T8vrlnjARGiDjuRUwRWUbox4bHtSHamjWdpm50A3jNE=;
b=0xtXpgm2y9ozWUMYQSLPwDZ2o+Gmwv9kOYzhdYVZfRv0yyN9dqfKhDG6DvsYVfh4dbpO
H2x5p3NHcyAz40AU2On4YyE93XzVFx/zmJrAYZXBAhSk+0RRAUhX3opciiEe/C8nmuoFb
Pd0NSnBpYAXTEPHjHjLKYiK7XZeZjNFam5pln8MwWeFmBk999ZJgDwB7r4LKFBj8xZISH
hgQJGKx5+xKhX657WpQ0heq1qbbN7JkqFRubyxQBy4ZxTYdTtGJyPvMBjzbbrHnDTpDSR
qgJqn+e4tFO1P3Lazcz0X6qqQEwoXYPY4QxEScprn/kuzFjJOh2kbhOz3kf3qU2GPMg==
X-ARC-Authentication-Results: i=3; smtp.subspace.kernel.org;
dkim=pass header.d=paul-moore.com header.i=@paul-moore.com header.a=rsa-sha256 header.s=google header.b=QFn0RApB;
dmarc=pass header.from=paul-moore.com;
spf=pass smtp.mailfrom=paul-moore.com;
arc=pass header.oldest-pass=0 smtp.remote-ip=127.0.0.1
X-Received: from localhost.localdomain (localhost [127.0.0.1])
by smtp.subspace.kernel.org (Postfix) with ESMTP id 3E121606A321;
Thu, 29 Oct 2026 01:11:19 +0000 (UTC)
X-Authentication-Results: smtp.subspace.kernel.org;
dkim=pass (2048-bit key, unprotected) header.d=paul-moore.com header.i=@paul-moore.com header.a=rsa-sha256 header.s=google header.b=QFn0RApB
X-Authentication-Results: smtp.subspace.kernel.org; arc=pass header.oldest-pass=0 smtp.remote-ip=209.85.210.178
X-ARC-Seal: i=2; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; cv=pass;
t=1793236278;
b=3WJRk7h7GKULDzdb9pPpndjxHbvOW2DhxXTzWFFPYP+IZ1aP1qIk1jCAFxk5mF9i2CW2
zjiIrFvaM47MW7w2akfWjHSgRhSSsGrFzmFY5U6vsxXJL6n+RV+6nKoFiqhZCSR3OAVyc
BMRp6RrbkwhW+SKWD9r3csAWfzWgwxEO7Afl4N93FLhhn8xW/LT87zDjhHcvtplUO0jzJ
DVXLk1NHln2fFTeCR9jhl/Py5fDamXshp+2hwSFCa7LCHpUmFn574ZLDc1G2arPlYzl/v
V1qDEwcsVHu74GYbcC0LCTfoEvpeM0+cMir1tHPQfArmyNMYfeVa4RkaBk5IMiRg4NQ==
X-ARC-Message-Signature: i=2; d=subspace.kernel.org; s=arc20261015;
a=rsa-sha256; c=relaxed/relaxed; t=1793236278;
h=DMARC-Filter:Received:DKIM-Signature:X-Google-DKIM-Signature:
X-Gm-Message-State:X-Gm-Gg:X-Received:MIME-Version:References:
In-Reply-To:From:Date:X-Gm-Features:Message-ID:Subject:To:Cc:
Content-Type:Content-Transfer-Encoding;
bh=T8vrlnjARGiDjuRUwRWUbox4bHtSHamjWdpm50A3jNE=;
b=lv+9Xdwhl4t2vxugs6Jvqs3UGpBfeQGeYddm1XMzNQCnyEG7hgluNLZHQmNPQFyflLuF
Ma8Z5lEuwh5tXa/4mS1NCWln37keyf9k/3pT7gf9B8qcWxYGuX3IF7/XyOTvyJIYxeTm8
EkJVaxJy8TLU75d30zajC/2NqsJd1063ant4vkkX1zqX9+wdkDT15dAkUo9+blhSd8ann
Aa2SKr/P3IJF9FBNUNbGVudYa6nyfgwhKMdGFOy233eWVV1r+KpAneT6VQrjFM1RyOri5
Bge44oqPwdCHDL0lZpCxDcahMWdInvL3kCW9SEVkEBZTcikxBN3XoaIkoOS/dTxEJaA==
X-ARC-Authentication-Results: i=2; smtp.subspace.kernel.org;
dmarc=pass header.from=paul-moore.com;
spf=pass smtp.mailfrom=paul-moore.com;
dkim=pass header.d=paul-moore.com header.i=@paul-moore.com header.a=rsa-sha256 header.s=google header.b=QFn0RApB;
arc=pass header.oldest-pass=0 smtp.remote-ip=209.85.210.178
X-Received: from mail-pf1-f178.google.com (mail-pf1-f178.google.com [209.85.210.178])
(using TLSv1.3 with cipher TLS_AES_128_GCM_SHA256 (128/128 bits)
key-exchange X25519 server-signature ECDSA (prime256v1) server-digest SHA256)
(No client certificate requested)
by smtp.subspace.kernel.org (Postfix) with ESMTPS id BCA96606A31A
for <netdev@vger.kernel.org>; Thu, 29 Oct 2026 01:11:17 +0000 (UTC)
X-DMARC-Filter: OpenDMARC Filter v1.4.2 smtp.subspace.kernel.org BCA96606A31A
X-Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=paul-moore.com
X-Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=paul-moore.com
X-Received: by mail-pf1-f178.google.com with SMTP id d2e1a72fcca58-886e61fa30fso791289b3a.1
for <netdev@vger.kernel.org>; Wed, 28 Oct 2026 18:11:17 -0700 (PDT)
X-ARC-Seal: i=1; a=rsa-sha256; t=1793236277; cv=none;
d=google.com; s=arc-20260327;
b=l94k8/+56+IlKUnCe881urkdURed5SgTKKdIPn/CqtOAQWdHNXBwzoC1voWq+7zUlK
Nm78v9nslDFTr0FSfhA0EbPvuRXOzFvGduWIam9a0NlUZMlfGsKuLK3j+/nJuK42AkYE
KskWLBWDZB1hFOJ1SdsVDV9zXTJOTHlheSwecCMqa1ZFSW2rhTNRIpOoJ0dzUlrPhmm/
H0V6BYWM/Ijr7TiKtFsbQxgfsAyObbfk8nVexi+BCOrgUagg2UymaxNFkupifci19BHj
n0p9JorOzqXlAb9pJKhZ7BzxP1t8JQvXLuHDWOwkPVVqEmMZKBb18jX/TBp+TjN0SvoE
leIw==
X-ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20260327;
h=content-transfer-encoding:cc:to:subject:message-id:date:from
:in-reply-to:references:mime-version:dkim-signature;
bh=T8vrlnjARGiDjuRUwRWUbox4bHtSHamjWdpm50A3jNE=;
fh=hN+Y/wIkw7vLXNUUzap0GdKQQlEs7yQPeojl4/ZQBLQ=;
b=asrmwdXLfqC8ORRnRi5ZmmhZNEA7+BKh+sj9B2WOuB7kjHdxGc3gHDtCp9YuZJlhFp
h/mE2ps2TT5i5GrcSPzo8T5WLu73q7Yfwu4yIOmtbdJB/uXsYNybm+JMfBsTdMpqF0NB
c7dXNF51CaUfmvfQ9sxsx7QeGxI4IETty/Pt30i+UnZql68/Pzi+LuF9y2ftnmpBSbTD
yiZPOo8JyMpTdo3BFV0LTdU4sthGCoQVGL6PHB+7bGunRyU0PPBIO4bi0eluAN+nKZeA
/lMU/rKZ4LucEaIdl+f+W2GenWOSbkoro5WnfvHDD2XSGWn67t348TlhNeOoouwPbnR1
Rr0g==;
darn=vger.kernel.org
X-ARC-Authentication-Results: i=1; mx.google.com; arc=none
X-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed;
d=paul-moore.com; s=google; t=1793236277; x=1793841077; darn=vger.kernel.org;
h=content-transfer-encoding:content-type:cc:to:subject:message-id
:date:from:in-reply-to:references:mime-version:from:to:cc:subject
:date:message-id:reply-to:content-type;
bh=T8vrlnjARGiDjuRUwRWUbox4bHtSHamjWdpm50A3jNE=;
b=QFn0RApB/826lxN0LU222f/R+lapxjGz6ks3phdhGPowHtq/z2VmroSMeLTTjb9EjF
uiadR4Ik7VcZRxFCYn2EQNJ8kh2xOz3dmVXvF4UgI+PvdXKLCJVV7DJYXvrI+mG3Ow/G
BkxiRET922nuV0OfGkx5WEoAMh9EK41xLUPv5t4mmeQlRB/Hj/L8vOB7FdjwYm+/+Rz1
ZbQ3uAhOJY7fB/2SKI2fMP3FcNTXJBq9IdkoPcFaK1V8gqkiU3FUmJRsuCCbikMI106R
6ObyxD4tX6zTYoGj6f91vcHj4HAa6T9//0PQFNMmg+Y3tp+USNTf4Roeeyx7pzi3V0F/
DaCA==
X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed;
d=1e100.net; s=20260707; t=1793236277; x=1793841077;
h=content-transfer-encoding:content-type:cc:to:subject:message-id
:date:from:in-reply-to:references:mime-version:x-gm-gg
:x-gm-message-state:from:to:cc:subject:date:message-id:reply-to
:content-type;
bh=T8vrlnjARGiDjuRUwRWUbox4bHtSHamjWdpm50A3jNE=;
b=2OUSsBwsbJkdyaSciI/cyTdb+keRrmcWDDUu6Hst9vbt9e8uqMBI/nm/9DDzPukbug
Pl2qwFrL4Vt/1cWUQWNnr3DMVyZ0vC6+KWI5FhhkC8vM6j+mvDiAjXPl7ZL4tBLLr6Fo
WFJ+B2ImKTAAxOZ25TJ9EIG2ucIneHyvSKKYGVSzSl70aAqQ4ES58q1gIYyVSsmldHTn
k/V/glTAf7F8vnrMVeslcRK3GlAgXG9Xr2/p8nBvQ/p7UrQRyYXUnQZnpFcPtXs5rUiz
9v6btmL3DlrzN+lTEKBfy64ScCnOkZ3ZD3ijeGUbmi94C6jC29lpIdWwOI5Jz9N5H40z
mS8w==
X-Gm-Message-State: AFq9FYL8lMbFdn8KwZMkynPmzlejsDxcV3zPgkt5uLr8f8t3xmaCvV6l
00Z4I+6SiuCNlUCrTJbpBMgm943KNauiudHRQkMQjW0PqQBZUwoIovp4dAOoej2omgf7Pl2wtLP
Y/FFkyUGl3Za9mFGiLms89SedrbvsxQ50glTbw0xRAmgTRgPtr21l/jNJ
X-Gm-Gg: AYBFou2qwds9lqw2O08sdIHHw7tK0FLF4BlEr02JN1U1bmKnVUV1woNKyPi41W1IExD
Ii/fggHPPYTuaVceWn9Z3R0ggvZFOvPX4SdIIliKO88PZpXcl8tE82PNvKQCFBhAy8Ct3pi9LP0
8AJXsWbB1IFXBirqV+r0piBBsztLVS8xttKsum8rA4yjMKFkp2NL2lA8sHAN7o1tu8B6JxTQwZs
g+aA0loLwX/AHXZQxXj9NYzJ7gYJA5aCuO7ayyMVoO8aG/Nor+d//WC1YlSjo2F0ZTDzhIfv3F6
wyqiEIdwG2EDEghi58/7GYqjSjw1iOBLpMRuFIWfFX9jkxm7xmQpBuZlUKz5VW35ev+Sfbf4LM2
Dzr6OVk+IupqZ+WrakTt8MktOI+v8PCrq9mG6uvWzoEfkmr5Ha+Mgm8GbcSuHvVLY6W8B
X-Received: by 2002:a05:6a21:3e0a:b0:3e0:e9f7:814c with SMTP id
adf61e73a8af0-3e9023833fbmr2058685637.33.1793236277145; Wed, 28 Oct 2026
18:11:17 -0700 (PDT)
X-Mailing-List: netdev@vger.kernel.org
X-List-Post: <mailto:netdev@vger.kernel.org>
X-List-Help: <mailto:netdev+help@vger.kernel.org>
X-List-Subscribe: <mailto:netdev+subscribe@vger.kernel.org>
X-List-Unsubscribe: <mailto:netdev+unsubscribe@vger.kernel.org>
X-List-Owner: <mailto:netdev+owner@vger.kernel.org>
X-Precedence: list
X-In-Reply-To: <uOcTaW7-g5e97ng6BG_DcH5mlMnpw7KzU25SZjL69pkAVINTMiL26FryLAuYPSNowDo8qwfb9hm_I4dQ1BwpiRe62E-I2TyUkJZ_eBeuLoo=@proton.me>
X-Gm-Features: AclHuK_-Tt6aAk1Q9UVaRNEoFiyF4HEXUF2NG9jMAfN6nnbuCUnaax6L8izesW8
X-Cc: "netdev@vger.kernel.org" <netdev@vger.kernel.org>, Qihang <q.h.hack.winter@gmail.com>