Received: by 2002:ab2:6a05:0:b0:1f8:1780:a4ed with SMTP id w5csp614509lqo; Fri, 10 May 2024 09:21:39 -0700 (PDT) X-Forwarded-Encrypted: i=3; AJvYcCWKU5GQ7oYFhPdwfS0cNb6XWOWRw25s27ZcS9UhhK55xWxKZxf8NiyW8d0LBhXRt1yuSQA20jODCmcyL0vkJJKqXB4rgwsk/fmj8DenUg== X-Google-Smtp-Source: AGHT+IGhmF6Sm27JocMqWsiB/fwNOobIVdf9N0VT8l34HuD5QCIrHlUZodtrCeQudabgDi7aS9tZ X-Received: by 2002:a05:622a:1982:b0:43a:ffb9:6c65 with SMTP id d75a77b69052e-43dfd9a930dmr34531021cf.0.1715358098896; Fri, 10 May 2024 09:21:38 -0700 (PDT) ARC-Seal: i=2; a=rsa-sha256; t=1715358098; cv=pass; d=google.com; s=arc-20160816; b=fUDTLJMTvZP4K+UJmtkAzzFCzVreNB0I5NMyeDFsINnbNk12SaFbD9TDAKF1mxz2ds Lreb7b89knTppJKb63V7jT6SoyaGpXbFpdCuq87xsaabGr7BmY5gmvDhmXCtK/IMXwnf Lf6vX9SGJCydx7i6PY33r6KRAj7L5TKpAVLqXpj1Shn93RUvAEPGIQI9nxl7kJLW1rQ+ pxPXKmvPBEkQg+YuORkR+FPCtL4Aq+j+GsPhserSZxfjx+X5Ihmz7/dA00fYJr8k4MdN 1OjOe4S7IKRSkkSdWU7p4eEVc4UT3w5ju5JHkZPM/jlkIsq5zusZgs7IVKSoZAHo7Pj0 wCSw== ARC-Message-Signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=content-transfer-encoding:cc:to:subject:message-id:date:from :in-reply-to:references:mime-version:list-unsubscribe:list-subscribe :list-id:precedence:dkim-signature; bh=eFE3n+MZyxeo0bNjBIjsCbl4GDn+4HbpNAkc84Q2m38=; fh=v06yDXuzbXhQetrz2Vduk+eeaBVYGWlgXdq5gXSaKW0=; b=bhOwK3NMVX/06qUccTWfG1Hz172+UKh7A4e2r1U58TDGz+PF5zg4ClZA3V4+XtKw6s twmpmU6X0w7xvTxlsHOc8IuT9y7C+xHWrQIfAJXhwGKtv/igC+KgRY31swbYRSm0FWH9 lSSBczF3h7haVRc5Yhj75wpOi+B/wzVoEX1GnhXOXQ4grlwoJEkACOcxCo4UimNhUAER VGLfxl5LkPlxAYtFaqEhBHPwtwHoSKRpaWENfO9XmVK/nAJAf1EPtWE4sxz6b6NkntJn 0X78LlhOU/EiTEw1GBvH9nym3bFmJFqwYYZKJ0I79D3M1bEC+WMc0vvUpiSMKQuutcWF SGfQ==; dara=google.com ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@google.com header.s=20230601 header.b=JVIw+3Sd; arc=pass (i=1 spf=pass spfdomain=google.com dkim=pass dkdomain=google.com dmarc=pass fromdomain=google.com); spf=pass (google.com: domain of linux-kernel+bounces-176005-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:45d1:ec00::1 as permitted sender) smtp.mailfrom="linux-kernel+bounces-176005-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=pass (p=REJECT sp=REJECT dis=NONE) header.from=google.com Return-Path: Received: from ny.mirrors.kernel.org (ny.mirrors.kernel.org. [2604:1380:45d1:ec00::1]) by mx.google.com with ESMTPS id d75a77b69052e-43df69dd153si36205811cf.755.2024.05.10.09.21.38 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 10 May 2024 09:21:38 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel+bounces-176005-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:45d1:ec00::1 as permitted sender) client-ip=2604:1380:45d1:ec00::1; Authentication-Results: mx.google.com; dkim=pass header.i=@google.com header.s=20230601 header.b=JVIw+3Sd; arc=pass (i=1 spf=pass spfdomain=google.com dkim=pass dkdomain=google.com dmarc=pass fromdomain=google.com); spf=pass (google.com: domain of linux-kernel+bounces-176005-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:45d1:ec00::1 as permitted sender) smtp.mailfrom="linux-kernel+bounces-176005-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=pass (p=REJECT sp=REJECT dis=NONE) header.from=google.com Received: from smtp.subspace.kernel.org (wormhole.subspace.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by ny.mirrors.kernel.org (Postfix) with ESMTPS id 8421D1C24666 for ; Fri, 10 May 2024 16:21:38 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id D791D173340; Fri, 10 May 2024 16:21:21 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=google.com header.i=@google.com header.b="JVIw+3Sd" Received: from mail-yb1-f182.google.com (mail-yb1-f182.google.com [209.85.219.182]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 8A92D172798 for ; Fri, 10 May 2024 16:21:19 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.219.182 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1715358081; cv=none; b=nH8NP+M2uNNr9AzHNqAqcXKNamb4hIPLIe/UajOYnkBjs+e+LZOKP3AjRlT5pm0kUEZ7RxLkbg1Cr0/87u0LLAG3ahKd6JwkRhEdk4weinzk9po2Npnb/hBD+wUkz4WjhRVcV/aBLpBJhUE5gzXQXDPN5GmDsCoQ6k5EjsZF7XE= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1715358081; c=relaxed/simple; bh=8aU0aZOb2y9DUg+lZw8BCNxpFVehcs41OsBX/b+s5tA=; h=MIME-Version:References:In-Reply-To:From:Date:Message-ID:Subject: To:Cc:Content-Type; b=gdvpAe8HKxr2P3Z1llVj6RwAkIejPItWiE2ExsYZhOxyEldV0407XJ42AvjiNa7ThptmkG0cZs1r8doYzZhnb34knOSHvdBR3wghYJvsvl/aBYMhB38di4Mx7+M0AYDgWyiVav9uDcog7o8ma8irtLDZUlngjRYFEFoazlDWMQk= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=google.com; spf=pass smtp.mailfrom=google.com; dkim=pass (2048-bit key) header.d=google.com header.i=@google.com header.b=JVIw+3Sd; arc=none smtp.client-ip=209.85.219.182 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=google.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=google.com Received: by mail-yb1-f182.google.com with SMTP id 3f1490d57ef6-de46b113a5dso2086059276.3 for ; Fri, 10 May 2024 09:21:19 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20230601; t=1715358078; x=1715962878; darn=vger.kernel.org; h=content-transfer-encoding:cc:to:subject:message-id:date:from :in-reply-to:references:mime-version:from:to:cc:subject:date :message-id:reply-to; bh=eFE3n+MZyxeo0bNjBIjsCbl4GDn+4HbpNAkc84Q2m38=; b=JVIw+3SdPraslrAkUD+qP1EL8SvbtmlAA6hZ5bM4Hw8/qeRwI5JrXO2iIcpmaMpgZs Zun4MxTUSoxsj+OY6wfTpiRVvcFwG/VNn/FwP2F/nNraLxBkp44rQmv3eA2pHkfSKtAL 7vhxxDi/sAQ1DTbJsLD+xp0e6srravEyfLRnxbzZF2b0VNMivyFLE90e/5HtgUVnpovV gFW6bmVp78XTzYRQNGARB/YWcbQ3v4VntRu5mBCVLfKx0Ap+EQPMWQVPJS1amcWJ7RlS 9Ldf9PhdtDUTp98JzMKzKawmmUSSI7IyeZocfMbQtjH3rro+q/77A40a8w6V3KbBXUSu 0DQQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1715358078; x=1715962878; h=content-transfer-encoding:cc:to:subject:message-id:date:from :in-reply-to:references:mime-version:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=eFE3n+MZyxeo0bNjBIjsCbl4GDn+4HbpNAkc84Q2m38=; b=PvgaphYUVeIqbWWcBuL2VnAJu15HaZlUJ2Czp2DzPbVsQM7tfDXYwSvnfz8rgJQDM/ Vk0AC5NcUz+FyUtwGYQz54ZYzzQ368Reg7UOq6UJpJ9oDjH5or5iwD7YYVu4Qr+RO35y t1MAE3y/PCuMsISArctOh5VkKhKk1/OErIiDpRoLoDBEhJC0wsVXNzxrN6rmOXKKeO7d LtBgQ+BZLL7pmGcG4axjv9tnXB4eXkA9E10ydxCO6Wjhc3rysUu8LQJqocltVWDe9MWX bxeveCYXBY7D1RyO85DUJxwiA02UprO3mRghnGY0Yr5nYcROlg/j8xUYqThzJju1+3qf yPpg== X-Forwarded-Encrypted: i=1; AJvYcCV8uisqxxKv/HHzjiVDE5fndDCz0nHJTq5Is9ELXcCc4AwZ1wraIyDZjBuNSzbx8WA/4zJbF62CbdIuS9BTux3FE3xnDN3cC+VWEpw9 X-Gm-Message-State: AOJu0YyD3J0cRB4mz4LdvYgirNh6K/DUIad+DEmtuuSAvKu+1Fut7KPN 5Xj4Jd3Wm9Onzh2FoBtq7gFvyNCZ4omfu7RdtK5HM0pZH7wGqgP5fb3l12ooXKLZB/VrUEW4aTE eKnww5QSQjiJxH9hfRqG/KrU47Fi5CfD1N7nU X-Received: by 2002:a25:bc8f:0:b0:dee:6346:b856 with SMTP id 3f1490d57ef6-dee6346bbaemr42235276.34.1715358077724; Fri, 10 May 2024 09:21:17 -0700 (PDT) Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 References: <20240509-b4-sio-read_write-v1-1-06bec2022697@google.com> <20240510151508.hajqjxsn7rghk3dj@quack3> In-Reply-To: <20240510151508.hajqjxsn7rghk3dj@quack3> From: Justin Stitt Date: Fri, 10 May 2024 09:21:06 -0700 Message-ID: Subject: Re: [PATCH] fs: fix unintentional arithmetic wraparound in offset calculation To: Jan Kara Cc: Alexander Viro , Christian Brauner , Nathan Chancellor , Bill Wendling , linux-fsdevel@vger.kernel.org, linux-kernel@vger.kernel.org, llvm@lists.linux.dev, linux-hardening@vger.kernel.org Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: quoted-printable On Fri, May 10, 2024 at 8:15=E2=80=AFAM Jan Kara wrote: > > On Thu 09-05-24 21:34:58, Justin Stitt wrote: > > --- > > fs/read_write.c | 2 +- > > 1 file changed, 1 insertion(+), 1 deletion(-) > > > > diff --git a/fs/read_write.c b/fs/read_write.c > > index d4c036e82b6c..10c3eaa5ef55 100644 > > --- a/fs/read_write.c > > +++ b/fs/read_write.c > > @@ -88,7 +88,7 @@ generic_file_llseek_size(struct file *file, loff_t of= fset, int whence, > > { > > switch (whence) { > > case SEEK_END: > > - offset +=3D eof; > > + offset =3D min_t(loff_t, offset, maxsize - eof) + eof; > > Well, but by this you change the behavior of seek(2) for huge offsets. > Previously we'd return -EINVAL (from following vfs_setpos()), now we set > position to maxsize. I don't think that is desirable? RIght, we shouldn't change the current behavior. This patch needs rethinkin= g. > > Also the addition in SEEK_CUR could overflow in the same way AFAICT so we > could treat that in one patch so that the whole function is fixed at once= ? Yep let's include that one as well. However, I'm going to hold off on sending a new version until the discussion about how to handle overflow comes to a conclusion; as suggested by Greg [1]. I made too many assumptions about how folks want overflow to be handled. In the case of this patch, a simple check_add_overflow() should be okay and match the behavior, but let's wait and see. > > Honza > -- > Jan Kara > SUSE Labs, CR [1]: https://lore.kernel.org/all/2024051039-bankable-liking-e836@gregkh/ Thanks Justin