Received: by 2002:a89:2c3:0:b0:1ed:23cc:44d1 with SMTP id d3csp20060lqs; Mon, 4 Mar 2024 13:32:56 -0800 (PST) X-Forwarded-Encrypted: i=3; AJvYcCUXh8mYHQ1v+0Sf6JxSmMDBF/0Pxgk29FUouizplv44WTlhVD48Xb5bzMCqQC/KOeKxHtXRFHFtOl0mTXItfmtfeVVDFXZ/QZ1rYJs65A== X-Google-Smtp-Source: AGHT+IHsZ6oF5+3+X0qgeUb9D/cNN3f8Nyf362bWe/hFaWniYwcvN8l/f3lXaqRgbln+PHG/sJLC X-Received: by 2002:a05:6402:35cc:b0:566:f851:f53b with SMTP id z12-20020a05640235cc00b00566f851f53bmr7906169edc.35.1709587976333; Mon, 04 Mar 2024 13:32:56 -0800 (PST) ARC-Seal: i=2; a=rsa-sha256; t=1709587976; cv=pass; d=google.com; s=arc-20160816; b=hfww3igQpKoH6FVdERgXfn7r5jtK7495gGMD9kzDkr2CtYexLqDInPuVHNh2sHM085 hhL6q3pqUmGiZe4g3B+1Z/pgcXYS2xThmHRnwtwcxji9bv+H6c8ci/jXRwD0PxaQ7o6S SGQwy+9w138siy0XvCNgO/Ar0ifdnrTaVxzL3sKM9m/a8oLlcPQ6duY0crwpM3gdlbLH IdEka1C5+PLpRetBvvNWcxbFrA+/5mCdPAHNVzJNDrjTfk5MtJZYDqQs6jkI9jHnzdT7 Pp4sxLvt1BggNpVztG0zwjVAYq7SOvk/bEtU9ZJrKyrPwL/PX2rkoq7tBzqnhaZaz1vZ pRlw== ARC-Message-Signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=in-reply-to:content-disposition:mime-version:list-unsubscribe :list-subscribe:list-id:precedence:references:message-id:subject:cc :to:from:date:dkim-signature; bh=5AAGBs1uayIPxzgb5qVJOa8HOKMdVNYp2rAU1bHGoGE=; fh=p5bCogN7i8T11+B2GvTvZcOGJFE+JkjfOkmANd24RHM=; b=gfsfakzgYvFAFMpPvlSO9QhTGIx0uiKHO7bVTtK9i7uVeeDSbg++BGk46cJPSIX3Y3 owM3TegJHxb9wyB1dDBWzNx2BTcA0WgXCXr0L+Licmk/1XNYwAxXx1C5MzEFy4QAQCFF 8YqBQiKtkAbezg1GQQ212k7EHDm0jPRsZwGpbWQdagVLatgC0UxRjQoKVIIEJDxSSyoz +7Vv76W8sSsJmkYT6cMzTyrCEKIdxrLYfP+8Z1xj4HC/pynnFD6U5x7kT56Hh5dTArZ8 GvTQVigiR/Wz6rxYGJ2IYQujrJY1T6n3zhuIsm6htWyFeM5xgwJ5AcA7fYquVLapTlNy /J+w==; dara=google.com ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@chromium.org header.s=google header.b=LlxvZC8d; arc=pass (i=1 spf=pass spfdomain=chromium.org dkim=pass dkdomain=chromium.org dmarc=pass fromdomain=chromium.org); spf=pass (google.com: domain of linux-kernel+bounces-91311-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:4601:e00::3 as permitted sender) smtp.mailfrom="linux-kernel+bounces-91311-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=chromium.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 n13-20020aa7c44d000000b0056782ecb183si140109edr.11.2024.03.04.13.32.56 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 04 Mar 2024 13:32:56 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel+bounces-91311-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=@chromium.org header.s=google header.b=LlxvZC8d; arc=pass (i=1 spf=pass spfdomain=chromium.org dkim=pass dkdomain=chromium.org dmarc=pass fromdomain=chromium.org); spf=pass (google.com: domain of linux-kernel+bounces-91311-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:4601:e00::3 as permitted sender) smtp.mailfrom="linux-kernel+bounces-91311-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=chromium.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 D927B1F21833 for ; Mon, 4 Mar 2024 21:32:55 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id BEC677B3FA; Mon, 4 Mar 2024 21:32:24 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=chromium.org header.i=@chromium.org header.b="LlxvZC8d" Received: from mail-pf1-f181.google.com (mail-pf1-f181.google.com [209.85.210.181]) (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 52A6B7BAF0 for ; Mon, 4 Mar 2024 21:32:22 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.210.181 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1709587943; cv=none; b=SKqwtJDR0y3khRByB1M1eTEnMsuKWBuTtVPoVJY8lCNwk2DJnRQvdI751NgHfqkU1Rrh/aUB6RXXGnhc4mhc719C2VxlcQRUBfofuJ1/OnctHZZucjK3RFuv07vh6/VjITSFcf99eISA0Y940zdf047Wx1/41DTW9LfCqSeWk+Q= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1709587943; c=relaxed/simple; bh=Fid7qZAd/FJHN/tsMQvT21XJE1w7mAABpnaR9DnDguQ=; h=Date:From:To:Cc:Subject:Message-ID:References:MIME-Version: Content-Type:Content-Disposition:In-Reply-To; b=Sm5IOpeklQJ5Q6v9YX7uaS1sznM1eoPeGw8dMXOMrHNJm99NUN2YlKO08mk1oj0PlXrWC2+DvjqQYouZn6yc7Ia/Mc8LRpzYhFlBHfq6lQJXjHcfrpBX/eJ+SiY4fmDaMCLVPHlf9EA2OKYY6gu6KDanKrQo9gK7tauSeAV4MLY= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=chromium.org; spf=pass smtp.mailfrom=chromium.org; dkim=pass (1024-bit key) header.d=chromium.org header.i=@chromium.org header.b=LlxvZC8d; arc=none smtp.client-ip=209.85.210.181 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=chromium.org Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=chromium.org Received: by mail-pf1-f181.google.com with SMTP id d2e1a72fcca58-6e6381df003so204946b3a.0 for ; Mon, 04 Mar 2024 13:32:22 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=chromium.org; s=google; t=1709587941; x=1710192741; darn=vger.kernel.org; h=in-reply-to:content-disposition:mime-version:references:message-id :subject:cc:to:from:date:from:to:cc:subject:date:message-id:reply-to; bh=5AAGBs1uayIPxzgb5qVJOa8HOKMdVNYp2rAU1bHGoGE=; b=LlxvZC8dI4upTIvgiol1/vPFgKgj0eEt9Rlrekdddxoa1plFoW6paMLc2u/8Z0C98l whP6lPQDQHBOBOXmn2tEdmakrisCM5AC4ZVF2ljUz2f9OnVkT4P3rs/eDlqB97Wjs7fl oqLKO6CSdmej4UMCvQKeBtYiufJL65tLIY1aA= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1709587941; x=1710192741; h=in-reply-to:content-disposition:mime-version:references:message-id :subject:cc:to:from:date:x-gm-message-state:from:to:cc:subject:date :message-id:reply-to; bh=5AAGBs1uayIPxzgb5qVJOa8HOKMdVNYp2rAU1bHGoGE=; b=dt5qmXS5lVgDjWeBvIJh4IHqOLx++EWdmelu59FxEJ3DsH8xz77eHizFNql1/rD2+R X8ZEqr+usiSnzDjym8N6zzJIpuOJWrJ9LcmNYSYpYc4Sw1AU3tEREHegAeUijW6UhPib zqVVo2icXpMVzCbmjydKHMn6dqj/IiD9KFshdYnbH2I6uxfbI9+EG55iTIXUsoNl/Jlm igryJfSX8fpxMn+qKWtYHtlsGH2NIq82IGm3ri1cVkJ9RUBdDtyPWw0iNZexyBphlJ0S q/CMPRCGNQF5XXmCalmW8mTvPeN27gcoDP46q3PAiRkp4Dui9ZX5fLJmGGVsnhA8aKA7 rG3Q== X-Forwarded-Encrypted: i=1; AJvYcCX9YWtJ6N+KSldeUr8r75szyRSa7VBZMlkfjcRsDBziVRlJOJePnMBQiWOWwedwBfkkV0zd6bDwvm+w+AeFRWDOZ94gcA0k0qGgK5qm X-Gm-Message-State: AOJu0Yw7Se0rI1Zs6aO4WsTfTUSjO2nJc0TEO6Q5nqPVaMwK5HL3Cxsl 1j/abUMFatH1gnxNjScvvn2QFG+MnUUG/n44xCqJ4TBfz4SB9IQ9SRhX1i7wfQ== X-Received: by 2002:a05:6a20:3c8d:b0:1a1:2a5b:a6c3 with SMTP id b13-20020a056a203c8d00b001a12a5ba6c3mr12600656pzj.3.1709587941650; Mon, 04 Mar 2024 13:32:21 -0800 (PST) Received: from www.outflux.net ([198.0.35.241]) by smtp.gmail.com with ESMTPSA id w62-20020a636241000000b005e485fbd455sm7872070pgb.45.2024.03.04.13.32.21 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 04 Mar 2024 13:32:21 -0800 (PST) Date: Mon, 4 Mar 2024 13:32:20 -0800 From: Kees Cook To: Dave Chinner Cc: Vlastimil Babka , Christian Brauner , Alexander Viro , Jan Kara , linux-fsdevel@vger.kernel.org, "GONG, Ruiqi" , Xiu Jianfeng , Suren Baghdasaryan , Kent Overstreet , Andrew Morton , Christoph Lameter , Pekka Enberg , David Rientjes , Joonsoo Kim , Roman Gushchin , Hyeonggon Yoo <42.hyeyoo@gmail.com>, linux-kernel@vger.kernel.org, linux-mm@kvack.org, linux-hardening@vger.kernel.org Subject: Re: [PATCH 3/4] xattr: Use dedicated slab buckets for setxattr() Message-ID: <202403041330.06842D397@keescook> References: <20240304184252.work.496-kees@kernel.org> <20240304184933.3672759-3-keescook@chromium.org> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: On Tue, Mar 05, 2024 at 08:16:30AM +1100, Dave Chinner wrote: > On Mon, Mar 04, 2024 at 10:49:31AM -0800, Kees Cook wrote: > > The setxattr() API can be used for exploiting[1][2][3] use-after-free > > type confusion flaws in the kernel. Avoid having a user-controlled size > > cache share the global kmalloc allocator by using a separate set of > > kmalloc buckets. > > > > Link: https://duasynt.com/blog/linux-kernel-heap-spray [1] > > Link: https://etenal.me/archives/1336 [2] > > Link: https://github.com/a13xp0p0v/kernel-hack-drill/blob/master/drill_exploit_uaf.c [3] > > Signed-off-by: Kees Cook > > --- > > Cc: Christian Brauner > > Cc: Alexander Viro > > Cc: Jan Kara > > Cc: linux-fsdevel@vger.kernel.org > > --- > > fs/xattr.c | 12 +++++++++++- > > 1 file changed, 11 insertions(+), 1 deletion(-) > > > > diff --git a/fs/xattr.c b/fs/xattr.c > > index 09d927603433..2b06316f1d1f 100644 > > --- a/fs/xattr.c > > +++ b/fs/xattr.c > > @@ -821,6 +821,16 @@ SYSCALL_DEFINE4(fgetxattr, int, fd, const char __user *, name, > > return error; > > } > > > > +static struct kmem_buckets *xattr_buckets; > > +static int __init init_xattr_buckets(void) > > +{ > > + xattr_buckets = kmem_buckets_create("xattr", 0, 0, 0, > > + XATTR_LIST_MAX, NULL); > > + > > + return 0; > > +} > > +subsys_initcall(init_xattr_buckets); > > + > > /* > > * Extended attribute LIST operations > > */ > > @@ -833,7 +843,7 @@ listxattr(struct dentry *d, char __user *list, size_t size) > > if (size) { > > if (size > XATTR_LIST_MAX) > > size = XATTR_LIST_MAX; > > - klist = kvmalloc(size, GFP_KERNEL); > > + klist = kmem_buckets_alloc(xattr_buckets, size, GFP_KERNEL); > > There's a reason this uses kvmalloc() - allocations can be up to > 64kB in size and it's not uncommon for large slab allocation to > fail on long running machines. hence this needs to fall back to > vmalloc() to ensure that large xattrs can always be read. I can add a vmalloc fallback interface too. It looked like the larger xattr usage (8k-64k) was less common, but yeah, let's not remove the correct allocation fallback here. I'll fix this for v2. Thanks! -Kees -- Kees Cook