From patchwork Tue Jan 9 11:20:22 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: David Howells X-Patchwork-Id: 186328 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a05:7300:2411:b0:101:2151:f287 with SMTP id m17csp41431dyi; Tue, 9 Jan 2024 03:24:17 -0800 (PST) X-Google-Smtp-Source: AGHT+IGcv0pZ+8gSf4Tjnc3wgu7CMlnpAMeWShNeQGdMBmHenibDARH5fFUfpQKV38nDxu+x33P8 X-Received: by 2002:a17:902:684c:b0:1d3:e8b1:c2cf with SMTP id f12-20020a170902684c00b001d3e8b1c2cfmr2648591pln.116.1704799457014; Tue, 09 Jan 2024 03:24:17 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1704799456; cv=none; d=google.com; s=arc-20160816; b=etzunHke+U2X2We6alHm1AfnQ0F1sx/fqvrdn5ZlOcwz6ys0OdHjR842ucHXMBislD LtVSINiqKZrgmax7p3K3g/AKpDym4tQL9qk8eb/XjAB8wxgkJZwMfsk3J5pnUaXBEjGC LiinzMxPtWXp5L0JxjuAKQs1PAc9euhQIhr90Co3+eZqUQRqQqNsG8toypydMA5vcGRA brDsGUH2k+7y/HSizzq9AbrqPqvqxdmFSKSPs2R8EDtpKWYFvP4pSwY/omj6Y8iCUvmE RrD0+Qv1N2E8Q9k7ybNCAE8vda9iSM//VVNsjsCBXeNKZYq0532pQzrmQnYS72qy084H jFzw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=content-transfer-encoding:mime-version:list-unsubscribe :list-subscribe:list-id:precedence:references:in-reply-to:message-id :date:subject:cc:to:from:dkim-signature; bh=Z0xNWJpdRPanEuZiAQenKRA87zeZrifRwyW7XU8kxYA=; fh=rqpPS96O0g2fQmn7KhcIs+VloH2LssYDKKWvCBPtAeo=; b=MgaCdS/mhGreiEX9jkRhoWR89TLKixadcfMBWRgqvVNPeRniXRTZegW0vn4XA6Q71D DIwVc2TqfmSxmOu8hA97a34lbMNtIEnmt/sQZMxxk8uvtua4rJTa+/4TxcuWApPcXOA3 SYIuS0BoxZo/n7+bo/Mvct4cAlq/H46l0LJM+hLgeDuba6hOpOvS+rAu4m0HXYUgzqNB 6sjabTolVbQvQedkIaXG/4yIWUXCJmwTbZTuviACK94lG4xCJiUx8C1r3/ejQrRSu9S8 uUEnAEPGrypZgc12CoNxwEDWjViQaWyjE5Q79Ywe+ZvxqtF5RPhm4YHhx0e894LW2qoH WdKA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@redhat.com header.s=mimecast20190719 header.b=aenuw9aH; spf=pass (google.com: domain of linux-kernel+bounces-20761-ouuuleilei=gmail.com@vger.kernel.org designates 2604:1380:45e3:2400::1 as permitted sender) smtp.mailfrom="linux-kernel+bounces-20761-ouuuleilei=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=redhat.com Received: from sv.mirrors.kernel.org (sv.mirrors.kernel.org. [2604:1380:45e3:2400::1]) by mx.google.com with ESMTPS id x3-20020a1709027c0300b001d30ee06c66si1333035pll.22.2024.01.09.03.24.16 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 09 Jan 2024 03:24:16 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel+bounces-20761-ouuuleilei=gmail.com@vger.kernel.org designates 2604:1380:45e3:2400::1 as permitted sender) client-ip=2604:1380:45e3:2400::1; Authentication-Results: mx.google.com; dkim=pass header.i=@redhat.com header.s=mimecast20190719 header.b=aenuw9aH; spf=pass (google.com: domain of linux-kernel+bounces-20761-ouuuleilei=gmail.com@vger.kernel.org designates 2604:1380:45e3:2400::1 as permitted sender) smtp.mailfrom="linux-kernel+bounces-20761-ouuuleilei=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=redhat.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 sv.mirrors.kernel.org (Postfix) with ESMTPS id C6F882872CD for ; Tue, 9 Jan 2024 11:24:16 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 70E833A1B1; Tue, 9 Jan 2024 11:21:12 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=redhat.com header.i=@redhat.com header.b="aenuw9aH" Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.129.124]) (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 5A9E539AF5 for ; Tue, 9 Jan 2024 11:21:08 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=redhat.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=redhat.com DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1704799267; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=Z0xNWJpdRPanEuZiAQenKRA87zeZrifRwyW7XU8kxYA=; b=aenuw9aHRQL27VHKd8TZIUSzbuPzLvSAP9TxWUqXC8oonOoFJfjVmemuzi47tyWRK+FHh4 Aez8xm0OjtWMefvNnRfEsTLtKLFWIXCz6hEHPNVAX8dwZgsfpW6XKfYiCuzF9zalX3UEen nJV7R85qms2x4mFwd1ttema+GEAaoh4= Received: from mimecast-mx02.redhat.com (mx-ext.redhat.com [66.187.233.73]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-581-EPXp23K5MHONs8COTGeLaw-1; Tue, 09 Jan 2024 06:20:58 -0500 X-MC-Unique: EPXp23K5MHONs8COTGeLaw-1 Received: from smtp.corp.redhat.com (int-mx03.intmail.prod.int.rdu2.redhat.com [10.11.54.3]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits) server-digest SHA256) (No client certificate requested) by mimecast-mx02.redhat.com (Postfix) with ESMTPS id 357C31C06505; Tue, 9 Jan 2024 11:20:57 +0000 (UTC) Received: from warthog.procyon.org.com (unknown [10.42.28.67]) by smtp.corp.redhat.com (Postfix) with ESMTP id C71151121306; Tue, 9 Jan 2024 11:20:53 +0000 (UTC) From: David Howells To: Christian Brauner , Jeff Layton , Gao Xiang , Dominique Martinet Cc: David Howells , Steve French , Matthew Wilcox , Marc Dionne , Paulo Alcantara , Shyam Prasad N , Tom Talpey , Eric Van Hensbergen , Ilya Dryomov , linux-cachefs@redhat.com, linux-afs@lists.infradead.org, linux-cifs@vger.kernel.org, linux-nfs@vger.kernel.org, ceph-devel@vger.kernel.org, v9fs@lists.linux.dev, linux-erofs@lists.ozlabs.org, linux-fsdevel@vger.kernel.org, linux-mm@kvack.org, netdev@vger.kernel.org, linux-kernel@vger.kernel.org, Simon Horman , kernel test robot , Yiqun Leng , Jia Zhu Subject: [PATCH 5/6] cachefiles: Fix signed/unsigned mixup Date: Tue, 9 Jan 2024 11:20:22 +0000 Message-ID: <20240109112029.1572463-6-dhowells@redhat.com> In-Reply-To: <20240109112029.1572463-1-dhowells@redhat.com> References: <20240109112029.1572463-1-dhowells@redhat.com> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 X-Scanned-By: MIMEDefang 3.4.1 on 10.11.54.3 X-getmail-retrieved-from-mailbox: INBOX X-GMAIL-THRID: 1787611795303922616 X-GMAIL-MSGID: 1787611795303922616 In __cachefiles_prepare_write(), the start and pos variables were made unsigned 64-bit so that the casts in the checking could be got rid of - which should be fine since absolute file offsets can't be negative, except that an error code may be obtained from vfs_llseek(), which *would* be negative. This breaks the error check. Fix this for now by reverting pos and start to be signed and putting back the casts. Unfortunately, the error value checks cannot be replaced with IS_ERR_VALUE() as long might be 32-bits. Fixes: 7097c96411d2 ("cachefiles: Fix __cachefiles_prepare_write()") Reported-by: Simon Horman Reported-by: kernel test robot Closes: https://lore.kernel.org/oe-kbuild-all/202401071152.DbKqMQMu-lkp@intel.com/ Signed-off-by: David Howells Reviewed-by: Simon Horman cc: Gao Xiang cc: Yiqun Leng cc: Jia Zhu cc: Jeff Layton cc: linux-cachefs@redhat.com cc: linux-erofs@lists.ozlabs.org cc: linux-fsdevel@vger.kernel.org cc: linux-mm@kvack.org Reviewed-by: Gao Xiang Tested-by: Jia Zhu --- fs/cachefiles/io.c | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/fs/cachefiles/io.c b/fs/cachefiles/io.c index 3eec26967437..9a2cb2868e90 100644 --- a/fs/cachefiles/io.c +++ b/fs/cachefiles/io.c @@ -522,7 +522,7 @@ int __cachefiles_prepare_write(struct cachefiles_object *object, bool no_space_allocated_yet) { struct cachefiles_cache *cache = object->volume->cache; - unsigned long long start = *_start, pos; + loff_t start = *_start, pos; size_t len = *_len; int ret; @@ -556,7 +556,7 @@ int __cachefiles_prepare_write(struct cachefiles_object *object, cachefiles_trace_seek_error); return pos; } - if (pos >= start + *_len) + if ((u64)pos >= (u64)start + *_len) goto check_space; /* Unallocated region */ /* We have a block that's at least partially filled - if we're low on @@ -575,7 +575,7 @@ int __cachefiles_prepare_write(struct cachefiles_object *object, cachefiles_trace_seek_error); return pos; } - if (pos >= start + *_len) + if ((u64)pos >= (u64)start + *_len) return 0; /* Fully allocated */ /* Partially allocated, but insufficient space: cull. */