Received: by 2002:a05:7412:b10a:b0:f3:1519:9f41 with SMTP id az10csp2571861rdb; Mon, 4 Dec 2023 00:58:02 -0800 (PST) X-Google-Smtp-Source: AGHT+IFq8wvR5b1jwW4UA9o4a6U+x67ija7RCUOu3TxYtn/l+EX/61DmiQbSwbkF8vDS1Df9Ix0k X-Received: by 2002:a05:6830:cb:b0:6d8:7ecb:b5ed with SMTP id x11-20020a05683000cb00b006d87ecbb5edmr2150658oto.52.1701680282667; Mon, 04 Dec 2023 00:58:02 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1701680282; cv=none; d=google.com; s=arc-20160816; b=Vl6bUdmO4mEx5s2NcA7lGT1feNhIFdBL8m2tPkG6XfTCP2i2s41WjFPV6hmvbHfclc znA42szF9KFNYer+ZWjSCUT3X1pxB8ZnHNTA3RafuzuvHQywk3Nz1EGWve4cFZgq/vrv Ayc82B0TJkXlejJTIvCM1KpVNtLQV3KUCdY0u+v6gTsSxDFNueEIvmc1y54pk8STsm4A GUdBSeabT3MqC122Ded/90TlXjJvzbpaFMol7DZddsI+m2IqfiU3NVLYsRzcfNsaSF09 ytPcDtQJyCay+DYrrXdaa1BOWCh4d9ASD6Hmc3QgrIE1A+DEDkXkHUvvXcXds7h5Bt9I beBQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :organization:references:in-reply-to:message-id:subject:cc:to:from :date:dkim-signature; bh=as+mUhZT9eKzCHaYz+7jVrwGQR55Ba1FhGnt3+3ZvD4=; fh=9XstciAWLTXkqpfZYftuSl+nTpBqhLmsUaEhK2cbCCE=; b=vFMix8qFNCUENduAY+hFSvwpgmzU2V+yhMCmmCLce/ASXoIA/PkoWRty3xZazLUT6H GF7NqfNF9zuj+ghXobuMycPi8j3crPkse2z7qOl4SnesXeRFuX9c9QLbkEwa5FbuJesm d4nqoWJP5QzhLxUy1Ap9z+wTZrdOquIqTUscxV6WiHUBcT792HlFCjD/ypLtbZK/MjJz cNhyfG9HScl5moKLBlwQ0BugBIGFBp8UEqTDeDg9U+zi+vM8aThI7UOHzZJ+MdWQLWau NtsmcmGDJXe+5XmRJzwMZ02cH2D4XxYYCJeSsmxlAfwEYsXOVav9qD2ZWQ1jVSzKM63m yRrg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@bootlin.com header.s=gm1 header.b=aLnlFZs5; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:2 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=REJECT sp=REJECT dis=NONE) header.from=bootlin.com Return-Path: Received: from agentk.vger.email (agentk.vger.email. [2620:137:e000::3:2]) by mx.google.com with ESMTPS id z13-20020a6552cd000000b005aaab9e7bcfsi7558148pgp.388.2023.12.04.00.58.02 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 04 Dec 2023 00:58:02 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:2 as permitted sender) client-ip=2620:137:e000::3:2; Authentication-Results: mx.google.com; dkim=pass header.i=@bootlin.com header.s=gm1 header.b=aLnlFZs5; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:2 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=REJECT sp=REJECT dis=NONE) header.from=bootlin.com Received: from out1.vger.email (depot.vger.email [IPv6:2620:137:e000::3:0]) by agentk.vger.email (Postfix) with ESMTP id C663E805EAE5; Mon, 4 Dec 2023 00:57:56 -0800 (PST) X-Virus-Status: Clean X-Virus-Scanned: clamav-milter 0.103.11 at agentk.vger.email Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S230245AbjLDI5d (ORCPT + 99 others); Mon, 4 Dec 2023 03:57:33 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:43974 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S234853AbjLDI5Y (ORCPT ); Mon, 4 Dec 2023 03:57:24 -0500 Received: from relay7-d.mail.gandi.net (relay7-d.mail.gandi.net [IPv6:2001:4b98:dc4:8::227]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 9AC441AA; Mon, 4 Dec 2023 00:57:23 -0800 (PST) Received: by mail.gandi.net (Postfix) with ESMTPSA id 0801F20003; Mon, 4 Dec 2023 08:57:19 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=bootlin.com; s=gm1; t=1701680241; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=as+mUhZT9eKzCHaYz+7jVrwGQR55Ba1FhGnt3+3ZvD4=; b=aLnlFZs512kyZLhaL3DHgbAlUoXp2N1gGvZOufQmRNHTCa1fqpyXM3bgzNhyNY6XOknKXD 0YIFWli7WoqNp21U/ur77cwQn0WrPrE2ul8xSNcXOYKdvXkZiLBgj4gLgLLyKxaFfkwoi6 Biu07W/nk84JjvHjEQxkR5c2SHnUG+VEJ/EZuwLHz0UJBZwMkUt+vEz9xUd99SO+lEpVE3 lL8BRWhMmAdrq8m17DWn9z22TOh9wmar5itZ4oRodqvowGvCgO36lMDmfGA6TOMJQHGk+W 6AgW4MSJ5n66bER0fVws5s4uWFIbabBzPbiersoxoBEKNw8oIRRL0N1zEYEecg== Date: Mon, 4 Dec 2023 09:57:18 +0100 From: Miquel Raynal To: Zhang Shurong Cc: alex.aring@gmail.com, stefan@datenfreihafen.org, davem@davemloft.net, edumazet@google.com, kuba@kernel.org, pabeni@redhat.com, linux-wpan@vger.kernel.org, netdev@vger.kernel.org, linux-kernel@vger.kernel.org, harperchen1110@gmail.com Subject: Re: [PATCH RESEND] mac802154: Fix uninit-value access in ieee802154_hdr_push_sechdr Message-ID: <20231204095718.40ccb1ee@xps-13> In-Reply-To: References: Organization: Bootlin X-Mailer: Claws Mail 4.0.0 (GTK+ 3.24.33; x86_64-pc-linux-gnu) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: quoted-printable X-GND-Sasl: miquel.raynal@bootlin.com X-Spam-Status: No, score=-0.9 required=5.0 tests=DKIM_SIGNED,DKIM_VALID, DKIM_VALID_AU,HEADER_FROM_DIFFERENT_DOMAINS,MAILING_LIST_MULTI, SPF_HELO_NONE,SPF_PASS,T_SCC_BODY_TEXT_LINE autolearn=unavailable autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on agentk.vger.email Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org X-Greylist: Sender passed SPF test, not delayed by milter-greylist-4.6.4 (agentk.vger.email [0.0.0.0]); Mon, 04 Dec 2023 00:57:57 -0800 (PST) Hi Zhang, zhang_shurong@foxmail.com wrote on Sat, 2 Dec 2023 22:58:52 +0800: > The syzkaller reported an issue: Subject should start with [PATCH wpan] >=20 > BUG: KMSAN: uninit-value in ieee802154_hdr_push_sechdr net/ieee802154/hea= der_ops.c:54 [inline] > BUG: KMSAN: uninit-value in ieee802154_hdr_push+0x971/0xb90 net/ieee80215= 4/header_ops.c:108 > ieee802154_hdr_push_sechdr net/ieee802154/header_ops.c:54 [inline] > ieee802154_hdr_push+0x971/0xb90 net/ieee802154/header_ops.c:108 > ieee802154_header_create+0x9c0/0xc00 net/mac802154/iface.c:396 > wpan_dev_hard_header include/net/cfg802154.h:494 [inline] > dgram_sendmsg+0xd1d/0x1500 net/ieee802154/socket.c:677 > ieee802154_sock_sendmsg+0x91/0xc0 net/ieee802154/socket.c:96 > sock_sendmsg_nosec net/socket.c:725 [inline] > sock_sendmsg net/socket.c:748 [inline] > ____sys_sendmsg+0x9c2/0xd60 net/socket.c:2494 > ___sys_sendmsg+0x28d/0x3c0 net/socket.c:2548 > __sys_sendmsg+0x225/0x3c0 net/socket.c:2577 > __compat_sys_sendmsg net/compat.c:346 [inline] > __do_compat_sys_sendmsg net/compat.c:353 [inline] > __se_compat_sys_sendmsg net/compat.c:350 [inline] >=20 > We found hdr->key_id_mode is uninitialized in mac802154_set_header_securi= ty() > which indicates hdr.fc.security_enabled should be 0. However, it is set t= o be cb->secen before. > Later, ieee802154_hdr_push_sechdr is invoked, causing KMSAN complains uni= nit-value issue. I am not too deeply involved in the security header but for me it feels like your patch does the opposite of what's needed. We should maybe initialize hdr->key_id_mode based on the value in cb->secen, no? (maybe Alexander will have a better understanding than I have). > Since mac802154_set_header_security() sets hdr.fc.security_enabled based = on the variables > ieee802154_sub_if_data *sdata and ieee802154_mac_cb *cb in a collaborativ= e manner. > Therefore, we should not set security_enabled prior to mac802154_set_head= er_security(). >=20 > Fixed it by removing the line that sets the hdr.fc.security_enabled. >=20 > Syzkaller don't provide repro, and I provide a syz repro like: > r0 =3D syz_init_net_socket$802154_dgram(0x24, 0x2, 0x0) > setsockopt$WPAN_SECURITY(r0, 0x0, 0x1, &(0x7f0000000000)=3D0x2, 0x4) > setsockopt$WPAN_SECURITY(r0, 0x0, 0x1, &(0x7f0000000080), 0x4) > sendmsg$802154_dgram(r0, &(0x7f0000000100)=3D{&(0x7f0000000040)=3D{0x24, = @short}, 0x14, &(0x7f00000000c0)=3D{0x0}}, 0x0) >=20 > Fixes: 32edc40ae65c ("ieee802154: change _cb handling slightly") > Signed-off-by: Zhang Shurong > --- This is a resend, a message in a shortlog to express why is welcome. If it's a ping, then no need to resend. > net/mac802154/iface.c | 1 - > 1 file changed, 1 deletion(-) >=20 > diff --git a/net/mac802154/iface.c b/net/mac802154/iface.c > index c0e2da5072be..c99b6e40a5db 100644 > --- a/net/mac802154/iface.c > +++ b/net/mac802154/iface.c > @@ -368,7 +368,6 @@ static int ieee802154_header_create(struct sk_buff *s= kb, > =20 > memset(&hdr.fc, 0, sizeof(hdr.fc)); > hdr.fc.type =3D cb->type; > - hdr.fc.security_enabled =3D cb->secen; > hdr.fc.ack_request =3D cb->ackreq; > hdr.seq =3D atomic_inc_return(&dev->ieee802154_ptr->dsn) & 0xFF; > =20 Thanks, Miqu=C3=A8l