Received: by 2002:a05:6a10:c7c6:0:0:0:0 with SMTP id h6csp1826214pxy; Mon, 2 Aug 2021 11:10:08 -0700 (PDT) X-Google-Smtp-Source: ABdhPJwUZ7dNncztwTJU7OtAFt2BXo/EQiD5iSRygQl3e8AR3ViZRS4rO4k1eALVB1yRPGv1eo/S X-Received: by 2002:a92:dcc5:: with SMTP id b5mr2598791ilr.234.1627927808041; Mon, 02 Aug 2021 11:10:08 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1627927808; cv=none; d=google.com; s=arc-20160816; b=0I07bD1D7rrST1fNZ40oxi0A1GuqE5AqPcjbk1U1z6RVaITyg8b0/5l6weJiMQUXJJ a9HqwcXG3uHJRsy7YBb2Mjtob7XlyGVeTRovZqFvENUUZ4FuCgU30zU5MuUcRG4z9SXl 3n+0H54XHDoxhqrjdPrl9gFVAD+DSRUCMt64zUegF4FWfg5A4v01EPgCzcGsadByWm2c oQZYpZaNdnq97fLSOADxdSLYOeWkzvxSu/sEwgk2z5ozBjL7CHnsn00PMUYDgeif2roV bNICD+YSXsDE0gkxqe+PUKnkT6o37Yofyzp84jTUfK9LtlMVWlFRL0DtMjzsxE3p3LvN u+ZA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:cc:to:from:subject:mime-version:message-id:date :dkim-signature; bh=j+JSAL2TyTO06rmOJxXfenDO1JaBiOx8vJieMlI9pfs=; b=l5Z6IdNIwluwTEDtwOtDNwruKySO1/HzrAYr8wW9dT3MNHXcMmFuV1XNwr2nyed4ri +KKEd08OtWiB5bKyBeNQNUrr2uwdMDkHebabk9qWQpzcBdQrAH0ajhfUVgO2JCIzXVZW tj21mUp162Gtlxi3oZ4AfOSj0OgFcZQpS1wARIYNy+75GyvE9Iu7xFIYGKvuTge+uIvj ejsZPijWzX1K4S9uvW0xgFNrjBbMArEl5/qTkS8LkYFA9VV2uyVwhbGJOIdWfZQAnWj7 AWRgQaSYWT3COL+/nZ+ObDn/rNz+UNq1PfurtUi0LjfoIOCxj9ygYxUoGWQIV5zZjdTs ZDHA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@google.com header.s=20161025 header.b=UcuHbh2l; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=REJECT sp=REJECT dis=NONE) header.from=google.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id l14si14054087ilf.126.2021.08.02.11.09.52; Mon, 02 Aug 2021 11:10:08 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) client-ip=23.128.96.18; Authentication-Results: mx.google.com; dkim=pass header.i=@google.com header.s=20161025 header.b=UcuHbh2l; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=REJECT sp=REJECT dis=NONE) header.from=google.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S229710AbhHBSJB (ORCPT + 99 others); Mon, 2 Aug 2021 14:09:01 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:47888 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229537AbhHBSJA (ORCPT ); Mon, 2 Aug 2021 14:09:00 -0400 Received: from mail-pl1-x649.google.com (mail-pl1-x649.google.com [IPv6:2607:f8b0:4864:20::649]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 17B30C06175F for ; Mon, 2 Aug 2021 11:08:50 -0700 (PDT) Received: by mail-pl1-x649.google.com with SMTP id x7-20020a170902b407b029012c8cffc695so8256747plr.2 for ; Mon, 02 Aug 2021 11:08:50 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20161025; h=date:message-id:mime-version:subject:from:to:cc; bh=j+JSAL2TyTO06rmOJxXfenDO1JaBiOx8vJieMlI9pfs=; b=UcuHbh2lDaqGs/MbwByb6nz+B/co5nzT1R6NZhmA9NdIsZ040uo8xyHQh0XBBND7N5 FI3HwlivUGntgnh0D27Em+HiAYwCVDKhqhfH8YZqQr00B7tzgf1u57utnYjG6aBwlvLF zFfPvhhCPnxnqP3fbByF+3iehSxCd4BIkM9ceagxD6y9bOjLtC0LxoDDrFvIVYdK6RUz W6vlGioEeNf8j8C4Zerh4WMqwFyKa206rBGYI+IDnAWVAHEZrfbfIqzVOHQfXRNGygq5 9DkbD0DIugA89cd7d6aIje5OBCTvhjnYkYEirB168/1Atr4V9lq2mK4GRyUBBX6ij9wm +FEg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:date:message-id:mime-version:subject:from:to:cc; bh=j+JSAL2TyTO06rmOJxXfenDO1JaBiOx8vJieMlI9pfs=; b=Ke8F7HqI1kxz3JN6pxYV/0fE2IdvXauozJVkb7SR77EAoA1NtKHXpkZLrjNG+g6758 1gAuaBBmbkGUYQ9gVr2kck1rhVf3rX7mH15jfbFtavU6AGqn+oLIm/Frro2ckhUryuMN 6ekVYUoHp4eCEk00rbLWxtwYVSGcEMFyvCB4A9aY4QMemahRvYxlfv39Y1WfNi8CdCeg W3Jh9q7aPdA/9WVGbA1JuWW7eHjSyvGGzuwiUBXjtlr2kQCRnA5nHTrF874cjhUA3xWz OFlOfQw3/0Ijy43ETrA8BuYtKK741C4dGyWM/8gPAVS+a+kMV5YnvWYSdX5wFj5W6711 O1cw== X-Gm-Message-State: AOAM532LjX5whuCcn9jIbU3y3eBqRDcGqPo2Lx/q6We72/2mGYjNqbBL srZp+6ZVtxqmK35XUZg2mjl+zLtoUuHpVg== X-Received: from shakeelb.svl.corp.google.com ([2620:15c:2cd:202:75f8:2e73:f9c:f799]) (user=shakeelb job=sendgmr) by 2002:a17:90b:3d6:: with SMTP id go22mr18047527pjb.40.1627927729598; Mon, 02 Aug 2021 11:08:49 -0700 (PDT) Date: Mon, 2 Aug 2021 11:08:18 -0700 Message-Id: <20210802180819.1110165-1-shakeelb@google.com> Mime-Version: 1.0 X-Mailer: git-send-email 2.32.0.554.ge1b32706d8-goog Subject: [PATCH] slub: fix kmalloc_pagealloc_invalid_free unit test From: Shakeel Butt To: Christoph Lameter , Pekka Enberg , David Rientjes , Vlastimil Babka Cc: Michal Hocko , Roman Gushchin , Wang Hai , Muchun Song , Andrew Morton , linux-mm@kvack.org, linux-kernel@vger.kernel.org, Shakeel Butt , Nathan Chancellor , Joonsoo Kim Content-Type: text/plain; charset="UTF-8" Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org The unit test kmalloc_pagealloc_invalid_free makes sure that for the higher order slub allocation which goes to page allocator, the free is called with the correct address i.e. the virtual address of the head page. The commit f227f0faf63b ("slub: fix unreclaimable slab stat for bulk free") unified the free code paths for page allocator based slub allocations but instead of using the address passed by the caller, it extracted the address from the page. Thus making the unit test kmalloc_pagealloc_invalid_free moot. So, fix this by using the address passed by the caller. Should we fix this? I think yes because dev expect kasan to catch these type of programming bugs. Fixes: f227f0faf63b ("slub: fix unreclaimable slab stat for bulk free") Signed-off-by: Shakeel Butt Reported-by: Nathan Chancellor Cc: Michal Hocko Cc: Roman Gushchin Cc: Muchun Song Cc: Christoph Lameter Cc: Pekka Enberg Cc: David Rientjes Cc: Joonsoo Kim Cc: Vlastimil Babka Cc: Andrew Morton --- mm/slub.c | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/mm/slub.c b/mm/slub.c index af984e4990e8..60aeedc436d5 100644 --- a/mm/slub.c +++ b/mm/slub.c @@ -3236,12 +3236,12 @@ struct detached_freelist { struct kmem_cache *s; }; -static inline void free_nonslab_page(struct page *page) +static inline void free_nonslab_page(struct page *page, void *object) { unsigned int order = compound_order(page); VM_BUG_ON_PAGE(!PageCompound(page), page); - kfree_hook(page_address(page)); + kfree_hook(object); mod_lruvec_page_state(page, NR_SLAB_UNRECLAIMABLE_B, -(PAGE_SIZE << order)); __free_pages(page, order); } @@ -3282,7 +3282,7 @@ int build_detached_freelist(struct kmem_cache *s, size_t size, if (!s) { /* Handle kalloc'ed objects */ if (unlikely(!PageSlab(page))) { - free_nonslab_page(page); + free_nonslab_page(page, object); p[size] = NULL; /* mark object processed */ return size; } @@ -4258,7 +4258,7 @@ void kfree(const void *x) page = virt_to_head_page(x); if (unlikely(!PageSlab(page))) { - free_nonslab_page(page); + free_nonslab_page(page, object); return; } slab_free(page->slab_cache, page, object, NULL, 1, _RET_IP_); -- 2.32.0.554.ge1b32706d8-goog