Received: by 2002:a05:7412:31a9:b0:e2:908c:2ebd with SMTP id et41csp4933241rdb; Fri, 15 Sep 2023 17:59:47 -0700 (PDT) X-Google-Smtp-Source: AGHT+IEkIS4MLkLdYmSmdS9i+hDTd0CbvD83dO2HccipUruzHCJ/5mcJHakdZztSjIRKp9pEaxpt X-Received: by 2002:a05:6a00:23c4:b0:68f:b8ca:adf with SMTP id g4-20020a056a0023c400b0068fb8ca0adfmr3522803pfc.0.1694825986797; Fri, 15 Sep 2023 17:59:46 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1694825986; cv=none; d=google.com; s=arc-20160816; b=Su+u23E8GWdwX7iGnChFeocrQq45Csp5x/q3dOWDOBk6b/qRrKQ9xiieXuj3al0mQ5 4raAQXt0EzZtf6Zxz7D9WZCAW5ltQV7oqwAX7bQEU4PlDffJxRoBK7tpyMWk9XQz8ecB b+UlAQ4dS7Ngql1C9wnKlrDoHjtsTWvgz5zVKdGZph+JpCPUXbdmvMhTsUB7Yw6kAgdg 9wo7LI1UyRaZ7vziv6WLyqKF0hkHpy5/Bfprm3eW+fvWsoa4vyUuvCxnFrW9Udmmx1st YnJ4iVwE4p+wOrcmVKp+PiAlZr8IGJG1BZeajje6iTahlHW8WvwQgZR2lJcw6RxeZNb1 sXRw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:in-reply-to:content-disposition:mime-version :references:message-id:subject:cc:to:from:date:dkim-signature; bh=pixcN5Y1AubjMBamu4r0/OjVDhrvJd2jJgNFr0zPGBA=; fh=jqyVLh6bCUdwF76+d1nSsH9gan5yVpKFn6DRJJLnHtk=; b=SURtgyYc7DFQtwjvIlkBegdaRxjMJB9R+B1UWhW/aKKgmYIognPCh8Ql4PIOkjVeVs W0aZwK9ZQ/JXk+m8tQ/42at3GKHwhCaMenD7eeXxsSfCFKYK4fd/8Tf/RTw10xdocPZt fMBXJQ6WgOYCGIb54wwZ88hPNACJ32imPYfYMr30uTwO+mfaRYw7KkEnnIREzhQm3FWy DcpqcjW8YJNFhBzbvMDt2P10CkBL4D2RFIRNt/SpgXgxXpIldoYuNyv0tvkUO4VxoPBV x+uKFo9sKPLLzAR4tO3M5iSiDwH9B+YGafDxmfGQIO3Clt5pbqvEscgWeMO5JQuXqrRU c0Zg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@chromium.org header.s=google header.b=HuODhYel; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:2 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=chromium.org Return-Path: Received: from agentk.vger.email (agentk.vger.email. [2620:137:e000::3:2]) by mx.google.com with ESMTPS id t64-20020a638143000000b00565e7a3342dsi4009023pgd.256.2023.09.15.17.59.46 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 15 Sep 2023 17:59:46 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:2 as permitted sender) client-ip=2620:137:e000::3:2; Authentication-Results: mx.google.com; dkim=pass header.i=@chromium.org header.s=google header.b=HuODhYel; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:2 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=chromium.org Received: from out1.vger.email (depot.vger.email [IPv6:2620:137:e000::3:0]) by agentk.vger.email (Postfix) with ESMTP id 5217A82B3B9F; Fri, 15 Sep 2023 13:52:03 -0700 (PDT) X-Virus-Status: Clean X-Virus-Scanned: clamav-milter 0.103.10 at agentk.vger.email Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S237290AbjIOUvc (ORCPT + 99 others); Fri, 15 Sep 2023 16:51:32 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:60944 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S237863AbjIOUus (ORCPT ); Fri, 15 Sep 2023 16:50:48 -0400 Received: from mail-pl1-x62f.google.com (mail-pl1-x62f.google.com [IPv6:2607:f8b0:4864:20::62f]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 8D73E35BB for ; Fri, 15 Sep 2023 13:50:02 -0700 (PDT) Received: by mail-pl1-x62f.google.com with SMTP id d9443c01a7336-1c09673b006so20653085ad.1 for ; Fri, 15 Sep 2023 13:50:02 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=chromium.org; s=google; t=1694811001; x=1695415801; 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=pixcN5Y1AubjMBamu4r0/OjVDhrvJd2jJgNFr0zPGBA=; b=HuODhYelyacRY9HlytTsIm4B7wz8OazwsD1/3T8eipUeYOw7pRmK87nYD+La4M2ERL c+7i0KKd0WStxwghrx1gk/tXpFGLX6oCJQ8XsXYFkD4z/28YqyucPyx/EH8c5tVvxeQ4 l6Cr7hN2AKgTyDnzeP4hXi1kaJYFNVGjzbZTA= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1694811001; x=1695415801; 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=pixcN5Y1AubjMBamu4r0/OjVDhrvJd2jJgNFr0zPGBA=; b=knTZ3Kcqy3xx4nbERuHY8K0SpG0EtRveuLba4zMRGFeJuv9MboqsPtr0bRIZkyE9yH 1ZISl+KGZgtZJP2vWdS+ByzDz0nSh1NRsdfrrcrt4OVg1mMf6pv4vqWjbSFwqO15nW1W 9PbSGaJNBORhIY0BuNYuDQB49b+YOdmfcFFab9lxHA0Hml2GFbiYS2CbZaJqzlkpy8BM wPe/jA6AJiz5UiDDeC/bKW/F35/9N1YRyTk3XyqVHv7oHYKHoLBSCbZqzcewx8brwQJk kyqG4LaA1tAB6oSt0rgdTIt4ItdFIyUl/SUygr8no8dAgywmPXTzAlncYhl8r2Cy4oxN jA1w== X-Gm-Message-State: AOJu0YxVZbNPY+BLbSFL4Ryx/6Q8wE9+zgSP03tp/2vDdlh3/iaU1gb8 uZ/xnjO8UZfe/Mp/YnrY0RDrGA== X-Received: by 2002:a17:902:d4c7:b0:1c1:e52e:49e3 with SMTP id o7-20020a170902d4c700b001c1e52e49e3mr2611409plg.36.1694811001209; Fri, 15 Sep 2023 13:50:01 -0700 (PDT) Received: from www.outflux.net (198-0-35-241-static.hfc.comcastbusiness.net. [198.0.35.241]) by smtp.gmail.com with ESMTPSA id q22-20020a170902bd9600b001bb9f104328sm3876566pls.146.2023.09.15.13.50.00 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 15 Sep 2023 13:50:00 -0700 (PDT) Date: Fri, 15 Sep 2023 13:50:00 -0700 From: Kees Cook To: Matteo Rizzo Cc: cl@linux.com, penberg@kernel.org, rientjes@google.com, iamjoonsoo.kim@lge.com, akpm@linux-foundation.org, vbabka@suse.cz, roman.gushchin@linux.dev, 42.hyeyoo@gmail.com, linux-kernel@vger.kernel.org, linux-doc@vger.kernel.org, linux-mm@kvack.org, linux-hardening@vger.kernel.org, tglx@linutronix.de, mingo@redhat.com, bp@alien8.de, dave.hansen@linux.intel.com, x86@kernel.org, hpa@zytor.com, corbet@lwn.net, luto@kernel.org, peterz@infradead.org, jannh@google.com, evn@google.com, poprdi@google.com, jordyzomer@google.com Subject: Re: [RFC PATCH 01/14] mm/slub: don't try to dereference invalid freepointers Message-ID: <202309151349.BEBA203D@keescook> References: <20230915105933.495735-1-matteorizzo@google.com> <20230915105933.495735-2-matteorizzo@google.com> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <20230915105933.495735-2-matteorizzo@google.com> X-Spam-Status: No, score=-0.9 required=5.0 tests=DKIMWL_WL_HIGH,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,HEADER_FROM_DIFFERENT_DOMAINS, MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS autolearn=unavailable autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on agentk.vger.email Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org X-Greylist: Sender passed SPF test, not delayed by milter-greylist-4.6.4 (agentk.vger.email [0.0.0.0]); Fri, 15 Sep 2023 13:52:04 -0700 (PDT) On Fri, Sep 15, 2023 at 10:59:20AM +0000, Matteo Rizzo wrote: > slab_free_freelist_hook tries to read a freelist pointer from the > current object even when freeing a single object. This is invalid > because single objects don't actually contain a freelist pointer when > they're freed and the memory contains other data. This causes problems > for checking the integrity of freelist in get_freepointer. > > Signed-off-by: Matteo Rizzo > --- > mm/slub.c | 4 +++- > 1 file changed, 3 insertions(+), 1 deletion(-) > > diff --git a/mm/slub.c b/mm/slub.c > index f7940048138c..a7dae207c2d2 100644 > --- a/mm/slub.c > +++ b/mm/slub.c > @@ -1820,7 +1820,9 @@ static inline bool slab_free_freelist_hook(struct kmem_cache *s, > > do { > object = next; > - next = get_freepointer(s, object); > + /* Single objects don't actually contain a freepointer */ > + if (object != old_tail) > + next = get_freepointer(s, object); > > /* If object's reuse doesn't have to be delayed */ > if (!slab_free_hook(s, object, slab_want_init_on_free(s))) { I find this loop's logic a bit weird, but, yes, this ends up being correct and avoids needless work. Reviewed-by: Kees Cook -- Kees Cook