From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by smtp.lore.kernel.org (Postfix) with ESMTP id 1CBC8CFA775 for ; Fri, 4 Oct 2024 14:04:08 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id AB7306B014F; Fri, 4 Oct 2024 10:04:07 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id A675A6B0405; Fri, 4 Oct 2024 10:04:07 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 8BA2B6B0406; Fri, 4 Oct 2024 10:04:07 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0015.hostedemail.com [216.40.44.15]) by kanga.kvack.org (Postfix) with ESMTP id 6A12B6B014F for ; Fri, 4 Oct 2024 10:04:07 -0400 (EDT) Received: from smtpin22.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay07.hostedemail.com (Postfix) with ESMTP id 0938A161020 for ; Fri, 4 Oct 2024 14:04:07 +0000 (UTC) X-FDA: 82636088934.22.023F5A4 Received: from smtp-out2.suse.de (smtp-out2.suse.de [195.135.223.131]) by imf17.hostedemail.com (Postfix) with ESMTP id 9722440027 for ; Fri, 4 Oct 2024 14:04:04 +0000 (UTC) Authentication-Results: imf17.hostedemail.com; dkim=pass header.d=suse.cz header.s=susede2_rsa header.b=tSd5zOIw; dkim=pass header.d=suse.cz header.s=susede2_ed25519 header.b=qabWiVfO; dkim=pass header.d=suse.cz header.s=susede2_rsa header.b=tSd5zOIw; dkim=pass header.d=suse.cz header.s=susede2_ed25519 header.b=qabWiVfO; dmarc=none; spf=pass (imf17.hostedemail.com: domain of vbabka@suse.cz designates 195.135.223.131 as permitted sender) smtp.mailfrom=vbabka@suse.cz ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1728050548; a=rsa-sha256; cv=none; b=Ec7MvfklnXTpp6IvIBR3qamu1wyONz24AJuJATi2xWSdzyLmbwL4/aCK36Q39lQG06ef/y SEECC7akv4dEVKXBJIa3pEnOQoaT+r6BYY+birHNFbr1uM90fYSfGJNKAo5ntwYBgsOuQn bnZ35Ftq9wzrnLcwlT/pv4mK5gldjXg= ARC-Authentication-Results: i=1; imf17.hostedemail.com; dkim=pass header.d=suse.cz header.s=susede2_rsa header.b=tSd5zOIw; dkim=pass header.d=suse.cz header.s=susede2_ed25519 header.b=qabWiVfO; dkim=pass header.d=suse.cz header.s=susede2_rsa header.b=tSd5zOIw; dkim=pass header.d=suse.cz header.s=susede2_ed25519 header.b=qabWiVfO; dmarc=none; spf=pass (imf17.hostedemail.com: domain of vbabka@suse.cz designates 195.135.223.131 as permitted sender) smtp.mailfrom=vbabka@suse.cz ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1728050548; h=from:from:sender:reply-to:subject:subject:date:date: message-id:message-id:to:to:cc:cc:mime-version:mime-version: content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references:dkim-signature; bh=vpAe5qPGyHx09K/FsSp/0X4jiT8rVzItXWB8AiSztiU=; b=MlC1gI8SuY6CX/KWh62+Hxk1g+0bqGNAj8SLsBx9O8PhfVTiPE4H7W+bVz6ItG9FGWTUei RClPKYxp2uvEhD8tmYKVGAL+x1ak17Lr9pT0UNqO+lrOTzj8JeG+inK6c2/kYcWowAUNON lxAG5AbhVuosSCkQ05x+90jP+US4TBA= Received: from imap1.dmz-prg2.suse.org (unknown [10.150.64.97]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits) server-digest SHA256) (No client certificate requested) by smtp-out2.suse.de (Postfix) with ESMTPS id C8B581FD89; Fri, 4 Oct 2024 14:04:02 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=suse.cz; s=susede2_rsa; t=1728050642; h=from:from:reply-to:date:date:message-id:message-id:to:to:cc:cc: mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references:autocrypt:autocrypt; bh=vpAe5qPGyHx09K/FsSp/0X4jiT8rVzItXWB8AiSztiU=; b=tSd5zOIwIV94hT3qX7J+pq8Oy0RwB2ew3gvKZbQh3v29FIJHdQ7fIkj32P7ec6bYShOm36 M4tPXmuQC58f7iiBM7UhqVJa4Tr7cpgMLGl1LAfAT1A4UXwrYKPHzGf7m3/JvV2nf/k+PB 5rBSjqVin2TobcentGhBlz9hHXp7QTo= DKIM-Signature: v=1; a=ed25519-sha256; c=relaxed/relaxed; d=suse.cz; s=susede2_ed25519; t=1728050642; h=from:from:reply-to:date:date:message-id:message-id:to:to:cc:cc: mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references:autocrypt:autocrypt; bh=vpAe5qPGyHx09K/FsSp/0X4jiT8rVzItXWB8AiSztiU=; b=qabWiVfOnMnGl0jN9dDJ1CWOWRpfAXHg8vNc5jv1c8XXWUzKsLvFNeyf/uiLn/7rVrBWfx u4tmDP39KJ0vzjAg== DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=suse.cz; s=susede2_rsa; t=1728050642; h=from:from:reply-to:date:date:message-id:message-id:to:to:cc:cc: mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references:autocrypt:autocrypt; bh=vpAe5qPGyHx09K/FsSp/0X4jiT8rVzItXWB8AiSztiU=; b=tSd5zOIwIV94hT3qX7J+pq8Oy0RwB2ew3gvKZbQh3v29FIJHdQ7fIkj32P7ec6bYShOm36 M4tPXmuQC58f7iiBM7UhqVJa4Tr7cpgMLGl1LAfAT1A4UXwrYKPHzGf7m3/JvV2nf/k+PB 5rBSjqVin2TobcentGhBlz9hHXp7QTo= DKIM-Signature: v=1; a=ed25519-sha256; c=relaxed/relaxed; d=suse.cz; s=susede2_ed25519; t=1728050642; h=from:from:reply-to:date:date:message-id:message-id:to:to:cc:cc: mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references:autocrypt:autocrypt; bh=vpAe5qPGyHx09K/FsSp/0X4jiT8rVzItXWB8AiSztiU=; b=qabWiVfOnMnGl0jN9dDJ1CWOWRpfAXHg8vNc5jv1c8XXWUzKsLvFNeyf/uiLn/7rVrBWfx u4tmDP39KJ0vzjAg== Received: from imap1.dmz-prg2.suse.org (localhost [127.0.0.1]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits) server-digest SHA256) (No client certificate requested) by imap1.dmz-prg2.suse.org (Postfix) with ESMTPS id B97A113A6E; Fri, 4 Oct 2024 14:04:02 +0000 (UTC) Received: from dovecot-director2.suse.de ([2a07:de40:b281:106:10:150:64:167]) by imap1.dmz-prg2.suse.org with ESMTPSA id 0gjvLNL1/2bXYAAAD6G6ig (envelope-from ); Fri, 04 Oct 2024 14:04:02 +0000 Message-ID: Date: Fri, 4 Oct 2024 16:04:02 +0200 MIME-Version: 1.0 User-Agent: Mozilla Thunderbird Subject: Re: [DESIGN] Hardening page allocator against type confusion Content-Language: en-US To: Matthew Wilcox Cc: linux-mm@kvack.org, Kees Cook , Jann Horn References: From: Vlastimil Babka Autocrypt: addr=vbabka@suse.cz; keydata= xsFNBFZdmxYBEADsw/SiUSjB0dM+vSh95UkgcHjzEVBlby/Fg+g42O7LAEkCYXi/vvq31JTB KxRWDHX0R2tgpFDXHnzZcQywawu8eSq0LxzxFNYMvtB7sV1pxYwej2qx9B75qW2plBs+7+YB 87tMFA+u+L4Z5xAzIimfLD5EKC56kJ1CsXlM8S/LHcmdD9Ctkn3trYDNnat0eoAcfPIP2OZ+ 9oe9IF/R28zmh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th1pTtABKQ1YuTvehj7EfoWD3bv9kuGZGPrAeFNiHPdOT7DaXKeHpW9homgtBxj 8aX/UkSvEGJKUEbFL9cVa5tzyialGkSiZJNkWgeHe+jEcfRT6pJZOJidSCdzvJpbdJmm+eED w9XOLH1IIWh7RURU7G1iOfEfmImFeC3cbbS73LQEFGe1urxvIH5K/7vX+FkNcr9ujwWuPE9b 1C2o4i/yZPLXIVy387EjA6GZMqvQUFuSTs/GeBcv0NjIQi8867H3uLjz+mQy63fAitsDwLmR EP+ylKVEKb0Q2A== In-Reply-To: Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 7bit X-Rspamd-Queue-Id: 9722440027 X-Rspam-User: X-Rspamd-Server: rspam05 X-Stat-Signature: 7n34r59gdrmiecrs5u6ydnxyddbr34nu X-HE-Tag: 1728050644-165902 X-HE-Meta: U2FsdGVkX19Rlm3wEXe32AfozQXKdy5W1+BYvV69ZTLoSUIGV/RM7Dm042hoMzRMnq4l+JDK964LTIqr+Q5eDXZxQ6U2hli212Rkyv3bELQ2LA/eNz+dJ0Vnf82qPEVzyJxdCRxRL/bl2i0gEB3oEZVsc8c5GepR6/5o+VqZRSIdFl1jgZnJ4xmir+Tj2GHJpbIlJGM8jXhb2aaYTN72SkeoyIUYEctkIAgJO1V/2FU1rJ1hRHIJXZFIXimubQ6WpFBiAjMoUX6ntW+rK2yLRx3N0RGiAgqyspx0kxCz9FmSrc/qAksjLmGVRibTgS3uKlxDco3uE/0mvyYca+A/n7h+890PwFm/Kyl4UcABUYq/rHqsyOnBZpPQqfZEWS5gHpSuWvIry6MraHsNovWrk4a9LusgyMeGS2tAsgjPX9h7uu71JwOofuEoPpLYReF4aU8kwEZgKbxE4LmRLFSJ+TUfwf2btsA9AIkq5huazi5f1XF0Jf/BvloNTH6WYFRHyJozTm3GCgpjfmtw+E43AM2XCBHBPzYftpIun0McwgaNHNOHj/rlQXr0jFeG0hwVKWghstSOe6QCHsDYiN8QnkLwgKXNtJtaWM6b5ADDNnaDVWsm6sE9nivu8YuwYqi/m1Pz18BYnh61JeGxnwjRPPEn7QD0MjkarW7kPLOPUdaO4gK/9POVRnX9LXKNDasBf4EMuy1OsMl2dHyTjl6qIyg13X++L6sUXbyB0Iwsh1qAEGUY4fo6XXFmEFetiuQTiUHQiQIZyrfD096S4ZKjHT6EQHOj3d94Cr8LxQE19HagwVND/HXLc/Rrj2jxc5OCBAS04FvQjk17PzsUuRmPpKbTZsjIDr28ADIkcxOGQvK/Y/0/iuHWNdPmM7IYFNTUqAuZfJsZgrnRKB0JWEPVxeDaK9oDO3rAFJzLL/PDGPDtz4j/7f/98I2N9zzlK/cRA4HaY4M0H7NXs64fNWE AGnK5Wzg kj6RuFqo4oi14A+81Ay6AqQiPWE+vHt8h7co4OsUFVBYxLqor7Y+YvUp70Wnw9fuoleaCurbLJUQnMC7sPNTqw/XL40vRornZYNUFon+3G63yOi2nhSVKr8A5adFFs7sj8k+18L6Z12PVFkfc4cp8ODUqnvGpn0ll6CpQxC1tSNWjBL79X3BXAE3t1MtYJNoJRE12ThbHwQs3AmtO0/15nAUGUDaMRC3B2sR6vut8C5gKIgSrgbmS5J3IFqjPBBIBwKFLGhS8cUehXcfAaskRdtTq3bmyDiMo71IUiQ7QAHgQyrxyHcStGTlv7wgNoJzhsTB9esOFVnF2DzPw9P8eawi7SDw74yS3x+6w X-Bogosity: Ham, tests=bogofilter, spamicity=0.000000, version=1.2.4 Sender: owner-linux-mm@kvack.org Precedence: bulk X-Loop: owner-majordomo@kvack.org List-ID: List-Subscribe: List-Unsubscribe: On 10/3/24 18:50, Matthew Wilcox wrote: > On Thu, Oct 03, 2024 at 04:27:12PM +0200, Vlastimil Babka wrote: >> On 9/25/24 21:46, Matthew Wilcox wrote: >> > Kees and I had a fun discussion at Plumbers. >> > >> > We're trying to harden against type confusion, where we think we have >> > a pointer to one thing, but it turns out to be a pointer to a different >> > thing. There's various ways this can be harmful, which Kees has laid out >> > before when adding slab buckets. eg see https://lwn.net/Articles/978976/ >> > >> > Not all allocations come from slab though. If we free a slab object >> > and the slab it was in gets freed back to the page allocator, it can >> > turn into almost anything else _quickly_ as the page allocator fronts >> > the buddy allocator with a stack of recently-freed pages (called PCP, >> > not to be confused with percpu memory), so if the attacker can arrange >> > for a page table allocation to come in soon after a slab free, it is >> > very likely to be the memory they have access to. The paragraph above seems very much about allocations that were originally from slab. AFAIU that's the biggest concern for type confusion. >> > My proposal is that we resolve this "type confusion" by having separate >> > PCP lists for different types of pages. We'll need to have this for >> > memdescs anyway, so this is just shifting some of the work left. >> > >> > We'd reduce the exploitability of type confusion by using a per-CPU, >> > per-type stack of recently used pages. To turn a slab page into a page >> > table page, the attacker would have to cause a dozen slabs to be freed on >> > this CPU, pushing this one into the buddy allocator. Then they'd have >> > to cause the allocating task to empty its stack of page table pages, >> > causing the attackable slab to be pulled from the buddy. It's still >> > possible, but it's harder. >> > >> > Harder enough? I don't know, hence this email. We can get into the >> > API design (and then the implementation design) if we have agreement >> > that this is the right approach to be taking. >> >> Not a security expert but I doubt it's harder enough? >> >> I thought the robust mitigation here was SLAB_VIRTUAL > > Well, this is for allocations that _don't_ come from slab. Like page > tables and page cache or anoymous memory. See above. I'm not sure how relevant are the other kinds of page type confusion in practice. Maybe large kmalloc() (not technically slab allocations) or arbitrary kernel alloc_pages() allocations reused as e.g. page tables?