Received: by 2002:ab2:3141:0:b0:1ed:23cc:44d1 with SMTP id i1csp2052443lqg; Mon, 4 Mar 2024 11:16:07 -0800 (PST) X-Forwarded-Encrypted: i=3; AJvYcCV01aSs5DZ5oOZ4zAGKzKyI3tx4KfiBL5+AMwdjyjCz81zNxWjnDgFVxJnYEMgbOtF3BPFplKunp/DUa9Lhcc7g/H+lfzF6HlGPfp8a/w== X-Google-Smtp-Source: AGHT+IGRg+Jfpstjx/vSPcuF52PCNJ7pXi5hJwJS/LffAZoQjYXPlpjF3nuMqKtXRa7kLX2JL14b X-Received: by 2002:a17:902:b717:b0:1dc:1c81:1b17 with SMTP id d23-20020a170902b71700b001dc1c811b17mr7749820pls.55.1709579767280; Mon, 04 Mar 2024 11:16:07 -0800 (PST) ARC-Seal: i=2; a=rsa-sha256; t=1709579767; cv=pass; d=google.com; s=arc-20160816; b=gF27UNyN/+KwA//rC7PS37udscV1YtiTD9hNMRfSkQ7Z8Vp9N4pnvApPA4J3UDg4cR L4HBtGdWz9BCAkz8Yfx4PPc/t+ff+T9PKyKrEPnhgfuVdRF6HyMbtalXOt/OIOY7o+fq 8YkaHBex2PE3SdQDI9JcaQHQkx1xoxy1hL02aR2KdPG65TgSFGvAMx2QA5I9KZ2lycAT /AE4/r4qAdrtbXWSQWP+6pBzAZ/zphrQkTAtsWPrEWUweSDXTobW89BCAXx+5IYLt3tM JPuajBXxXd7MKBfAR0fkpCpr6u4KtqkxjvulA19JkCI8ZBxtUDx25fzoW+EjiQCH/YL5 OuVw== ARC-Message-Signature: i=2; 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 :date:subject:cc:to:from:dkim-signature; bh=2QOKxvJdszgSExOijEeIBqvAxDpXCtl9o7KCQ12P01Y=; fh=mAC9rFqYXNpDUAXFhl9K6OFev6kXd0XtxmLDG0MaaGA=; b=x3nPLk6Lnubtk58I5lcZ7gsLNFoJW6Y8D+TwbRlSrLBneBHYSF0Wg8jsJ5GjmM0p+Z kimMCnFRFVo4ge/fe37d4ybIM7O0nsQMzRyXVxRkbnmoGGxJQewJHpWgzeLCSSuQkEGt 8UP2hV4puMrYYttDmRCfCNwqY4GxFx06g0+xstimKKL3Nge9waZXSa7eJRnqgwZH782v b9OxQ/seeJZ0xxRbH6We5DwgUcXc8k4AOmJ7fFyl+xLDmgPAxzxEvgyyHzLb3ayv26bk hAeHZT32BOio6hsEcyAK40OJaPekEuCVxb87wpuSJcRpHGJUECILMdiz7J3d+k5LLfOs EZcg==; dara=google.com ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@chromium.org header.s=google header.b=FjOMYjnR; 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-91131-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:40f1:3f00::1 as permitted sender) smtp.mailfrom="linux-kernel+bounces-91131-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=chromium.org Return-Path: Received: from sy.mirrors.kernel.org (sy.mirrors.kernel.org. [2604:1380:40f1:3f00::1]) by mx.google.com with ESMTPS id k18-20020a170902c41200b001d71de11ca5si9102475plk.493.2024.03.04.11.16.06 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 04 Mar 2024 11:16:07 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel+bounces-91131-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:40f1:3f00::1 as permitted sender) client-ip=2604:1380:40f1:3f00::1; Authentication-Results: mx.google.com; dkim=pass header.i=@chromium.org header.s=google header.b=FjOMYjnR; 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-91131-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:40f1:3f00::1 as permitted sender) smtp.mailfrom="linux-kernel+bounces-91131-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 sy.mirrors.kernel.org (Postfix) with ESMTPS id 1DB74B2472D for ; Mon, 4 Mar 2024 18:50:59 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 367107B3DE; Mon, 4 Mar 2024 18:49:44 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=chromium.org header.i=@chromium.org header.b="FjOMYjnR" Received: from mail-pf1-f175.google.com (mail-pf1-f175.google.com [209.85.210.175]) (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 4D3976216C for ; Mon, 4 Mar 2024 18:49:40 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.210.175 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1709578183; cv=none; b=Yaw8s1CuhfAg+e+M86q1H7CwlzmP2FlIeN2MO/07buj2gNdoKNUeMKDfeYntDGLQ5LtQMKCUoU7+SlGXv1YCedn2s87sYqQpqG0C5D0pKPvnw5cA1FaDQO+WGMbSKnNw8R4H2TARV57GUF2M9DXGn6VC9j3kwx7Xl5QTJh+52GE= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1709578183; c=relaxed/simple; bh=IcLElAry6DIoRKKwJQmpd7ju+FKDVUugrCBgj64Jc1w=; h=From:To:Cc:Subject:Date:Message-Id:In-Reply-To:References: MIME-Version; b=ImBB4YNRu1p97mxNsTqfpkocURGlbKtIHVSaSXhYDuY59MEIs+WpFIXYJc+fQUF7QE6PSSFplKDxDFpOwx/xJFXBypBktO0q4d4g1e0dTXvfx8GVVy+/CyVqs4noYROHVdj+f5z2QUXOq1U5v2m1KOydVCRWQ2hGqvAXKgQepsA= 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=FjOMYjnR; arc=none smtp.client-ip=209.85.210.175 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-f175.google.com with SMTP id d2e1a72fcca58-6e5eb3dd2f8so1489574b3a.2 for ; Mon, 04 Mar 2024 10:49:40 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=chromium.org; s=google; t=1709578179; x=1710182979; darn=vger.kernel.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=2QOKxvJdszgSExOijEeIBqvAxDpXCtl9o7KCQ12P01Y=; b=FjOMYjnRMCw8a5h5ArmSEPQ6udrpaxW+1c0RexEdjfVm9cpDln9PewKj+qmiD09/rq jbSGrBJ9sZAN6kkLxylO+qxRHMFx0vrQQZyEoWwU3VHNHvjNflgYvjbKKAz2C2Lc5c9N Mn/XvuCQamq9Qf/t1fVTySzbuf+Sr8pTRa+CE= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1709578179; x=1710182979; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=2QOKxvJdszgSExOijEeIBqvAxDpXCtl9o7KCQ12P01Y=; b=OcgFWE3N1FsLN5NyPm+AAaG0odph5ITEzHVObVwxrt9Ka/TophaD0gEglM9Xdl0eyC fNiUChyfGKukOjepSS7g87mz/yhUhPm7E7CrDdNdYDoZ1z9JmJY75OHHHCLcZ+Zub5KE +4Ehjsa/591AuVuZ4feKId0Yj4gTFWLZ2ScKBZZfHv29BgYfJJQ52XpX9v60/gmaMVl9 g/tmNiIAAwsG+IdvSwmcev2GQk5q7jKR92dNyrSuOZtgJD/F+n5fVJHbr3HLhcpeEtwi tmBC3CeYDaB3z1Z/hXK6CiL7lNOc1MNsskmSFeJksPq+gqVs+QcHU6E6qnAXEo0iMjaH QmXg== X-Forwarded-Encrypted: i=1; AJvYcCVLBZjm+ljIv49MfgKGEZlexmhFolclDlwpuVDY1vLjz3D5fBbeYEmu2bKxcVrJHDEt/xzs7K340ZCKA6ZnAUSTQS8qyGBpdjdu/dO6 X-Gm-Message-State: AOJu0YyBAejICpSzcwRQRrMuwYhWlZK8KufY6qQpyKVZHU4eahEF6p4x Vk8yMx6MFT4eR8SCy7ZS/uc5nO95EoNv6xKvsFvVI+eRaIK73zY+pObEtoYQEw== X-Received: by 2002:aa7:88c1:0:b0:6e5:5425:d914 with SMTP id k1-20020aa788c1000000b006e55425d914mr10540158pff.2.1709578179470; Mon, 04 Mar 2024 10:49:39 -0800 (PST) Received: from www.outflux.net ([198.0.35.241]) by smtp.gmail.com with ESMTPSA id r27-20020aa79edb000000b006e60c08cbcasm2881132pfq.50.2024.03.04.10.49.34 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 04 Mar 2024 10:49:34 -0800 (PST) From: Kees Cook To: Vlastimil Babka Cc: Kees Cook , 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: [PATCH 3/4] xattr: Use dedicated slab buckets for setxattr() Date: Mon, 4 Mar 2024 10:49:31 -0800 Message-Id: <20240304184933.3672759-3-keescook@chromium.org> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20240304184252.work.496-kees@kernel.org> References: <20240304184252.work.496-kees@kernel.org> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 X-Developer-Signature: v=1; a=openpgp-sha256; l=1560; i=keescook@chromium.org; h=from:subject; bh=IcLElAry6DIoRKKwJQmpd7ju+FKDVUugrCBgj64Jc1w=; b=owEBbQKS/ZANAwAKAYly9N/cbcAmAcsmYgBl5he8RUV3Nml6+beLYoX/gI6MaxpEQEieiV1Pk LAMHZWkh1eJAjMEAAEKAB0WIQSlw/aPIp3WD3I+bhOJcvTf3G3AJgUCZeYXvAAKCRCJcvTf3G3A JgarD/9HvGby2B7eoqRlayCbyDlLBOSIiVV2Bq+vUUsC8Ne0FV1zyqgFRQrXbQ2G6VGoWXimSlm M1jvsW/Y99i2kQDWqeDEZeZf+LehlADDm5Vd8pmJfMMgX19BF898FQYPT7s7OKOxOJ4T/GuE1Kf f8BRgEGLrWxyrMYUyG5/wFYfmfEzazDwiU+A/d2eMxhnYFT6e1elFQ0FweaUabd1+ZCJwV5UdWh HIyGFxL/YTavdVnf68HYBNALeF2lzUERVyzafZOv6WzhMzem7sDreYdkBpWwU4Nvafa5vCB+mCZ kz+tSe+uPkTDLUvM18O8w9hPQ0ywaf1CFBDkCciseVfUKVnH06WlWb84AbCwLv1KSDl6ipWRLxU 84NhknBpAY4fgIguhU0kDs83NhdIl/kn10T/oubIkmY5wdavroHRaFjSlkw/VAeVdJCOOH+U3b9 AJDGgUmwEUlmq7b731/mixhLBrz0CTKq8Aa59nDba3ji+Utrd7I1HKHwMPTcsPrBIVtK2QspH+t pcBzTrTkEuaW7vRD41WXoqxhSJ+mUK3+SKCFafsj0ZaMq2qMA977BazfKFPlNrWRRWzRrteGmk1 Q8c9m2anBqS3EOtpP7bZ2OHyh5VlDQiLJP6Mo78p0Tkgsf+LU7XH1gWUSibuhbnTREFTie5DhAK x63js6NDKJKKoCA== X-Developer-Key: i=keescook@chromium.org; a=openpgp; fpr=A5C3F68F229DD60F723E6E138972F4DFDC6DC026 Content-Transfer-Encoding: 8bit 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); if (!klist) return -ENOMEM; } -- 2.34.1