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 7801680033; Wed, 21 Feb 2024 14:10:20 +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=1708524620; cv=none; b=aNAsQRdZ1Lbm0B/0Lp/NAXVFPP/JW1B7KABW+bb9jj3m2B8pVi/lgWI8PWq2gLYZ6RSL1CG/hVHx7D63Gs3Co1bojSVVDYUinEtQD+rG2ORbf37bRR3OvD2DOgPe/VQ8xQnApDEmtI/3YBSvqSxqcYBDp4s6c4c8S/XDeGwN1O0= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1708524620; c=relaxed/simple; bh=ZwjVPCY0Am3o53yDDEkWEixlhodVuRoyWg/UIb0IKwU=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=FvYc+to4NEBJndYUtyDFSep8oMbZJgIrf35LIVvk4NXZn58eMkyOLGQuFD017qke4Y2wz364DWv79ZwAYNue30qRySbEc2LH0hhrMZ8fHEBX4WbDqMIpfuXWPVU/GjPJHzubJzxq4lMm+g//G3LsSHteXDGRPaa6WY9d24dDGuo= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=linuxfoundation.org header.i=@linuxfoundation.org header.b=tAaxkm8B; 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="tAaxkm8B" Received: by smtp.kernel.org (Postfix) with ESMTPSA id EB972C433F1; Wed, 21 Feb 2024 14:10:19 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linuxfoundation.org; s=korg; t=1708524620; bh=ZwjVPCY0Am3o53yDDEkWEixlhodVuRoyWg/UIb0IKwU=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=tAaxkm8BcubZyOPkMSV7gcAMmrhp4zILxkQFvKM4ikkgxirp85cJ7sA9PGXP39jFu 66jhlcY/38qpIun9wGcbCE6w73gL+7LWeruny71NvYh5Sw9HDzEo+SZGyFyaET1hqK sWFEj0KTkeJT5SwN9zcos5CPR9q8rGJtUlJQh5d0= 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 5.10 298/379] mm/writeback: fix possible divide-by-zero in wb_dirty_limits(), again Date: Wed, 21 Feb 2024 14:07:57 +0100 Message-ID: <20240221130003.739286268@linuxfoundation.org> X-Mailer: git-send-email 2.43.2 In-Reply-To: <20240221125954.917878865@linuxfoundation.org> References: <20240221125954.917878865@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 5.10-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 @@ -1524,7 +1524,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