]> git.ipfire.org Git - thirdparty/kernel/stable.git/commit
writeback: use |1 instead of +1 to protect against div by zero
authorTejun Heo <tj@kernel.org>
Tue, 21 Apr 2015 20:49:13 +0000 (16:49 -0400)
committerSasha Levin <sasha.levin@oracle.com>
Sat, 23 May 2015 19:52:00 +0000 (15:52 -0400)
commit4e258a15e1037e05492a11cde68cb4ece0a21248
treeec6e1c731940c4e06fd4e296a13bd2ea0d94ba77
parentf42b455331b5eb2ef5f2cecab28941eb1fada554
writeback: use |1 instead of +1 to protect against div by zero

[ Upstream commit 464d1387acb94dc43ba772b35242345e3d2ead1b ]

mm/page-writeback.c has several places where 1 is added to the divisor
to prevent division by zero exceptions; however, if the original
divisor is equivalent to -1, adding 1 leads to division by zero.

There are three places where +1 is used for this purpose - one in
pos_ratio_polynom() and two in bdi_position_ratio().  The second one
in bdi_position_ratio() actually triggered div-by-zero oops on a
machine running a 3.10 kernel.  The divisor is

  x_intercept - bdi_setpoint + 1 == span + 1

span is confirmed to be (u32)-1.  It isn't clear how it ended up that
but it could be from write bandwidth calculation underflow fixed by
c72efb658f7c ("writeback: fix possible underflow in write bandwidth
calculation").

At any rate, +1 isn't a proper protection against div-by-zero.  This
patch converts all +1 protections to |1.  Note that
bdi_update_dirty_ratelimit() was already using |1 before this patch.

Signed-off-by: Tejun Heo <tj@kernel.org>
Cc: stable@vger.kernel.org
Reviewed-by: Jan Kara <jack@suse.cz>
Signed-off-by: Jens Axboe <axboe@fb.com>
Signed-off-by: Sasha Levin <sasha.levin@oracle.com>
mm/page-writeback.c