Received: by 2002:a05:7412:b10a:b0:f3:1519:9f41 with SMTP id az10csp1507076rdb; Fri, 1 Dec 2023 21:16:25 -0800 (PST) X-Google-Smtp-Source: AGHT+IHGxj1Ay8Ez2OfMFnd2Sn7T8GMc9sl/K2Fs9BP+x+N++YhHFDETm0tUcb5LtM6yxbejnWPP X-Received: by 2002:a50:a444:0:b0:54c:67c0:831f with SMTP id v4-20020a50a444000000b0054c67c0831fmr889854edb.13.1701494185208; Fri, 01 Dec 2023 21:16:25 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1701494185; cv=none; d=google.com; s=arc-20160816; b=H1vbzgLScZV1J8jwaRu1ucJXlWVyoVexkavBg0hFLkPSoV3J2ubADinmmNYTEXvo2n JZBEU1bXBOOfBIouyfRrWojsLiii4q5uzUwqgy+Kpn5zzyZPdmRonBNBdaaR31ptCPZe 0vniAkjHR+aN5q9Cx3/m9QkTEn+1Q0HfITP7RRRU71/0RoWlBsIWpc8G4a3hWFrfVmiw DEalPNK04ktAR9rmBQnruxaGXGIoRGE+ZeegbZQ5nvvwmtj1/b3kmHqSTv3PS0wwFwt1 zFp0GXHOf87Qiv9S2rq1wQf8MZjqySBEFED7E92ObErQFMaYf9ImNuInSzABFp66qss+ WvWA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=content-transfer-encoding:mime-version:list-unsubscribe :list-subscribe:list-id:precedence:references:in-reply-to:message-id :subject:cc:to:from:date:dkim-signature; bh=CdAQJd5gWEezH5bF7wsiv9G+cJHpHo+/FUHPnNi2Los=; fh=EN1+PnvKdn4Mnl9NT4IZDzFcV6XEJ3EDYA++33PfDng=; b=bOGyoGOoPrRP90XnIis7Qqf3RtSFql+boAaL2kz4Hacp7Mu2l41P+cLF3V1ayJW4H0 tDrhzvXl9EbdKvfkJS/8wxdTKc1EIKPqXYf/m+UlD7oUTuqmT45KD+X4lyurM6K0ILsp mkUfE4XUFaZe+Yf+FZ/caRyv1BuyjCmRCZ2+R5KHIOj0weWJ0FIo8WwGkiTrQAqCJVSi LFxidtemPXGJP2DWZxW94cLXGOFVEHO0PGgHbiSE/AcQy2oeQy0o7ns/JS1crQwy6ltX pk0tBvawDaRsPIPoI4dJMmvSQWLiilRh3rN1KRfSlgfx7nHsYR/ZIo5WHUx26VQ00QF0 HM2w== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=k20201202 header.b="awNc6pr/"; spf=pass (google.com: domain of linux-wireless+bounces-319-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:4601:e00::3 as permitted sender) smtp.mailfrom="linux-wireless+bounces-319-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Return-Path: Received: from am.mirrors.kernel.org (am.mirrors.kernel.org. [2604:1380:4601:e00::3]) by mx.google.com with ESMTPS id r22-20020a50aad6000000b0054c49b61ab0si1494078edc.56.2023.12.01.21.16.25 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 01 Dec 2023 21:16:25 -0800 (PST) Received-SPF: pass (google.com: domain of linux-wireless+bounces-319-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:4601:e00::3 as permitted sender) client-ip=2604:1380:4601:e00::3; Authentication-Results: mx.google.com; dkim=pass header.i=@kernel.org header.s=k20201202 header.b="awNc6pr/"; spf=pass (google.com: domain of linux-wireless+bounces-319-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:4601:e00::3 as permitted sender) smtp.mailfrom="linux-wireless+bounces-319-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Received: from smtp.subspace.kernel.org (wormhole.subspace.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by am.mirrors.kernel.org (Postfix) with ESMTPS id 93EB91F21165 for ; Sat, 2 Dec 2023 05:16:24 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 9F9FD8F7D; Sat, 2 Dec 2023 05:16:19 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b="awNc6pr/" X-Original-To: linux-wireless@vger.kernel.org Received: from smtp.kernel.org (aws-us-west-2-korg-mail-1.web.codeaurora.org [10.30.226.201]) (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 7662F619BF; Sat, 2 Dec 2023 05:16:19 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 5E1FEC433CA; Sat, 2 Dec 2023 05:16:18 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1701494179; bh=a5C2kC+KSpawAbx8lhoz4O1Yt38hNED4Gqe/bJLIJXs=; h=Date:From:To:Cc:Subject:In-Reply-To:References:From; b=awNc6pr/csIVFZadi+dsjlFqJH0vMZ2ya0aZlzFChyv3Oe81+rw4R9lfv5pE6X1Wu zJDPqLj3FNIO9IyUbrp9totzo/CPWBzfCCb8Jxd7tqbqWcbkcimAEFCaE1bzClx5Mz ZmQN3rKeEA4xL5k9EXnOiUohZVbj+iOBVa2GaOzC/Y5QGV29IIXPr8dbfiQcehiCWq uaigaHSZhkJ0BrxfRrH4qXSBzLdLSLdxIn00RkSYMhqY+RePTkHFLfTYcV+S9knhEK 5ZCDev0zcE2qBfG3SoETXSspt3Iy0lIqg82doFYapGl5rokjwF7PtgkttShxOF/xdI 92qvdxwXfvHDw== Date: Fri, 1 Dec 2023 21:16:17 -0800 From: Jakub Kicinski To: Kees Cook Cc: kernel test robot , "David S. Miller" , Eric Dumazet , Paolo Abeni , Johannes Berg , Jeff Johnson , Michael Walle , Max Schulze , netdev@vger.kernel.org, linux-wireless@vger.kernel.org, linux-kernel@vger.kernel.org, linux-hardening@vger.kernel.org Subject: Re: [PATCH] netlink: Return unsigned value for nla_len() Message-ID: <20231201211617.30371d79@kernel.org> In-Reply-To: <202312012026.A0178237@keescook> References: <20231130200058.work.520-kees@kernel.org> <20231130172520.5a56ae50@kernel.org> <202312010953.BEDC06111@keescook> <20231201104505.44ec5c89@kernel.org> <202312012026.A0178237@keescook> Precedence: bulk X-Mailing-List: linux-wireless@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Type: text/plain; charset=US-ASCII Content-Transfer-Encoding: 7bit On Fri, 1 Dec 2023 20:39:44 -0800 Kees Cook wrote: > > We are reading nla->nla_len, which is the first 2 bytes of the structure. > > And then we check if the structure is... there? > > I'm not debating whether it's there or not -- I'm saying the _contents_ of > "nlattr::nla_len", in the face of corruption or lack of initialization, > may be less than NLA_HDRLEN. (There's a lot of "but that's can't happen" > that _does_ happen in the kernel, so I'm extra paranoid.) nlattr is not an object someone has allocated. It's a header of a TLV in a byte stream of nested TLVs which comes from user space. If the attr did not go thru nla_ok() or some other careful validation we're toast regardless. > > If we don't trust that struct nlattr which gets passed here is at least > > NLA_HDRLEN (4B) then why do we think it's safe to read nla_len (the > > first 2B of it)? > > Type confusion (usually due to Use-after-Free flaws) means that a memory > region is valid (i.e. good pointer), but that the contents might have > gotten changed through other means. (To see examples of this with > struct msg_msg, see: https://syst3mfailure.io/wall-of-perdition/) A bit of a long read. > (On a related note, why does nla_len start at 4 instead of 0? i.e. why > does it include the size of nlattr? That seems redundant based on the > same logic you're using here.) Beats me.