Re: [PATCH 04/18] csum_and_copy_..._user(): pass 0xffffffff instead of 0 as initial sum

From: Linus Torvalds
Date: Tue Jul 21 2020 - 16:55:37 EST


On Tue, Jul 21, 2020 at 1:25 PM Al Viro <viro@xxxxxxxxxxxxxxxxxx> wrote:
>
> Preparation for the change of calling conventions; right now all
> callers pass 0 as initial sum. Passing 0xffffffff instead yields
> the values comparable mod 0xffff and guarantees that 0 will not
> be returned on success.

This seems dangerous to me.

Maybe some implementation depends on the fact that they actually do
the csum 16 bits at a time, and never see an overflow in "int",
because they keep folding things.

You now break that assumption, and give it an initial value that the
csum code itself would never generate, and wouldn't handle right.

But I didn't check. Maybe we don't have anything that stupid in the kernel.

Linus