Received: by 2002:a25:ad19:0:0:0:0:0 with SMTP id y25csp3031963ybi; Tue, 2 Jul 2019 00:46:47 -0700 (PDT) X-Google-Smtp-Source: APXvYqzXWAscFzuDJFYwNLQ7w5TP3GjKGEKTfzPvgfuSBytafSToJIW1qrp7s8bUc7SnnIcOpSnJ X-Received: by 2002:a63:2259:: with SMTP id t25mr27112249pgm.298.1562053606943; Tue, 02 Jul 2019 00:46:46 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1562053606; cv=none; d=google.com; s=arc-20160816; b=L4sazqhF84Lrspoy1ToLw2A7u/ecovzexiP4EmTRcmEA8w1K7llQviSlhFDzZtVZ9B yOc1UNa34ElKfGqaHTOk/5TdT1Ds+3uHvFIHMDPNONPc0BSsBEUc2k+bo7nsKbhG9WzN 5akI2Wfy3HrUP7cwhiZ8ckdB4C8zJL5PG4DpXLqOmWBTXyNbzpMZsDVanqk/4t5YIY/W D7mCPEoVVn/pIJKClMuqAmrlF0biw9Q590Pusnw38HBEF18w5lO9JteSOU0A3ZflHcKF Gqx/k5nw6QxXtXTKLPNrH+bq+nRzYwFzqAR/fKpTqad4SH6pE3MSpJJiQHvqDfcKnaYA n9PA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:cc:to:subject:message-id:date:from :in-reply-to:references:mime-version:dkim-signature; bh=5IrBPD0J3ThoKKFU4/FQRnog7nkm0QgrOR9tIqfG3FY=; b=B3XMoYrkCEUQq8tFLdrPyNBIHkulduAZYnpLbdt/vkkibmFnjRkmIVqt5nHaAFuOqn MVyyBzoy7XjFFQVl7+zW/QXWKfKoHf+PKZ/oqgFWAqItPp40EMXwInE/NEkM9RjgTeY8 OSAYHCQy2YmSW6IVC9JH9F/Gr9ns2aEYoafiZi5Rf60kFcAFpX1RYzCFPZPVM74OQU4s Q1/SzKctBhWxngVvfwSA/qr0Z22X19Up7M0kVBJ7+X4VvPVyQAtF5ufVoYCrHGA6q8Af xM09pRuG3UL5aJ/tPr2jbQ8qP6aB+ele9M33/4Fjgh9o6qawCrGQuczqhNNB4lGuWUXI WAxg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@gmail.com header.s=20161025 header.b=d1R5QsTY; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=gmail.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id e1si1636517pjr.28.2019.07.02.00.46.31; Tue, 02 Jul 2019 00:46:46 -0700 (PDT) Received-SPF: pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; dkim=pass header.i=@gmail.com header.s=20161025 header.b=d1R5QsTY; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=gmail.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1725981AbfGBHqA (ORCPT + 99 others); Tue, 2 Jul 2019 03:46:00 -0400 Received: from mail-lj1-f194.google.com ([209.85.208.194]:41893 "EHLO mail-lj1-f194.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1725851AbfGBHp7 (ORCPT ); Tue, 2 Jul 2019 03:45:59 -0400 Received: by mail-lj1-f194.google.com with SMTP id 205so15863202ljj.8 for ; Tue, 02 Jul 2019 00:45:58 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=mime-version:references:in-reply-to:from:date:message-id:subject:to :cc; bh=5IrBPD0J3ThoKKFU4/FQRnog7nkm0QgrOR9tIqfG3FY=; b=d1R5QsTYa5MTtTEHHeCBzlMg9hZoSTCrw52r1zZF5ZH3HtRyfd1fMwfCVSWnHKA2kG 4yOBQgQwFxAfrJAoRCkpslMVYXq4M4qzZEhhN5eAueF6CDd47bf1YGy7CVMb4QD9NZ6N 9FFBS5L6sLobrCnhGda6f/KzikGGytL1t7rQamquIJyhjAVuuWEx7we3wKkf24HvN7Nl 6GDP08kRaJ2X8lBBU/kp/7dw40Kwc2TysdxBYOdxkhkWZwSAlHYNiQ6QQDdXumAjceiA re/bUmjD12UwXfzamlmxA5GbyLp1Ijx3uuJh4MGTHoBwxSrc7K+2vWPk15rDH77JGhPb yT2w== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:mime-version:references:in-reply-to:from:date :message-id:subject:to:cc; bh=5IrBPD0J3ThoKKFU4/FQRnog7nkm0QgrOR9tIqfG3FY=; b=XUnwkB5n6mdCye1ieIbxgxqwlGFMf0KeklLQ3z5A8NgNDgKHiH+LH0YjgVJC4Q+ALW ifvcphP/6H6MFGwCl/FD/d8h0zCXR8jCkx5Ta+qUGNWM85rvwplRIakCpom4xoZgQLlt HdbtDlVb7+iHyv8F/lg6RO73cBucMrc4xsVNLhQADaIeBvViflq90ROjhry2fYihw2z9 bQQkkR/vYEDnwacH3gxQuxRkENGWVk9MHKaPg2GkZrTq28dFOyPe+WyhuPqVSEj755G4 fdS/iMfi/CrrEMVczqzlbyTGbCqyiODNoHUF/gttSnwcaytt4QG/6WMO83o4Pe+d0iMY Ly/A== X-Gm-Message-State: APjAAAUE+NCxO+EHFFaoGx5NhkOj8LLafJqUSRhXsmkh7hjYvvVflS77 TY9bgkCr02i/Q3l67oSKzHEPtM7IdLt/IHBuRD4= X-Received: by 2002:a2e:86cc:: with SMTP id n12mr16247419ljj.146.1562053557722; Tue, 02 Jul 2019 00:45:57 -0700 (PDT) MIME-Version: 1.0 References: <20190701173042.221453-1-henryburns@google.com> In-Reply-To: <20190701173042.221453-1-henryburns@google.com> From: Vitaly Wool Date: Tue, 2 Jul 2019 10:45:46 +0300 Message-ID: Subject: Re: [PATCH] mm/z3fold: Fix z3fold_buddy_slots use after free To: Henry Burns Cc: Andrew Morton , Matthew Wilcox , Vitaly Vul , Mike Rapoport , Xidong Wang , Shakeel Butt , Jonathan Adams , Linux-MM , LKML Content-Type: text/plain; charset="UTF-8" Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Hi Henry, On Mon, Jul 1, 2019 at 8:31 PM Henry Burns wrote: > > Running z3fold stress testing with address sanitization > showed zhdr->slots was being used after it was freed. > > z3fold_free(z3fold_pool, handle) > free_handle(handle) > kmem_cache_free(pool->c_handle, zhdr->slots) > release_z3fold_page_locked_list(kref) > __release_z3fold_page(zhdr, true) > zhdr_to_pool(zhdr) > slots_to_pool(zhdr->slots) *BOOM* Thanks for looking into this. I'm not entirely sure I'm all for splitting free_handle() but let me think about it. > Instead we split free_handle into two functions, release_handle() > and free_slots(). We use release_handle() in place of free_handle(), > and use free_slots() to call kmem_cache_free() after > __release_z3fold_page() is done. A little less intrusive solution would be to move backlink to pool from slots back to z3fold_header. Looks like it was a bad idea from the start. Best regards, Vitaly