Received: by 2002:a05:6a10:5bc5:0:0:0:0 with SMTP id os5csp704675pxb; Mon, 25 Oct 2021 17:03:18 -0700 (PDT) X-Google-Smtp-Source: ABdhPJxjEBDNISjzc8Xrqy5tS9b+RqhUnrVS/fYc1Zi++2SrSCod86uG9Q1Is2JcZvlx2HbF7vf+ X-Received: by 2002:a17:906:9b89:: with SMTP id dd9mr26578599ejc.15.1635206598027; Mon, 25 Oct 2021 17:03:18 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1635206598; cv=none; d=google.com; s=arc-20160816; b=wK5lMiW7sqdgSB726opCtaRXHUY3T58PcfqZKyLVV7cIpK4xWcvEcyVTKEZ0q/0hGk 8oDShH59ddmjclsPAC0SmZPsS3F/ax4CJAxe34BNjAEDOq7+tceEMrjXuZlFBDQNbYRf b0sNfaGbPx/zA9YcsfOfHKAF9aW2k4U+sd/ODOzNGPP5zVZBuA38lq8VHKqG7qIzo3IS 1qPAcU5CIXuHvZ/4jTgFkuUHKdaqA//4UocJKkGwKv6DzCyqLZwHwY0pFoRio2f0gsbM udKQGZBca5aKXoFCTzJs+TZnMycRkn9+0VAfhaoxCFfJLv6fJUIXbgFTd43qsMmE6Gnu gAZA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :user-agent:references:in-reply-to:message-id:date:subject:cc:to :from:dkim-signature; bh=XYRDC/PacgYN2hizV+zTIVNupvOd3G9cXXvSQNrDb3o=; b=IyfFpIRqihBUUxb0Crg0JXhxWqrMAGcW3kaTO+IycdiNPMxMzoOeqMuoVsMxFksaNw M3iudx6QCkvwxd1bkksF5tngGptv8MvoDPCrApgrxBCHrasQfRvqC32WZjjtHUI1IuBz 91H67DWyVHLYet9fwriYCJpeGuaMuBrBAIqgvKsZVwX+Rgwi9Ie+/j9LtOCkP0VgibY/ JMaKJtLOrL9TnW5aI+4WkotW0PK6hhFOSnDUxIckcHk4geIhkpeDrkJcHpmy60IlkF0p 9ajfm+ABfAgVeKadxbt5LcDhx+6TSVZn2p6/cp6M2km8M9X6fQDjHkpBW3d+DTDlUGDY VR1A== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b=HhSAAwxO; 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=NONE sp=NONE dis=NONE) header.from=linuxfoundation.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id hg6si2122279ejc.448.2021.10.25.17.02.40; Mon, 25 Oct 2021 17:03:18 -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=@linuxfoundation.org header.s=korg header.b=HhSAAwxO; 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=NONE sp=NONE dis=NONE) header.from=linuxfoundation.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S235010AbhJYTlM (ORCPT + 99 others); Mon, 25 Oct 2021 15:41:12 -0400 Received: from mail.kernel.org ([198.145.29.99]:48370 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S235777AbhJYTc1 (ORCPT ); Mon, 25 Oct 2021 15:32:27 -0400 Received: by mail.kernel.org (Postfix) with ESMTPSA id E4FBF6115A; Mon, 25 Oct 2021 19:28:40 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linuxfoundation.org; s=korg; t=1635190121; bh=iGU5cIuAvJ/uiVvay9MjxSK1rq9mfR2mMKbqmdDwqmY=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=HhSAAwxOVe4Lw40IgP6SKoL3OpYQpENt7GMjmjEkqALSwaFY9ifWE5BLp6KIike5S xtE+p7k1XvE/w7cPIF3r5bIK7v55/UdwpBa4u5gmy3wTcZU3hLl8J0eSr0iuyfTAJX ojd4VHe+o6Mf6vw3OGEI0dTJtC2wykgfnVMs/zzA= From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , stable@vger.kernel.org, Miaohe Lin , Vlastimil Babka , Andrey Konovalov , Andrey Ryabinin , Bharata B Rao , Christoph Lameter , David Rientjes , Faiyaz Mohammed , Joonsoo Kim , Kees Cook , Pekka Enberg , Roman Gushchin , Andrew Morton , Linus Torvalds Subject: [PATCH 5.4 39/58] mm, slub: fix mismatch between reconstructed freelist depth and cnt Date: Mon, 25 Oct 2021 21:14:56 +0200 Message-Id: <20211025190943.894918734@linuxfoundation.org> X-Mailer: git-send-email 2.33.1 In-Reply-To: <20211025190937.555108060@linuxfoundation.org> References: <20211025190937.555108060@linuxfoundation.org> User-Agent: quilt/0.66 MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org From: Miaohe Lin commit 899447f669da76cc3605665e1a95ee877bc464cc upstream. If object's reuse is delayed, it will be excluded from the reconstructed freelist. But we forgot to adjust the cnt accordingly. So there will be a mismatch between reconstructed freelist depth and cnt. This will lead to free_debug_processing() complaining about freelist count or a incorrect slub inuse count. Link: https://lkml.kernel.org/r/20210916123920.48704-3-linmiaohe@huawei.com Fixes: c3895391df38 ("kasan, slub: fix handling of kasan_slab_free hook") Signed-off-by: Miaohe Lin Reviewed-by: Vlastimil Babka Cc: Andrey Konovalov Cc: Andrey Ryabinin Cc: Bharata B Rao Cc: Christoph Lameter Cc: David Rientjes Cc: Faiyaz Mohammed Cc: Greg Kroah-Hartman Cc: Joonsoo Kim Cc: Kees Cook Cc: Pekka Enberg Cc: Roman Gushchin Cc: Signed-off-by: Andrew Morton Signed-off-by: Linus Torvalds Signed-off-by: Greg Kroah-Hartman --- mm/slub.c | 11 +++++++++-- 1 file changed, 9 insertions(+), 2 deletions(-) --- a/mm/slub.c +++ b/mm/slub.c @@ -1455,7 +1455,8 @@ static __always_inline bool slab_free_ho } static inline bool slab_free_freelist_hook(struct kmem_cache *s, - void **head, void **tail) + void **head, void **tail, + int *cnt) { void *object; @@ -1490,6 +1491,12 @@ static inline bool slab_free_freelist_ho *head = object; if (!*tail) *tail = object; + } else { + /* + * Adjust the reconstructed freelist depth + * accordingly if object's reuse is delayed. + */ + --(*cnt); } } while (object != old_tail); @@ -3049,7 +3056,7 @@ static __always_inline void slab_free(st * With KASAN enabled slab_free_freelist_hook modifies the freelist * to remove objects, whose reuse must be delayed. */ - if (slab_free_freelist_hook(s, &head, &tail)) + if (slab_free_freelist_hook(s, &head, &tail, &cnt)) do_slab_free(s, page, head, tail, cnt, addr); }