Received: by 2002:ab2:7b86:0:b0:1f7:5705:b850 with SMTP id q6csp1444661lqh; Mon, 6 May 2024 07:59:21 -0700 (PDT) X-Forwarded-Encrypted: i=3; AJvYcCUcGNMUyHtdh0kq2y0eHlaggCq3kzemp49doK4zR3GaxWmasbjcu9UW8kfGZ0Wt9GGHctQqCOaKoHeKtoBtNHJ243vVneDmHTafCUVbqQ== X-Google-Smtp-Source: AGHT+IE38+eKyGInDCvi1eq7ZHk8ANLeQScC5zGetahPA/sIRwNUXO8Y43W7yIrw9VabOeJfpVL5 X-Received: by 2002:a17:907:9493:b0:a59:bacc:b082 with SMTP id dm19-20020a170907949300b00a59baccb082mr3053734ejc.60.1715007561489; Mon, 06 May 2024 07:59:21 -0700 (PDT) ARC-Seal: i=2; a=rsa-sha256; t=1715007561; cv=pass; d=google.com; s=arc-20160816; b=dPJ/NtgrgeiorX9+ss/XkqMxN+y4XUvVH9be1/zHK9GjKm5pEu2PqCtNtdHEwpfPlL BllICISwoyxOyno34lNyhMrVf36ElNHDkbrSCakT3X9NMr0/BeodUPPQ4oDYegotPOTY iW4P7ubaB2D+MUhXuF4X06YpBb8yGdZ+B12Faqq1FoeEt1YU+BkDtshBBVvr4uK76NAu Lcpjz24OPyRqirBem4mdvIwTP92lHoICqDh/w5O1H+McLB6YLg5F5fA+H+MFkYBD40Sh F3TsBpVONTRykzZC5kC9s3BxceByNFklq8nSJ3U1XUAlcniXU4r7+S6XH8BsOsnuokCY K4ew== ARC-Message-Signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=in-reply-to:content-disposition:mime-version:list-unsubscribe :list-subscribe:list-id:precedence:references:message-id:subject:cc :to:from:date:dkim-signature; bh=IunX6IRuqcgUzJVC/f5W6bbijjjJpOpS2R20SUSIYXo=; fh=YuhRGR1hLkyXW4H3ZJnT+6iwqQCR0pwMLIchTDHe0Gs=; b=M4TwwDUPgzeZ3T3ys8SdwUs8Z+KF0YTnYha1f5Ri12V13cFfvM5udEV+VP10c37Avi 7U7WiAf0P8SycYbbxt7MunbY4Qf/MFRJyDQ5wMGsG4PQkARtdqcwo0oOX7IwZLdTAAtc wYlsL/2EyDj4AoR75s4rSVmoLSEA/5aWEr0YkhfmKD9VoKkVGwZO/JMZYL2oZZ6+4zus 04zhGXkQhlSbcA1sB4t/5I8UxyS/CmIH/XpYNEU20Up+tSH9VtyHYuE9cdKqVEkGCrAJ q9WZMUisjg+URrLImbkmgMMC9zco9cOdfW5hVULZScy2/SjVPQd8caajncWqEqLKK08x reNg==; dara=google.com ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@chromium.org header.s=google header.b=CiBJPl+u; arc=pass (i=1 spf=pass spfdomain=chromium.org dkim=pass dkdomain=chromium.org dmarc=pass fromdomain=chromium.org); spf=pass (google.com: domain of linux-kernel+bounces-170032-linux.lists.archive=gmail.com@vger.kernel.org designates 147.75.80.249 as permitted sender) smtp.mailfrom="linux-kernel+bounces-170032-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=chromium.org Return-Path: Received: from am.mirrors.kernel.org (am.mirrors.kernel.org. [147.75.80.249]) by mx.google.com with ESMTPS id ds22-20020a170907725600b00a59b7305ce2si2495457ejc.604.2024.05.06.07.59.21 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 06 May 2024 07:59:21 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel+bounces-170032-linux.lists.archive=gmail.com@vger.kernel.org designates 147.75.80.249 as permitted sender) client-ip=147.75.80.249; Authentication-Results: mx.google.com; dkim=pass header.i=@chromium.org header.s=google header.b=CiBJPl+u; arc=pass (i=1 spf=pass spfdomain=chromium.org dkim=pass dkdomain=chromium.org dmarc=pass fromdomain=chromium.org); spf=pass (google.com: domain of linux-kernel+bounces-170032-linux.lists.archive=gmail.com@vger.kernel.org designates 147.75.80.249 as permitted sender) smtp.mailfrom="linux-kernel+bounces-170032-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=chromium.org Received: from smtp.subspace.kernel.org (wormhole.subspace.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by am.mirrors.kernel.org (Postfix) with ESMTPS id 3BA371F21C2A for ; Mon, 6 May 2024 14:59:21 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 93A37153811; Mon, 6 May 2024 14:59:15 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=chromium.org header.i=@chromium.org header.b="CiBJPl+u" Received: from mail-pg1-f179.google.com (mail-pg1-f179.google.com [209.85.215.179]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 5C2A31534E5 for ; Mon, 6 May 2024 14:59:13 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.215.179 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1715007554; cv=none; b=JmC4rfrCK/chvkT73KcLikPlY5wMyygH1ZlMAmuKhQUxSocIZBLQSvhmnAcfXq+pkWgn56UkmtUkdIK1T6ppB0UqFaN5trEhDB6Jen6FtKuB87kMfBO8sPCuogeQ2cwrLPODqtcW3GnxyxYvXONtllZt9frLuEbN+rnVK5B4srY= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1715007554; c=relaxed/simple; bh=1erwTJnls/2PKUoCQh7VD31qDN99YRlnp3qvueSRMe4=; h=Date:From:To:Cc:Subject:Message-ID:References:MIME-Version: Content-Type:Content-Disposition:In-Reply-To; b=tPLHJB52HgvdyPKLK0K3OTNrRVgVDXBTk4ZCpravzxZCHmE6FZ09eHplWzYwwjzs/84OR+maFhVlWVfGttlU1hjHylFCLcHPi5a9gTW9xeeUNTb5RRakwnCHMiWyOnze+LDakGJspKYbzEwahcf9VwK4f8MO0l8F3fFUpKAseKY= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=chromium.org; spf=pass smtp.mailfrom=chromium.org; dkim=pass (1024-bit key) header.d=chromium.org header.i=@chromium.org header.b=CiBJPl+u; arc=none smtp.client-ip=209.85.215.179 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=chromium.org Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=chromium.org Received: by mail-pg1-f179.google.com with SMTP id 41be03b00d2f7-5f80aa2d4a3so1406325a12.0 for ; Mon, 06 May 2024 07:59:13 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=chromium.org; s=google; t=1715007552; x=1715612352; 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=IunX6IRuqcgUzJVC/f5W6bbijjjJpOpS2R20SUSIYXo=; b=CiBJPl+uCAZ7oLEFlX/z4LfvbLCWgiLzaJpuP+hAjSW2mXSmNkmaNvNruLjkC7JKav YJ80sAin+TLOvl7yUf6D9z7nckvA5vzvaUzTPrcLLsYn2YRYktIj+JFNb8s0Gty9HNKN Y+LRtEv57taqdTxzTGYh/gLMRi5Rzthv2Vlbg= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1715007552; x=1715612352; 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=IunX6IRuqcgUzJVC/f5W6bbijjjJpOpS2R20SUSIYXo=; b=GaZiFUfTKM7eZMnaUm9o1qlvDmYO5Reoalw7Wjb6Sr72pElex61QMUjnx56qAV5ELU DR/lkM8bXybZd7n9f0I4fMAo4hNr1RhccGK1V+juOlEenuu48aqzyBTD057WL+0WCIx2 Gw2A57bkjqBdM4mUr7DJLwQTON2bEaKFWbJZjjM9hk4VrQpqZ4NNKrd/c2LlzkQUuvD3 jzpk7G/5K8z6F1xupd5hG2BIGHanw4gS+GZnj5OA88Hw1OXQKz280ixSUdIUuwerad+P d1irCj3WXJetCZneHEGO0EPRQbyvaibmsmH3joyrlagXHZdmTDk3Rp9p2ztBm4Bb9QIC 5roA== X-Forwarded-Encrypted: i=1; AJvYcCU7yOZB/HbUskiU+QWgREBM2wKvT8Kf9/JrPpdlrtjUb6GHBcrc+E6x2d865AzsLNekkR1ffDb1vldcy/QWFCsy/2xKeXdf0Mcc6xuH X-Gm-Message-State: AOJu0YwG7cbt95CJuqVwKSl3rBp4NIQtj35Mqzjmc41/cpyjh07YBRJs EaEEVGzP2f8GMZmEZXU9U7F8ZMqQFzgH0XoZiL7/+3kjBbRuBofyTSu3eA5alQ== X-Received: by 2002:a05:6a21:3943:b0:1af:a451:52ab with SMTP id ac3-20020a056a21394300b001afa45152abmr4783770pzc.48.1715007552476; Mon, 06 May 2024 07:59:12 -0700 (PDT) Received: from www.outflux.net ([198.0.35.241]) by smtp.gmail.com with ESMTPSA id le8-20020a056a004fc800b006f475027095sm2584859pfb.167.2024.05.06.07.59.11 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 06 May 2024 07:59:12 -0700 (PDT) Date: Mon, 6 May 2024 07:59:11 -0700 From: Kees Cook To: Oscar Salvador Cc: Andrew Morton , linux-kernel@vger.kernel.org, linux-mm@kvack.org, Michal Hocko , Vlastimil Babka , Marco Elver , Andrey Konovalov , Alexander Potapenko , Alexandre Ghiti , syzbot+41bbfdb8d41003d12c0f@syzkaller.appspotmail.com Subject: Re: [PATCH v4 2/4] mm,page_owner: Fix refcount imbalance Message-ID: <202405060754.4405F8402F@keescook> References: <20240404070702.2744-1-osalvador@suse.de> <20240404070702.2744-3-osalvador@suse.de> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <20240404070702.2744-3-osalvador@suse.de> On Thu, Apr 04, 2024 at 09:07:00AM +0200, Oscar Salvador wrote: > Current code does not contemplate scenarios were an allocation and > free operation on the same pages do not handle it in the same amount > at once. > To give an example, page_alloc_exact(), where we will allocate a page > of enough order to stafisfy the size request, but we will free the > remainings right away. > > In the above example, we will increment the stack_record refcount > only once, but we will decrease it the same number of times as number > of unused pages we have to free. > This will lead to a warning because of refcount imbalance. > > Fix this by recording the number of base pages in the refcount field. > > Reported-by: syzbot+41bbfdb8d41003d12c0f@syzkaller.appspotmail.com > Closes: https://lore.kernel.org/linux-mm/00000000000090e8ff0613eda0e5@google.com > Fixes: 217b2119b9e2 ("mm,page_owner: implement the tracking of the stacks count") Does this also fix this? https://lore.kernel.org/all/202405061514.23fedba1-oliver.sang@intel.com/ This is a report of the backtrace changing, but the warning was pre-existing. > [...] > -static void dec_stack_record_count(depot_stack_handle_t handle) > +static void dec_stack_record_count(depot_stack_handle_t handle, > + int nr_base_pages) > { > struct stack_record *stack_record = __stack_depot_get_stack_record(handle); > > - if (stack_record) > - refcount_dec(&stack_record->count); > + if (!stack_record) > + return; > + > + if (refcount_sub_and_test(nr_base_pages, &stack_record->count)) > + pr_warn("%s: refcount went to 0 for %u handle\n", __func__, > + handle); This pr_warn() isn't needed: refcount will very loudly say the same thing. :) -- Kees Cook