Received: by 2002:a05:6a10:22f:0:0:0:0 with SMTP id 15csp555159pxk; Thu, 17 Sep 2020 09:49:35 -0700 (PDT) X-Google-Smtp-Source: ABdhPJw6Rbs8kflZG9gCkCvQ/5MSi17ruQbt5anlY+x9nJER7zX0uZHdm5ZBP65RMXKU2sLE3I8e X-Received: by 2002:a17:906:a00c:: with SMTP id p12mr30756798ejy.10.1600361375343; Thu, 17 Sep 2020 09:49:35 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1600361375; cv=none; d=google.com; s=arc-20160816; b=xb1STWn91LTAPt2lv8Hiflro3SV3lj6IeIZSC7EcApwv2gXdl6HN1QLmKHNoAMlVoS g9AZr4EFvVIW1sJpeF4kEnZXr8GLPM7U9nzNMy9O0rkLQLSxJz8SGvbtJAQFEC4caFHh 7UhFJaSH9yG4QGt6HDQG0AljlaQZecKYnbTgtJZJt+Sb9eBYp6vgcCli5SEU9eDLrNyV //LinPHnimH/lVA/vdJadNkRGh/0YOqTDLsUW6pMgybX/YF5+uPChCwseJQCID+zm/Nw 8oGI8NvNL5FPgQvOCmaro/+YoOHUkxXL5KLqFCC/xLqJfLMC8KKLnjIJgSXNzrIkyi59 8Kqw== 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=i3rYWT4/H7TMsApGY2XJTDcoNsZ1Gcnvilz2IQK0Ae4=; b=N0d/fmtEze/4Fyv+z/r4ZrXZvfeI37a1a//TgbVwQOmhL63Mha9Qyg+7sCFmPtcy8T opiGp230B04Wgjuh4QtOXctG3lXQ+HjviIsHvnc3QGEt4eDh19JYcpRmMCuO9rqHLo1y W7TEz9q9+tv5dN7xhrn6oZiayU45w1sg9NQeRolDCSgOVkh4d+P8ydAMgoCkYQQEEpxy Einfn2pcEoLC0W+qpTX8Vxk6uuOvjCbjc/EhVAm8ZnVtN9qd2XeAFpw61zNmvFWLvcxv sHew2pz4ar1RqNRlh8o0stSJo5ED/IP2Zyjknsl1g/caDqk5F1fh52KwuBzfBmU2miUs oeCQ== 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 z9si338101ejj.34.2020.09.17.09.49.11; Thu, 17 Sep 2020 09:49:35 -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 S1728606AbgIQQqJ (ORCPT + 99 others); Thu, 17 Sep 2020 12:46:09 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:51974 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1728602AbgIQQoo (ORCPT ); Thu, 17 Sep 2020 12:44:44 -0400 Received: from ZenIV.linux.org.uk (zeniv.linux.org.uk [IPv6:2002:c35c:fd02::1]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 30A69C06174A; Thu, 17 Sep 2020 09:44:43 -0700 (PDT) Received: from viro by ZenIV.linux.org.uk with local (Exim 4.92.3 #3 (Red Hat Linux)) id 1kIx1M-000VUC-TD; Thu, 17 Sep 2020 16:44:33 +0000 Date: Thu, 17 Sep 2020 17:44:32 +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: <20200917164432.GU3421308@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> 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 10:10:27AM -0400, Qian Cai wrote: > [ 81.942909] generic_file_read_iter+0x23b/0x4b0 > [ 81.942918] fuse_file_read_iter+0x280/0x4e0 [fuse] > [ 81.942931] ? fuse_direct_IO+0xd30/0xd30 [fuse] > [ 81.942949] ? _raw_spin_lock_irqsave+0x80/0xe0 > [ 81.942957] ? timerqueue_add+0x15e/0x280 > [ 81.942960] ? _raw_spin_lock_irqsave+0x80/0xe0 > [ 81.942966] new_sync_read+0x3b7/0x620 > [ 81.942968] ? __ia32_sys_llseek+0x2e0/0x2e0 Interesting... Basic logics in there: ->direct_IO() might consume more (on iov_iter_get_pages() and friends) than it actually reads. We want to revert the excess. Suppose by the time we call ->direct_IO() we had N bytes already consumed and C bytes left. We expect that after ->direct_IO() returns K, we have C' bytes left, N + (C - C') consumed and N + K out of those actually read. So we revert by C - K - C'. You end up trying to revert beyond the beginning. Use of iov_iter_truncate() is problematic here, since it changes the amount of data left without having consumed anything. Basically, it changes the position of end, and the logics in the caller expects that to remain unchanged. iov_iter_reexpand() use should restore the position of end. How much IO does it take to trigger that on your reproducer?