Received: by 2002:a05:7208:9594:b0:7e:5202:c8b4 with SMTP id gs20csp125672rbb; Fri, 23 Feb 2024 14:21:51 -0800 (PST) X-Forwarded-Encrypted: i=3; AJvYcCUA6H+/RIrNj7zdcqeJcCIT3hZqZlvAWbQbt7QZdMw6NyX48OLHxAjGHQtCeW7MvVX+fTI8/TjPNE7d7uId0phC+wpYwLdw9NEpovl12g== X-Google-Smtp-Source: AGHT+IGPyW7NcW3/ZB/4sI+yidixa8e6SqayDDgMuelK/Hc6cy+EIROE1SOe0H85FMaM8XmEtq3D X-Received: by 2002:aa7:d384:0:b0:565:983d:7bbb with SMTP id x4-20020aa7d384000000b00565983d7bbbmr340630edq.14.1708726911666; Fri, 23 Feb 2024 14:21:51 -0800 (PST) ARC-Seal: i=2; a=rsa-sha256; t=1708726911; cv=pass; d=google.com; s=arc-20160816; b=VHfhtu3vYu2oFqPrA8qmsa4ieIUC+yBqePh8UIIPZ6wyUYQ4Kv9OlrNTbXHc2iYD2w jKDRi+qXKplTVPLP4xC75YjZpq2uFJSNYZOBwjmQTf9u3UGsrI99cxozcX31VmfRVuXM DbQo183frVUJVX/MfJQE6DGTpS8OqQikQLoSK6u0r0xTYnKel08vBE8rNuS/OXGMd+o5 MtxRyCbrudmzMwKTcPy1MuF1orcPnGaBhzWhdb8zD9sAiuKDfYFTo91lJ11cnlnN4W3V IGTr35SN6AJXMjtq2QGj/aa/nqDhdqfudBmF3gzK6cg2vdalvN8kQcDU+K+LTueJ9J5C vd3A== ARC-Message-Signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=content-transfer-encoding:cc:to:subject:message-id:date:from :in-reply-to:references:mime-version:list-unsubscribe:list-subscribe :list-id:precedence:dkim-signature; bh=ZSHK5epAuKvdBFEuYnQb3nyTXVxrBoDNXBYJr9NtKwo=; fh=e0mgL3tkk2w+URqfZlsT5s/Xenv3OsBZKXCxgusVTzg=; b=m5zMjz2SF28vBr/pqoIM3tPhqqJWlWmLZK8Wz8YlFDOlboC+LxdhY/zI2VN8RBfBaT c9u4jqCBsBtq/dBSey82R+c3iNC+gjK3YWf+bAsz6dws/np/obIctYMyPTLg1RuvrZ4l KP1H5RsqC9e6K2UjGnXfGscRwCfblkn0gKtzQxocA/VdS2EKKc/wlUyhdOk2UwW9ZinZ XcNgA7zH3LYP8qcvCZIG1GRCRPL+FP3nUh0FudiX8AKRJUorxGMoFsT2XFYpW0pSODgL awfUY4DtRBNZaacCmMIXQGgvRQdnnRhqrSRcBMVLC4Gfd5CsD05QxZ4EIl3NezMt8+xv rwFQ==; dara=google.com ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@paul-moore.com header.s=google header.b=DGeG1NJ2; arc=pass (i=1 spf=pass spfdomain=paul-moore.com dkim=pass dkdomain=paul-moore.com dmarc=pass fromdomain=paul-moore.com); spf=pass (google.com: domain of linux-kernel+bounces-79248-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:4601:e00::3 as permitted sender) smtp.mailfrom="linux-kernel+bounces-79248-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=paul-moore.com Return-Path: Received: from am.mirrors.kernel.org (am.mirrors.kernel.org. [2604:1380:4601:e00::3]) by mx.google.com with ESMTPS id ck3-20020a0564021c0300b00563c179b9a0si6603831edb.484.2024.02.23.14.21.51 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 23 Feb 2024 14:21:51 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel+bounces-79248-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=@paul-moore.com header.s=google header.b=DGeG1NJ2; arc=pass (i=1 spf=pass spfdomain=paul-moore.com dkim=pass dkdomain=paul-moore.com dmarc=pass fromdomain=paul-moore.com); spf=pass (google.com: domain of linux-kernel+bounces-79248-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:4601:e00::3 as permitted sender) smtp.mailfrom="linux-kernel+bounces-79248-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=paul-moore.com 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 131801F229E4 for ; Fri, 23 Feb 2024 22:21:51 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 402AB14DFC1; Fri, 23 Feb 2024 22:21:39 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=paul-moore.com header.i=@paul-moore.com header.b="DGeG1NJ2" Received: from mail-yb1-f178.google.com (mail-yb1-f178.google.com [209.85.219.178]) (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 D8FA214DFD2 for ; Fri, 23 Feb 2024 22:21:32 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.219.178 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1708726898; cv=none; b=Ys09cGu7D8/4El2FI/1TGx4qf/Y/xilH6uOzuvbrCLlYq01TNatJy1qYgaJywdOjZlVDC2aZmKHSLfdullxLv+xwvWaKqonzRfR+BKOCd5K4lZcFKaYKsEm8GDnrcmokXq7/Bm8lJN1blyI7PK0l7aQy1ELzfd6W966AOkcE9s8= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1708726898; c=relaxed/simple; bh=tCxLkZaiXV0zdt3VLXgnun/1lqJgVCO7ceU56CFwRpU=; h=MIME-Version:References:In-Reply-To:From:Date:Message-ID:Subject: To:Cc:Content-Type; b=PqGMrPYQeuRjp7ZjjqHxsj5wcLJTOauzpeRg1fmAMYa/yeJHl9wSNGWnV8vMFEFSgbVybhEgfzJ4dtyXSXgLXtTMe5AcM21GeFYHvStlywNcxODvH2NtGZiKzH2ZIbObscbu8q+EAlGQanUYewKMAJyCoFe0PTdraonXx+8ibdc= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=paul-moore.com; spf=pass smtp.mailfrom=paul-moore.com; dkim=pass (2048-bit key) header.d=paul-moore.com header.i=@paul-moore.com header.b=DGeG1NJ2; arc=none smtp.client-ip=209.85.219.178 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=paul-moore.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=paul-moore.com Received: by mail-yb1-f178.google.com with SMTP id 3f1490d57ef6-dcc86086c9fso1375636276.3 for ; Fri, 23 Feb 2024 14:21:32 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=paul-moore.com; s=google; t=1708726892; x=1709331692; darn=vger.kernel.org; h=content-transfer-encoding:cc:to:subject:message-id:date:from :in-reply-to:references:mime-version:from:to:cc:subject:date :message-id:reply-to; bh=ZSHK5epAuKvdBFEuYnQb3nyTXVxrBoDNXBYJr9NtKwo=; b=DGeG1NJ2i9WQOHMWBbz9z8nrmtXaogxgI5TGhyK4p/hjJMW8UG7NVPc/g7B467Iihv yuIQvf/mi1PSkisYQja3NlvZP/ibnX59/wVuAXrotALE5Rml7Cr2RMT7TJYtszr0xzpc Xz7bSENYj9Ebn6oiSA9GzRUx7TvCbCspCQG/KunAEF2QghjvI+o5GirNRqaL63z8x7J8 NCMCe4PhEVJj5lntgr6zco47iNn6EAEbFIAd8XBrHXJkZeZY+kwjmSGdgp+XTlhZu0sE yMs+M7TvEMAQ3jYyBcnK1cTplkAmac6d6fjlYAXbK4rjAfpNVTOw7X2wQ5INnUqVFlzG CK5A== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1708726892; x=1709331692; h=content-transfer-encoding:cc:to:subject:message-id:date:from :in-reply-to:references:mime-version:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=ZSHK5epAuKvdBFEuYnQb3nyTXVxrBoDNXBYJr9NtKwo=; b=tn/M9JWGoTs0aK+eXXWukO3u++EcczB5WF1Zn9qjDKw9CHnCTpd+DogRtcUIqnjFy6 Z5Efay5AoVj7/QWdoqvgA8SyG1r90GQ0w4rrLrUkg0e5TGBrIPgG8PYF4QZ8ga9XJn91 bY1EYq8+XwV2zGBuArjN34JGKUEvAmknXsF4dvNHGPIPdLaUtZaru5x/q7zL3zvAge7o t7AB0CGzZz+hMdVhK/I9DQgXHEgFXM/R8zKUmMKPjXZK+SYurkJOFXJUMsRAJrcD7zRD AFiB6tZ3sIed3YRm8uDkeC6JB1TLRe55xtvuANh3/oHAlgmnqNQbqMQbci4kMnnvjm4X Aeyw== X-Forwarded-Encrypted: i=1; AJvYcCWx3gjTnjSWTlIWmC+bMsGtaela/mCZ/SjxhAaAmUBIOg4TBglrMdnLRoW6jzsEh6kg8KzK+hovliG6tHRZkhrZTKkk6lTc5jJmO6zY X-Gm-Message-State: AOJu0YyCH46FG8o3lbFYrZsDJ1u03Ui9XEluWTuYOA1n5RbzBPKWgANs vza3HRyUDnouVoyNmiIQ9prHCZ7jGvtKTiGyUDnorxroyu+MdIXwLOP9uXl+qXX3u9A6dHo0u5Q xwARnMuR3CIznHd330vPUQZdWY3Tcvt7OvLrI X-Received: by 2002:a25:d0d4:0:b0:dcc:9dcc:a433 with SMTP id h203-20020a25d0d4000000b00dcc9dcca433mr1335893ybg.54.1708726891747; Fri, 23 Feb 2024 14:21:31 -0800 (PST) Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 References: <20240223190546.3329966-1-mic@digikod.net> <20240223.ieSh2aegurig@digikod.net> <20240223.eij0Oudai0Ia@digikod.net> <20240223.goo9Xei0xa9S@digikod.net> In-Reply-To: <20240223.goo9Xei0xa9S@digikod.net> From: Paul Moore Date: Fri, 23 Feb 2024 17:21:20 -0500 Message-ID: Subject: Re: [PATCH 1/2] SELinux: Fix lsm_get_self_attr() To: =?UTF-8?B?TWlja2HDq2wgU2FsYcO8bg==?= Cc: Casey Schaufler , John Johansen , James Morris , "Serge E . Hallyn" , linux-kernel@vger.kernel.org, linux-security-module@vger.kernel.org, stable@vger.kernel.org, selinux@vger.kernel.org Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: quoted-printable On Fri, Feb 23, 2024 at 5:03=E2=80=AFPM Micka=C3=ABl Sala=C3=BCn wrote: > On Fri, Feb 23, 2024 at 04:05:16PM -0500, Paul Moore wrote: > > On Fri, Feb 23, 2024 at 3:04=E2=80=AFPM Micka=C3=ABl Sala=C3=BCn wrote: > > > > > > On Fri, Feb 23, 2024 at 08:59:34PM +0100, Micka=C3=ABl Sala=C3=BCn wr= ote: > > > > On Fri, Feb 23, 2024 at 08:05:45PM +0100, Micka=C3=ABl Sala=C3=BCn = wrote: > > > > > selinux_lsm_getattr() may not initialize the value's pointer in s= ome > > > > > case. As for proc_pid_attr_read(), initialize this pointer to NU= LL in > > > > > selinux_getselfattr() to avoid an UAF in the kfree() call. > > > > > > > > Not UAF but NULL pointer dereference (both patches)... > > > > > > Well, that may be the result (as observed with the kfree() call), but > > > the cause is obviously an uninitialized pointer. > > > > Adding the SELinux list to the CC line; SELinux folks the original post= is here: > > > > * https://lore.kernel.org/all/20240223190546.3329966-1-mic@digikod.net > > > > Thanks for finding this and testing the patch, based on our off-list > > discussion, do you mind if I add a Suggested-by? Looking at this a > > Sure! I was in a hurry and didn't give it the attention it needed... > > > bit more I think we'll want to make a few changes to > > selinux_lsm_getattr() later, but this patch is a good one for stable > > as it not only fixes the bug, but it is a trivial one-liner with very > > low risk. > > > > I do think we need to tweak the commit description a bit, what do you > > think of the following? > > > > "selinux_getselfattr() doesn't properly initialize the string > > pointer it passes to selinux_lsm_getattr() which can cause a > > problem when an attribute hasn't been explicitly set; > > selinux_lsm_getattr() returns 0/success, but does not set or > > initialize the string label/attribute. Failure to properly > > initialize the string causes problems later in > > selinux_getselfattr() when the function attempts to kfree() > > the string." > > Much better! Great :) I just went ahead and merged this into the lsm/stable-6.8 branch to get this some testing in linux-next, although I'm going to be *shocked* if this commit causes a regression. I'll send this up to Linus early next week, and if John wants me to send the AppArmor patch I'll do that at the same time. --=20 paul-moore.com