From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from smtp.kernel.org (aws-us-west-2-korg-mail-1.web.codeaurora.org [10.30.226.201]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id D541673161; Wed, 21 Feb 2024 13:22:53 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=10.30.226.201 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1708521773; cv=none; b=ZpLHAD31MsfClWKyIlCQK07IVHaiLRGjXR/1baFG+W9y9sNrl5SRW8h93D1h2TNxuM/qIq8PLOA6jxAcH6+WQz79Ub/ASprs3BJru7O/lKX1djhznvfmbwebacTbjpGYzrDkR6BJdnognzkHhBjzQvmxgG4Ocftwhqj+TagFvhE= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1708521773; c=relaxed/simple; bh=aPjV3nVjStsz0oxFXFsvurJj91KzdGQG44w/A1Ay9vY=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=hhFRwXjySS11lAaqIgdN7L6sT3+HIzxVa5Jjx9E5XIjTkyIZSUlafsB3nfPuyKevzLGSVPuzg9g1czxS70ScOh3zQScqa8cpP84ZTd8t0ya1BXiuVsvheUitqMXvHzCP9kbkqX8hYaTq9IryoD3bzihKDQ8ADehPHIl8Orm/C0k= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=linuxfoundation.org header.i=@linuxfoundation.org header.b=ry9IVB/t; arc=none smtp.client-ip=10.30.226.201 Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=linuxfoundation.org header.i=@linuxfoundation.org header.b="ry9IVB/t" Received: by smtp.kernel.org (Postfix) with ESMTPSA id 5DD87C433C7; Wed, 21 Feb 2024 13:22:53 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linuxfoundation.org; s=korg; t=1708521773; bh=aPjV3nVjStsz0oxFXFsvurJj91KzdGQG44w/A1Ay9vY=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=ry9IVB/tsxt+ntjiWM0Xw8rVfFfVzlDveVUjpSU5LtK72wuixfQtSb1XpDW2AEcLM dN+shpehAxxbIJAly6e6xUVBtAbclBknBnT3M699IiN7VY8BKKdUFUUwOBLu0RxHWw Q3FzX1P19FLsdbcDvWS/Z2oHvbbhAWHY1qDpkgXM= From: Greg Kroah-Hartman To: stable@vger.kernel.org Cc: Greg Kroah-Hartman , patches@lists.linux.dev, Zach OKeefe , Maxim Patlasov , Andrew Morton Subject: [PATCH 4.19 174/202] mm/writeback: fix possible divide-by-zero in wb_dirty_limits(), again Date: Wed, 21 Feb 2024 14:07:55 +0100 Message-ID: <20240221125937.431280850@linuxfoundation.org> X-Mailer: git-send-email 2.43.2 In-Reply-To: <20240221125931.742034354@linuxfoundation.org> References: <20240221125931.742034354@linuxfoundation.org> User-Agent: quilt/0.67 X-stable: review X-Patchwork-Hint: ignore Precedence: bulk X-Mailing-List: patches@lists.linux.dev List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: 8bit 4.19-stable review patch. If anyone has any objections, please let me know. ------------------ From: Zach O'Keefe commit 9319b647902cbd5cc884ac08a8a6d54ce111fc78 upstream. (struct dirty_throttle_control *)->thresh is an unsigned long, but is passed as the u32 divisor argument to div_u64(). On architectures where unsigned long is 64 bytes, the argument will be implicitly truncated. Use div64_u64() instead of div_u64() so that the value used in the "is this a safe division" check is the same as the divisor. Also, remove redundant cast of the numerator to u64, as that should happen implicitly. This would be difficult to exploit in memcg domain, given the ratio-based arithmetic domain_drity_limits() uses, but is much easier in global writeback domain with a BDI_CAP_STRICTLIMIT-backing device, using e.g. vm.dirty_bytes=(1<<32)*PAGE_SIZE so that dtc->thresh == (1<<32) Link: https://lkml.kernel.org/r/20240118181954.1415197-1-zokeefe@google.com Fixes: f6789593d5ce ("mm/page-writeback.c: fix divide by zero in bdi_dirty_limits()") Signed-off-by: Zach O'Keefe Cc: Maxim Patlasov Cc: Signed-off-by: Andrew Morton Signed-off-by: Greg Kroah-Hartman --- mm/page-writeback.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) --- a/mm/page-writeback.c +++ b/mm/page-writeback.c @@ -1529,7 +1529,7 @@ static inline void wb_dirty_limits(struc */ dtc->wb_thresh = __wb_calc_thresh(dtc); dtc->wb_bg_thresh = dtc->thresh ? - div_u64((u64)dtc->wb_thresh * dtc->bg_thresh, dtc->thresh) : 0; + div64_u64(dtc->wb_thresh * dtc->bg_thresh, dtc->thresh) : 0; /* * In order to avoid the stacked BDI deadlock we need