Received: by 2002:a05:6a10:22f:0:0:0:0 with SMTP id 15csp630504pxk; Thu, 17 Sep 2020 11:48:10 -0700 (PDT) X-Google-Smtp-Source: ABdhPJwEg5OdOP72xubH3zGUW4OyTSvQIHC0xso0wOuAeUhQ0cbEfYPxLogsgABbEkhwfdBOq/yr X-Received: by 2002:a17:906:4902:: with SMTP id b2mr31531655ejq.208.1600368490741; Thu, 17 Sep 2020 11:48:10 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1600368490; cv=none; d=google.com; s=arc-20160816; b=ZVxPivhsL/a36nFW7yg+V8ZzSaBKkSQm7A1pHP1q/xC6uKLmd3k52A8Va9bPDDL+0D uxuS6tvEyjqFWEXq/pE9ZwwTvm6JCauKrFQ/Wlf0bL4NAI47wR5Vt2DGWWu4QuYKi07B bwAhav1ZzbKwN7QH6SmBNH1a/AU1NE7rdU0FTJu8tS4e6pAFof18liVEWWDncjKdu0Zd l5qzhLTDkgml4IcA1nW9v7B0lWTY9M7kO8ign64JmPHQZyKQv7CmoD5utPQlIz3Siugn CUz8HjPS6Csk5uFF3NVuNKTd5vqlH5zsHJF6xtZrYz8Sof3tdp3x7yGFa8l3D6iApX+B j1HA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:in-reply-to:content-disposition:mime-version :references:message-id:subject:cc:to:from:date; bh=E/kLYs2IAyG+mk5onRPFRZlofhc5DPj2cwzyh7K1SnA=; b=TjLjBDw9PYdd51wsC4marhVoZ0O6RtH62vGdnK99qS2bqQjq0PXLEPk3FdJzAQmr7G lBv0jC4y0iOnexhcjmwyfBdDbQshlEPq8LN5yCvScIM7uApxhfgumlSES7TV7BByJJqS xdJN5p0EdebBmwYxNR34RkPXaxwwEEmijVIGcdMxvI2KLQRg8p5gZemPHrDGhZY5krc8 5FcZ+r6uwxs+McvKWIfGibyo9p5ENbLpvavtzTfIvmQxnOOMmTUuIInwYPyscYMUVUdg 403iJgXRl0a8F51w2eOhbeDFJHfZksg3gqXMae9/aFYHQxN0F9RC+YNbZaqjgj0Ra/yw x6kw== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id u6si629286ejf.115.2020.09.17.11.47.46; Thu, 17 Sep 2020 11:48:10 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) client-ip=23.128.96.18; Authentication-Results: mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1726405AbgIQSqi (ORCPT + 99 others); Thu, 17 Sep 2020 14:46:38 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:42622 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726496AbgIQSqF (ORCPT ); Thu, 17 Sep 2020 14:46:05 -0400 Received: from ZenIV.linux.org.uk (zeniv.linux.org.uk [IPv6:2002:c35c:fd02::1]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id A8F05C06174A; Thu, 17 Sep 2020 11:46:04 -0700 (PDT) Received: from viro by ZenIV.linux.org.uk with local (Exim 4.92.3 #3 (Red Hat Linux)) id 1kIyus-000Z2Y-8K; Thu, 17 Sep 2020 18:45:58 +0000 Date: Thu, 17 Sep 2020 19:45:58 +0100 From: Al Viro To: Qian Cai Cc: torvalds@linux-foundation.org, vgoyal@redhat.com, miklos@szeredi.hu, linux-fsdevel@vger.kernel.org, linux-kernel@vger.kernel.org Subject: Re: slab-out-of-bounds in iov_iter_revert() Message-ID: <20200917184558.GX3421308@ZenIV.linux.org.uk> References: <20200911215903.GA16973@lca.pw> <20200911235511.GB3421308@ZenIV.linux.org.uk> <87ded87d232d9cf87c9c64495bf9190be0e0b6e8.camel@redhat.com> <20200917020440.GQ3421308@ZenIV.linux.org.uk> <20200917021439.GA31009@ZenIV.linux.org.uk> <20200917164432.GU3421308@ZenIV.linux.org.uk> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Thu, Sep 17, 2020 at 01:42:44PM -0400, Qian Cai wrote: > > > > How much IO does it take to trigger that on your reproducer? > > That is something I don't know for sure because it is always reproducible by > running the trinity fuzzer for a few seconds (32 threads). I did another run > below (still with your patch applied) and then tried to capture some logs here: > > http://people.redhat.com/qcai/iov_iter_revert/ FWIW, there were several bugs in that patch: * 'shortened' possibly left uninitialized * possible error returns with reexpand not done Could you try this instead? Signed-off-by: Al Viro --- diff --git a/fs/fuse/file.c b/fs/fuse/file.c index 6611ef3269a8..43c165e796da 100644 --- a/fs/fuse/file.c +++ b/fs/fuse/file.c @@ -3091,11 +3091,10 @@ fuse_direct_IO(struct kiocb *iocb, struct iov_iter *iter) ssize_t ret = 0; struct file *file = iocb->ki_filp; struct fuse_file *ff = file->private_data; - bool async_dio = ff->fc->async_dio; loff_t pos = 0; struct inode *inode; loff_t i_size; - size_t count = iov_iter_count(iter); + size_t count = iov_iter_count(iter), shortened = 0; loff_t offset = iocb->ki_pos; struct fuse_io_priv *io; @@ -3103,17 +3102,9 @@ fuse_direct_IO(struct kiocb *iocb, struct iov_iter *iter) inode = file->f_mapping->host; i_size = i_size_read(inode); - if ((iov_iter_rw(iter) == READ) && (offset > i_size)) + if ((iov_iter_rw(iter) == READ) && (offset >= i_size)) return 0; - /* optimization for short read */ - if (async_dio && iov_iter_rw(iter) != WRITE && offset + count > i_size) { - if (offset >= i_size) - return 0; - iov_iter_truncate(iter, fuse_round_up(ff->fc, i_size - offset)); - count = iov_iter_count(iter); - } - io = kmalloc(sizeof(struct fuse_io_priv), GFP_KERNEL); if (!io) return -ENOMEM; @@ -3129,15 +3120,22 @@ fuse_direct_IO(struct kiocb *iocb, struct iov_iter *iter) * By default, we want to optimize all I/Os with async request * submission to the client filesystem if supported. */ - io->async = async_dio; + io->async = ff->fc->async_dio; io->iocb = iocb; io->blocking = is_sync_kiocb(iocb); + /* optimization for short read */ + if (io->async && !io->write && offset + count > i_size) { + iov_iter_truncate(iter, fuse_round_up(ff->fc, i_size - offset)); + shortened = count - iov_iter_count(iter); + count -= shortened; + } + /* * We cannot asynchronously extend the size of a file. * In such case the aio will behave exactly like sync io. */ - if ((offset + count > i_size) && iov_iter_rw(iter) == WRITE) + if ((offset + count > i_size) && io->write) io->blocking = true; if (io->async && io->blocking) { @@ -3155,6 +3153,7 @@ fuse_direct_IO(struct kiocb *iocb, struct iov_iter *iter) } else { ret = __fuse_direct_read(io, iter, &pos); } + iov_iter_reexpand(iter, iov_iter_count(iter) + shortened); if (io->async) { bool blocking = io->blocking;