From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id C5A22C35275 for ; Mon, 7 Feb 2022 15:12:13 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1443048AbiBGPKQ (ORCPT ); Mon, 7 Feb 2022 10:10:16 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:60042 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1384220AbiBGO7E (ORCPT ); Mon, 7 Feb 2022 09:59:04 -0500 Received: from zeniv-ca.linux.org.uk (zeniv-ca.linux.org.uk [IPv6:2607:5300:60:148a::1]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 081D6C0401C6; Mon, 7 Feb 2022 06:59:02 -0800 (PST) Received: from viro by zeniv-ca.linux.org.uk with local (Exim 4.94.2 #2 (Red Hat Linux)) id 1nH5Tn-000Dvl-Oe; Mon, 07 Feb 2022 14:58:59 +0000 Date: Mon, 7 Feb 2022 14:58:59 +0000 From: Al Viro To: Ari Sundholm Cc: Andrew Morton , linux-kernel@vger.kernel.org, linux-fsdevel@vger.kernel.org, stable@vger.kernel.org, Anton Altaparmakov Subject: Re: [PATCH] fs/read_write.c: Fix a broken signed integer overflow check. Message-ID: References: <20220207120711.4070403-1-ari@tuxera.com> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <20220207120711.4070403-1-ari@tuxera.com> Sender: Al Viro Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Mon, Feb 07, 2022 at 02:07:11PM +0200, Ari Sundholm wrote: > The function generic_copy_file_checks() checks that the ends of the > input and output file ranges do not overflow. Unfortunately, there is > an issue with the check itself. > > Due to the integer promotion rules in C, the expressions > (pos_in + count) and (pos_out + count) have an unsigned type because > the count variable has the type uint64_t. Thus, in many cases where we > should detect signed integer overflow to have occurred (and thus one or > more of the ranges being invalid), the expressions will instead be > interpreted as large unsigned integers. This means the check is broken. I must be slow this morning, but... which values of pos_in and count are caught by your check, but not by the original? > - if (pos_in + count < pos_in || pos_out + count < pos_out) > + if ((loff_t)(pos_in + count) < pos_in || > + (loff_t)(pos_out + count) < pos_out) Example, please. Why do you need that comparison to be signed?