Received: by 2002:ab2:3319:0:b0:1ef:7a0f:c32d with SMTP id i25csp134185lqc; Thu, 7 Mar 2024 12:31:30 -0800 (PST) X-Forwarded-Encrypted: i=3; AJvYcCVpb1ztX26fCnW9Ahgt916HmUHdiUCb1Q05LWKcrqoyGbdlJ9CjKIuoPH72M8PZFQHgjFtd1kTJA8OR9S/SeFVlvuadStw8rbJAVDp4/g== X-Google-Smtp-Source: AGHT+IGw1NF5sKTR0Twv+bANSHM0g/r6hXrNZkXLbybSpLkmX1FTIjSlawoKB12EDF2u/UR8BAMx X-Received: by 2002:a17:906:cf88:b0:a45:373:d0a with SMTP id um8-20020a170906cf8800b00a4503730d0amr11084065ejb.32.1709843490689; Thu, 07 Mar 2024 12:31:30 -0800 (PST) ARC-Seal: i=2; a=rsa-sha256; t=1709843490; cv=pass; d=google.com; s=arc-20160816; b=wvQlp0ORLwOtmgAemQdPpsn8FXD9gm5XXXnJ2gW65pv4Csl+NMBGLrJVwLsv48H8BZ ZtJAMOJn4Myu0AhX2byjw0LRlmNd1/Wnf13xlrtDfLt9kk2l0Wd7XNgpWOmYVUfNPoTh soAfF1ZtZsGPkEiYOLy9ADMMPkxA4tK2NaozYwF5gfQVDDrTVLCYYz+7c2iZCny4ayye FvKJ/zMVyeibhwI+usVrU4tt3BpsmHRZEPqLCw3/ar4r9v8+IM6YAy+OEe8LR9X1y354 V3OexgXDAcczxpJuprKKInNeESmINhx1C+W7/QsuLgL2DaCy+ObOtbcm0cLFhOMrOBIp 4bNQ== 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=td/qc1v+LcJcAxN8xi3WFcUXSnLHGt1lHwkmw1ZD0As=; fh=F1xrMeVqtncyN5iIEa/vd8pkEe/XRz6Y13VWoDtGnI4=; b=i6uHS8QaolDa2StoLKddDLjNKZI6Pzu4ujmeaba75fAXxFrRqPFGAgsNFYUqOsRKJh r1OrKsLVaohY3oYrvSJOtlIxg9BhYSuuW+d31Oa74RrVNx0SW31M2kQG/CKSh83TNrA+ lcRbmBZiIe36PaHX/O8vb+KlZGYnhK/Di3XJ7c8u34spadPm43na2MVwQtNxIx2bDF/Z 95qS1xjdUMN6Bidq3DpQviOfpDT88S+iNGhP+ni+Aa+n2RvkjvuGpPXgOrCjHYlKHL9T PFLBzkA9Syn20eHrSgWCYdiciiErh0X01nprZlFDbUVgVc/0NS7z3RUAWzzeEOzwjRnQ BHkw==; dara=google.com ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@chromium.org header.s=google header.b=PcZLmtxG; 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-96195-linux.lists.archive=gmail.com@vger.kernel.org designates 147.75.80.249 as permitted sender) smtp.mailfrom="linux-kernel+bounces-96195-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. [147.75.80.249]) by mx.google.com with ESMTPS id k27-20020a17090632db00b00a456893af83si3761050ejk.140.2024.03.07.12.31.30 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 07 Mar 2024 12:31:30 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel+bounces-96195-linux.lists.archive=gmail.com@vger.kernel.org designates 147.75.80.249 as permitted sender) client-ip=147.75.80.249; Authentication-Results: mx.google.com; dkim=pass header.i=@chromium.org header.s=google header.b=PcZLmtxG; 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-96195-linux.lists.archive=gmail.com@vger.kernel.org designates 147.75.80.249 as permitted sender) smtp.mailfrom="linux-kernel+bounces-96195-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 6C2861F21B33 for ; Thu, 7 Mar 2024 20:31:30 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 142A34E1C3; Thu, 7 Mar 2024 20:31:22 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=chromium.org header.i=@chromium.org header.b="PcZLmtxG" Received: from mail-pl1-f170.google.com (mail-pl1-f170.google.com [209.85.214.170]) (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 BD01224B29 for ; Thu, 7 Mar 2024 20:31:19 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.214.170 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1709843481; cv=none; b=Veo/MKV/a1uh20xNbx1UudylsdPl/ihlssD4Lk7BfuvxL6qH7NuJ/BDqp0LY6/Yjo+a57U+npg6zPyorKZSQvHV04NDntmrrJzUZEU9n7z38WmLEf9vIzZn6m4dmWC5ToT/rP2i934FOOL3zHmWp3izGRGJ/5YUpQqdm3ghDqbc= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1709843481; c=relaxed/simple; bh=uFkSV3XWA6pSvBdWPTS5Z4D4hTCdELrOUpWgEurePV0=; h=Date:From:To:Cc:Subject:Message-ID:References:MIME-Version: Content-Type:Content-Disposition:In-Reply-To; b=OPZjbZqZu6yp/sir6Mc9Tt9tftfXY3Acn3MJ8XWC1OoK+bFPlNIqqN3FGbuUyTpfO+2szOIRQ/xp3yKyGX1KzPR3qrjl/nt9tz7ed0ITJEJ0JvBqjxVJP9A4hvI4XCOC+KTN4ljwI4mxYJT4/NQBx/KD5fEQ9uACIPtRyklY2uc= 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=PcZLmtxG; arc=none smtp.client-ip=209.85.214.170 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-pl1-f170.google.com with SMTP id d9443c01a7336-1dc3b4b9b62so10170705ad.1 for ; Thu, 07 Mar 2024 12:31:19 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=chromium.org; s=google; t=1709843479; x=1710448279; 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=td/qc1v+LcJcAxN8xi3WFcUXSnLHGt1lHwkmw1ZD0As=; b=PcZLmtxGTh7uVIpOoxFb+QeLRCq04OP99KCB1sSGFi0d/uUTcPGVZwkss6BrXiAiUi fhV3wi1KmFHke/EUAggJyb4TDH8uN6X9TWvYkhoFq/2TNkOkurSMCYzZ/OAwgZQkYQx8 +JL3tjctLJ3J2e2JwyNP5wJw6MY3H1FSyEZ7U= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1709843479; x=1710448279; 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=td/qc1v+LcJcAxN8xi3WFcUXSnLHGt1lHwkmw1ZD0As=; b=ESPm1SSz1QGLxe2x5O4ZykXDjpfyOVXALRtjQ0CL8NFlGIJzzq91/qfk2kKfr8EHLp 4d9fY+i8hlHd+ftFSC8Wy/Z0GRi5DP5A4SDzvEZfbxzEp928ptF0iy9yW6SWBxWvb0J6 VN0t1ch6aCNLqWDiN6Jyvs4tFgH5k0a1JLxmx34z3i5qPONxqCEPDJ7XKjwQI9bqaGCg KFOhu5Ic7ezmFdo9bT7pS6adFI6bBgjvbj9Lwv9tIEGbB1D7Ewi3e3i2j5TAIf8DG77y /WWKKzoVucQODGLqW5xELQM4jeG6GdZOFfRikSDVq0ajnweCPhTLcaYRnD0Jn7VV3j4q EyMQ== X-Forwarded-Encrypted: i=1; AJvYcCW+/w5uCXXS+vLoZ//UdFHJ4E5mtJe2mEzRqAxOfG0WvGir4AATIZjEQ2ciD2qIV29TbsvD4fgCH9kZ3Flc9U9f9o2tf35t8qzQTmJl X-Gm-Message-State: AOJu0Ywqj8WVSpIe0toBgsjmkVBZv3aqgCcS9OEp1q6/8r6R1XQC+ERc lAL37638oz3W9mWSPu7gypJ9JEFsNOTLmsZvTRpp+BIJXW2OZ43xgT5SC/n1Yg== X-Received: by 2002:a17:903:22cf:b0:1db:9ff1:b59b with SMTP id y15-20020a17090322cf00b001db9ff1b59bmr3493970plg.23.1709843479184; Thu, 07 Mar 2024 12:31:19 -0800 (PST) Received: from www.outflux.net ([198.0.35.241]) by smtp.gmail.com with ESMTPSA id i9-20020a170902c94900b001dcc09487e8sm15044171pla.50.2024.03.07.12.31.18 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 07 Mar 2024 12:31:18 -0800 (PST) Date: Thu, 7 Mar 2024 12:31:17 -0800 From: Kees Cook To: "GONG, Ruiqi" Cc: Vlastimil Babka , Andrew Morton , Christoph Lameter , Pekka Enberg , David Rientjes , Joonsoo Kim , Roman Gushchin , Hyeonggon Yoo <42.hyeyoo@gmail.com>, Xiu Jianfeng , Suren Baghdasaryan , Kent Overstreet , Jann Horn , Matteo Rizzo , linux-kernel@vger.kernel.org, linux-mm@kvack.org, linux-hardening@vger.kernel.org Subject: Re: [PATCH v2 0/9] slab: Introduce dedicated bucket allocator Message-ID: <202403071227.D29DE5F8C4@keescook> References: <20240305100933.it.923-kees@kernel.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 Wed, Mar 06, 2024 at 09:47:36AM +0800, GONG, Ruiqi wrote: > > > On 2024/03/05 18:10, Kees Cook wrote: > > Hi, > > > > Repeating the commit logs for patch 4 here: > > > > Dedicated caches are available For fixed size allocations via > > kmem_cache_alloc(), but for dynamically sized allocations there is only > > the global kmalloc API's set of buckets available. This means it isn't > > possible to separate specific sets of dynamically sized allocations into > > a separate collection of caches. > > > > This leads to a use-after-free exploitation weakness in the Linux > > kernel since many heap memory spraying/grooming attacks depend on using > > userspace-controllable dynamically sized allocations to collide with > > fixed size allocations that end up in same cache. > > > > While CONFIG_RANDOM_KMALLOC_CACHES provides a probabilistic defense > > against these kinds of "type confusion" attacks, including for fixed > > same-size heap objects, we can create a complementary deterministic > > defense for dynamically sized allocations. > > > > In order to isolate user-controllable sized allocations from system > > allocations, introduce kmem_buckets_create(), which behaves like > > kmem_cache_create(). (The next patch will introduce kmem_buckets_alloc(), > > which behaves like kmem_cache_alloc().) > > So can I say the vision here would be to make all the kernel interfaces > that handles user space input to use separated caches? Which looks like > creating a "grey zone" in the middle of kernel space (trusted) and user > space (untrusted) memory. I've also thought that maybe hardening on the > "border" could be more efficient and targeted than a mitigation that > affects globally, e.g. CONFIG_RANDOM_KMALLOC_CACHES. I think it ends up having a similar effect, yes. The more copies that move to memdup_user(), the more coverage is created. The main point is to just not share caches between different kinds of allocations. The most abused version of this is the userspace size-controllable allocations, which this targets. The existing caches (which could still be used for type confusion attacks when the sizes are sufficiently similar) have a good chance of being mitigated by CONFIG_RANDOM_KMALLOC_CACHES already, so this proposed change is just complementary, IMO. -Kees -- Kees Cook