From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from mail.openvz.org (mail.openvz.org [69.168.225.77]) by lore.virtuozzo.com (Postfix) with ESMTPS id 491F380033 for ; Tue, 1 Dec 2026 15:40:09 +0000 (UTC) Received: from mail.openvz.org (localhost [127.0.0.1]) by mail.openvz.org (8.14.4/8.14.4) with ESMTP id 6B1Fcuxf020218; Tue, 1 Dec 2026 18:38:56 +0300 DKIM-Filter: OpenDKIM Filter v2.11.0 mail.openvz.org 6B1Fcuxf020218 Authentication-Results: mail.openvz.org; dkim=fail reason="signature verification failed" (2048-bit key) header.d=virtuozzo.com header.i=@virtuozzo.com header.b="sPUndaVj" Received: from mail-ed1-f69.google.com (mail-ed1-f69.google.com [209.85.208.69]) by mail.openvz.org (8.14.4/8.14.4) with ESMTP id 6B1FcppA020200 (version=TLSv1/SSLv3 cipher=AES128-GCM-SHA256 bits=128 verify=FAIL) for ; Tue, 1 Dec 2026 18:38:51 +0300 DKIM-Filter: OpenDKIM Filter v2.11.0 mail.openvz.org 6B1FcppA020200 Received: by mail-ed1-f69.google.com with SMTP id 4fb4d7f45d1cf-6babdfe377cso8827441a12.0 for ; Tue, 01 Dec 2026 07:38:51 -0800 (PST) X-Gm-Message-State: APuU4Z/Z5NbaycNBU1KAlDX6NPdUe+X7mJIRaRC5Di/REW6VdVhwwJo2 Yi1hdSzV4kIYr/In3V6s7XzFXWZamrYCYYTYhz8zi04lpHMrP542rdbO36McllLebrj86UfpN/s GUfV9I56ixrsXqnG0Ts7zi8LEvepunMMXLGMLfmlCTDwhzm87nIhDXg== X-Gm-Gg: AZFdTZfzoWNQp9dpTNtDLM4oDP1BDMaPIhiojTj9BxA3Ydl5fp4sq5rLasalRJ3dqr6 iHkOzSpKYtaBBBsAGYKLbhqhPi2RUSUtLOkmdQLmdrdVZfqLRCr0ZG3H2//fazFod41ZT6mZ+/C HwC/AefVj/2F8pkJQx76Jy6ortQhE23NPIuXI5z8DkbwKjlR5Gyeqq39xSqRkz2ZqT+aud96TiY QRG9i3psG8bxsfKXhWgktxCzPA6mKtYvVh+tdkHWImCzlzrsode0IFfR5xBQvEBl1yNo2k2VekZ J1oyN+terMZZ6bOeezhEOvw+RvGSUSbmh1dANl7r1w2+Iy0SrRZ4ckJdm0uiQXtvvEzCB+wy+l/ DHT2VM7Gg0yGJr2LoqS0Wp/kf4Q== X-Received: by 2002:a05:6402:51cd:b0:6ba:3a5f:ab13 with SMTP id 4fb4d7f45d1cf-6ba3a5fad1fmr24804447a12.7.1796139531181; Tue, 01 Dec 2026 07:38:51 -0800 (PST) X-Received: by 2002:a05:6402:51cd:b0:6ba:3a5f:ab13 with SMTP id 4fb4d7f45d1cf-6ba3a5fad1fmr24804422a12.7.1796139530547; Tue, 01 Dec 2026 07:38:50 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1796139530; cv=none; d=google.com; s=arc-20260327; b=gnq5Igq56MatIcHtFLwtzL2pCF/oqzOst30fbUcuDsdZug4/yv7nThCilJfJTyhq60 lVo/W7diM5yJYcyKU3P0F/WI86ajHZ/akW0wyVt4BoAxwEL9HoJWY17zFUqBeay0QqRg mM+I6kRqfh4m5pZzs1SEWYT93uK4weDhqD5Iry4ThRD/+xkp5CNsM6Sl6be89lgdsKHc o2TF/dw1ClixDhf+izP0pT5VQa4JFrWMudjKDWvWOWxhrPOrkGbbmwPFPXRbdUB/65ts xVDHjbjCMLJmE1q7RHZsxWzM7D76/99Oy1TvF/hvfZjo9+BaRQ+ACF80xLjYbl7gyD0Z A/3w== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20260327; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:dkim-signature; bh=BJAXTccK5oJIcY+JQoOSHY5ee3HwHkgKX/XlSDTEkb0=; fh=/QSWnKFFIPNLStgUoDwCQRaXnWcMIG7fyKJgHY+VEpU=; b=T5xKOHcqK1lnKpRWIQWYOsVcshvgs6GKOeuLgzdNCCE7g3Y8akHexbSnQWdNQnXFsU RL4ifQDcPJCsjKPIXeQlwvAi1CqL+2G4DfaOhZksCkpqqmQJVab+ZbVd0u+bSswRVJmP So08p9NDeEvSG0VpZEyTZSbV+UZBDu+Hb37C+v3Vd2+N46gpJlX5ACNmQD7JuKeOQHF1 VmSHrRjoiC36OOZNSf+gnIyawwjWu+rXmw0GXfoX1o3PVE9Xr6PN9KLYr4o51vl4SsGx /wzCoalI9ZtmjjqqLvE2iTgxNFCtux8qD9HR4SrTbnYpe46eR6tFqdndHvlQ3J2GNGA6 kTUw==; dara=google.com ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@virtuozzo.com header.s=relay header.b=sPUndaVj; spf=pass (google.com: domain of eva.kurchatova@virtuozzo.com designates 130.117.225.111 as permitted sender) smtp.mailfrom=eva.kurchatova@virtuozzo.com; dmarc=pass (p=QUARANTINE sp=QUARANTINE dis=NONE) header.from=virtuozzo.com Received: from relay.virtuozzo.com (relay.virtuozzo.com. [130.117.225.111]) by mx.google.com with ESMTPS id 4fb4d7f45d1cf-6bae6cc461csi19661223a12.17.2026.12.01.07.38.50 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 01 Dec 2026 07:38:50 -0800 (PST) Received-SPF: pass (google.com: domain of eva.kurchatova@virtuozzo.com designates 130.117.225.111 as permitted sender) client-ip=130.117.225.111; Authentication-Results: mx.google.com; dkim=pass header.i=@virtuozzo.com header.s=relay header.b=sPUndaVj; spf=pass (google.com: domain of eva.kurchatova@virtuozzo.com designates 130.117.225.111 as permitted sender) smtp.mailfrom=eva.kurchatova@virtuozzo.com; dmarc=pass (p=QUARANTINE sp=QUARANTINE dis=NONE) header.from=virtuozzo.com DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=virtuozzo.com; s=relay; h=MIME-Version:Message-ID:Date:Subject:From: Content-Type; bh=BJAXTccK5oJIcY+JQoOSHY5ee3HwHkgKX/XlSDTEkb0=; b=sPUndaVj4bra b/HFdZ78yivV4P7m5b5fKJOdLj8uHQK8GQGuhoAS8WBep5BYEOyBUueXfwXbjhInnBJ6Ntp8CFf/q zRaOSZxKoCNNqqUvimFfKyG+OY3364SyraQrQUHZGgjLcoIGX6k6nwOqe2JGNqh2tWgASjSlERBqB fsgf8C+nGIIerWhMR1rif9Z1NPcuYf27L7ESHhSmLGL5LEgvFlEYuICgbPBBd1KhscTcqmbcxLdao qLj03NXTrTvbgsjRX6uMykok6vb5JUC8ozTR4ONrLNo0NtkoqUcbH4OJvl9e94vxrHrRUKp8AnQai 0slk+dbdhkt4ULTAQUOL9A==; Received: from ch-vpn.virtuozzo.com ([130.117.225.6] helo=LekKit-T14) by relay.virtuozzo.com with esmtp (Exim 4.96) (envelope-from ) id 1xYPvD-0081OE-0s; Tue, 01 Dec 2026 16:37:45 +0100 From: Eva Kurchatova To: khorenko@virtuozzo.com, vladimir.riabchun@virtuozzo.com Date: Tue, 1 Dec 2026 14:10:30 +0200 Message-ID: <20261201153749.2872789-16-eva.kurchatova@virtuozzo.com> X-Mailer: git-send-email 2.56.1 In-Reply-To: <20261201153749.2872789-1-eva.kurchatova@virtuozzo.com> References: <20261201153749.2872789-1-eva.kurchatova@virtuozzo.com> MIME-Version: 1.0 X-OZ-Fwd: true Cc: devel@openvz.org Subject: [Devel] [PATCH hci-8.2 v2 15/15] ms/cipso: stop modifying live ip_options_rcu X-BeenThere: devel@openvz.org X-Mailman-Version: 2.1.12 Precedence: list List-Id: OpenVZ development List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: 7bit Sender: devel-bounces@openvz.org Errors-To: devel-bounces@openvz.org From: Jann Horn [ Upstream commit 1f2c5183fc0902892648f0453e38c0951cef3fec ] cipso_v4_delopt() operates on the ip_options_rcu of a socket or a request socket, and tries to remove CIPSO options from the middle by moving all subsequent options. That's not allowed - ip_options_rcu can be read locklessly and must always be consistent. For example, ip_options_undo() reads trusted offsets and length values from the options buffer. Fix it by doing the modification in a copy. The core change is in cipso_v4_delopt(), the rest is ugly plumbing to propagate memory allocation failures. Triggering this bug requires that the system is configured to use CIPSO. (Setting up CIPSO requires privileges in init_user_ns.) Fixes: f6d8bd051c39 ("inet: add RCU protection to inet->opt") Cc: stable@vger.kernel.org Signed-off-by: Jann Horn Reviewed-by: Eric Dumazet Acked-by: Paul Moore Link: https://patch.msgid.link/20261106-cipso-rcuopts-v1-1-31ae931d7a0f@google.com Signed-off-by: Jakub Kicinski Signed-off-by: Sasha Levin (cherry picked from commit 29e21acda251848a29bb1e8a629d74c0968c8fcb) https://virtuozzo.atlassian.net/browse/VSTOR-158162 Feature: fix ms/net Signed-off-by: Eva Kurchatova --- include/net/cipso_ipv4.h | 11 ++++++----- include/net/netlabel.h | 11 ++++++----- net/ipv4/cipso_ipv4.c | 16 +++++++++++++--- net/netlabel/netlabel_kapi.c | 24 ++++++++++-------------- security/selinux/netlabel.c | 5 +++-- security/smack/smack_lsm.c | 14 +++++++++----- 6 files changed, 47 insertions(+), 34 deletions(-) diff --git a/include/net/cipso_ipv4.h b/include/net/cipso_ipv4.h index d6780d7903f4..b41672221797 100644 --- a/include/net/cipso_ipv4.h +++ b/include/net/cipso_ipv4.h @@ -185,12 +185,12 @@ int cipso_v4_sock_setattr(struct sock *sk, const struct cipso_v4_doi *doi_def, const struct netlbl_lsm_secattr *secattr, bool sk_locked); -void cipso_v4_sock_delattr(struct sock *sk); +int cipso_v4_sock_delattr(struct sock *sk); int cipso_v4_sock_getattr(struct sock *sk, struct netlbl_lsm_secattr *secattr); int cipso_v4_req_setattr(struct request_sock *req, const struct cipso_v4_doi *doi_def, const struct netlbl_lsm_secattr *secattr); -void cipso_v4_req_delattr(struct request_sock *req); +int cipso_v4_req_delattr(struct request_sock *req); int cipso_v4_skbuff_setattr(struct sk_buff *skb, const struct cipso_v4_doi *doi_def, const struct netlbl_lsm_secattr *secattr); @@ -221,8 +221,9 @@ static inline int cipso_v4_sock_setattr(struct sock *sk, return -ENOSYS; } -static inline void cipso_v4_sock_delattr(struct sock *sk) +static inline int cipso_v4_sock_delattr(struct sock *sk) { + return 0; } static inline int cipso_v4_sock_getattr(struct sock *sk, @@ -238,9 +239,9 @@ static inline int cipso_v4_req_setattr(struct request_sock *req, return -ENOSYS; } -static inline void cipso_v4_req_delattr(struct request_sock *req) +static inline int cipso_v4_req_delattr(struct request_sock *req) { - return; + return 0; } static inline int cipso_v4_skbuff_setattr(struct sk_buff *skb, diff --git a/include/net/netlabel.h b/include/net/netlabel.h index 529160f76cac..93ff5889a267 100644 --- a/include/net/netlabel.h +++ b/include/net/netlabel.h @@ -476,7 +476,7 @@ int netlbl_sock_setattr(struct sock *sk, u16 family, const struct netlbl_lsm_secattr *secattr, bool sk_locked); -void netlbl_sock_delattr(struct sock *sk); +int netlbl_sock_delattr(struct sock *sk); int netlbl_sock_getattr(struct sock *sk, struct netlbl_lsm_secattr *secattr); int netlbl_conn_setattr(struct sock *sk, @@ -484,7 +484,7 @@ int netlbl_conn_setattr(struct sock *sk, const struct netlbl_lsm_secattr *secattr); int netlbl_req_setattr(struct request_sock *req, const struct netlbl_lsm_secattr *secattr); -void netlbl_req_delattr(struct request_sock *req); +int netlbl_req_delattr(struct request_sock *req); int netlbl_skbuff_setattr(struct sk_buff *skb, u16 family, const struct netlbl_lsm_secattr *secattr); @@ -625,8 +625,9 @@ static inline int netlbl_sock_setattr(struct sock *sk, { return -ENOSYS; } -static inline void netlbl_sock_delattr(struct sock *sk) +static inline int netlbl_sock_delattr(struct sock *sk) { + return 0; } static inline int netlbl_sock_getattr(struct sock *sk, struct netlbl_lsm_secattr *secattr) @@ -644,9 +645,9 @@ static inline int netlbl_req_setattr(struct request_sock *req, { return -ENOSYS; } -static inline void netlbl_req_delattr(struct request_sock *req) +static inline int netlbl_req_delattr(struct request_sock *req) { - return; + return 0; } static inline int netlbl_skbuff_setattr(struct sk_buff *skb, u16 family, diff --git a/net/ipv4/cipso_ipv4.c b/net/ipv4/cipso_ipv4.c index 15b8bb57feef..fc5a21253cfc 100644 --- a/net/ipv4/cipso_ipv4.c +++ b/net/ipv4/cipso_ipv4.c @@ -2006,11 +2006,16 @@ static int cipso_v4_delopt(struct ip_options_rcu __rcu **opt_ptr) if (!opt || opt->opt.cipso == 0) return 0; if (opt->opt.srr || opt->opt.rr || opt->opt.ts || opt->opt.router_alert) { + struct ip_options_rcu *old_opt = opt; u8 cipso_len; u8 cipso_off; unsigned char *cipso_ptr; int optlen_new; + /* ip_options_rcu must not be modified in place, use a copy */ + opt = kmemdup(opt, sizeof(*opt) + opt->opt.optlen, GFP_ATOMIC); + if (!opt) + return -ENOMEM; cipso_off = opt->opt.cipso - sizeof(struct iphdr); cipso_ptr = &opt->opt.__data[cipso_off]; cipso_len = cipso_ptr[1]; @@ -2038,6 +2043,8 @@ static int cipso_v4_delopt(struct ip_options_rcu __rcu **opt_ptr) memset(&opt->opt.__data[optlen_new], IPOPT_END, opt->opt.optlen - optlen_new); + rcu_assign_pointer(*opt_ptr, opt); + kfree_rcu(old_opt, rcu); } else { /* only the cipso option was present on the socket so we can * remove the entire option struct */ @@ -2057,7 +2064,7 @@ static int cipso_v4_delopt(struct ip_options_rcu __rcu **opt_ptr) * Removes the CIPSO option from a socket, if present. * */ -void cipso_v4_sock_delattr(struct sock *sk) +int cipso_v4_sock_delattr(struct sock *sk) { struct inet_sock *sk_inet; int hdr_delta; @@ -2070,6 +2077,7 @@ void cipso_v4_sock_delattr(struct sock *sk) sk_conn->icsk_ext_hdr_len -= hdr_delta; sk_conn->icsk_sync_mss(sk, sk_conn->icsk_pmtu_cookie); } + return (hdr_delta < 0) ? hdr_delta : 0; } /** @@ -2080,9 +2088,11 @@ void cipso_v4_sock_delattr(struct sock *sk) * Removes the CIPSO option from a request socket, if present. * */ -void cipso_v4_req_delattr(struct request_sock *req) +int cipso_v4_req_delattr(struct request_sock *req) { - cipso_v4_delopt(&inet_rsk(req)->ireq_opt); + int hdr_delta = cipso_v4_delopt(&inet_rsk(req)->ireq_opt); + + return (hdr_delta < 0) ? hdr_delta : 0; } /** diff --git a/net/netlabel/netlabel_kapi.c b/net/netlabel/netlabel_kapi.c index 33b77084a4e5..34ef835191dd 100644 --- a/net/netlabel/netlabel_kapi.c +++ b/net/netlabel/netlabel_kapi.c @@ -1045,18 +1045,18 @@ int netlbl_sock_setattr(struct sock *sk, * ensuring that @sk is locked. * */ -void netlbl_sock_delattr(struct sock *sk) +int netlbl_sock_delattr(struct sock *sk) { switch (sk->sk_family) { case AF_INET: - cipso_v4_sock_delattr(sk); - break; + return cipso_v4_sock_delattr(sk); #if IS_ENABLED(CONFIG_IPV6) case AF_INET6: calipso_sock_delattr(sk); break; #endif /* IPv6 */ } + return 0; } /** @@ -1156,8 +1156,7 @@ int netlbl_conn_setattr(struct sock *sk, case NETLBL_NLTYPE_UNLABELED: /* just delete the protocols we support for right now * but we could remove other protocols if needed */ - netlbl_sock_delattr(sk); - ret_val = 0; + ret_val = netlbl_sock_delattr(sk); break; default: ret_val = -ENOENT; @@ -1185,8 +1184,7 @@ int netlbl_conn_setattr(struct sock *sk, case NETLBL_NLTYPE_UNLABELED: /* just delete the protocols we support for right now * but we could remove other protocols if needed */ - netlbl_sock_delattr(sk); - ret_val = 0; + ret_val = netlbl_sock_delattr(sk); break; default: ret_val = -ENOENT; @@ -1234,8 +1232,7 @@ int netlbl_req_setattr(struct request_sock *req, entry->cipso, secattr); break; case NETLBL_NLTYPE_UNLABELED: - netlbl_req_delattr(req); - ret_val = 0; + ret_val = netlbl_req_delattr(req); break; default: ret_val = -ENOENT; @@ -1255,8 +1252,7 @@ int netlbl_req_setattr(struct request_sock *req, entry->calipso, secattr); break; case NETLBL_NLTYPE_UNLABELED: - netlbl_req_delattr(req); - ret_val = 0; + ret_val = netlbl_req_delattr(req); break; default: ret_val = -ENOENT; @@ -1280,18 +1276,18 @@ int netlbl_req_setattr(struct request_sock *req, * Remove all the NetLabel labeling from @req. * */ -void netlbl_req_delattr(struct request_sock *req) +int netlbl_req_delattr(struct request_sock *req) { switch (req->rsk_ops->family) { case AF_INET: - cipso_v4_req_delattr(req); - break; + return cipso_v4_req_delattr(req); #if IS_ENABLED(CONFIG_IPV6) case AF_INET6: calipso_req_delattr(req); break; #endif /* IPv6 */ } + return 0; } /** diff --git a/security/selinux/netlabel.c b/security/selinux/netlabel.c index d51dfe892312..24b11d1891d8 100644 --- a/security/selinux/netlabel.c +++ b/security/selinux/netlabel.c @@ -557,9 +557,10 @@ static int selinux_netlbl_socket_connect_helper(struct sock *sk, * is set to AF_UNSPEC, if that is what is happening we want to reset * the socket */ if (addr->sa_family == AF_UNSPEC) { - netlbl_sock_delattr(sk); + rc = netlbl_sock_delattr(sk); + if (rc) + return rc; sksec->nlbl_state = NLBL_REQSKB; - rc = 0; return rc; } secattr = selinux_netlbl_sock_genattr(sk); diff --git a/security/smack/smack_lsm.c b/security/smack/smack_lsm.c index 9c03a6864936..c312b314ccb4 100644 --- a/security/smack/smack_lsm.c +++ b/security/smack/smack_lsm.c @@ -2607,22 +2607,26 @@ static int smack_netlbl_add(struct sock *sk) * * Remove the outbound smack value from a socket */ -static void smack_netlbl_delete(struct sock *sk) +static int smack_netlbl_delete(struct sock *sk) { struct socket_smack *ssp = smack_sock(sk); + int rc; /* * Take the label off the socket if one is set. */ if (ssp->smk_state != SMK_NETLBL_LABELED) - return; + return 0; local_bh_disable(); bh_lock_sock_nested(sk); - netlbl_sock_delattr(sk); + rc = netlbl_sock_delattr(sk); bh_unlock_sock(sk); local_bh_enable(); + if (rc) + return rc; ssp->smk_state = SMK_NETLBL_UNLABELED; + return 0; } /** @@ -2662,7 +2666,7 @@ static int smk_ipv4_check(struct sock *sk, struct sockaddr_in *sap) * Clear the socket netlabel if it's set. */ if (!rc) - smack_netlbl_delete(sk); + rc = smack_netlbl_delete(sk); } rcu_read_unlock(); @@ -4457,7 +4461,7 @@ static int smack_inet_conn_request(const struct sock *sk, struct sk_buff *skb, if (hskp == NULL) rc = netlbl_req_setattr(req, &ssp->smk_out->smk_netlabel); else - netlbl_req_delattr(req); + rc = netlbl_req_delattr(req); return rc; } -- 2.56.1 _______________________________________________ Devel mailing list Devel@openvz.org https://lists.openvz.org/mailman/listinfo/devel