From patchwork Fri Apr 15 10:51:28 2016 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Ming Lei X-Patchwork-Id: 8848531 Return-Path: X-Original-To: patchwork-linux-block@patchwork.kernel.org Delivered-To: patchwork-parsemail@patchwork2.web.kernel.org Received: from mail.kernel.org (mail.kernel.org [198.145.29.136]) by patchwork2.web.kernel.org (Postfix) with ESMTP id CA127C0553 for ; Fri, 15 Apr 2016 10:52:06 +0000 (UTC) Received: from mail.kernel.org (localhost [127.0.0.1]) by mail.kernel.org (Postfix) with ESMTP id F2E2F20373 for ; Fri, 15 Apr 2016 10:52:05 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id 2548320295 for ; Fri, 15 Apr 2016 10:52:05 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1753086AbcDOKvm (ORCPT ); Fri, 15 Apr 2016 06:51:42 -0400 Received: from mail-oi0-f67.google.com ([209.85.218.67]:33798 "EHLO mail-oi0-f67.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1752181AbcDOKvk (ORCPT ); Fri, 15 Apr 2016 06:51:40 -0400 Received: by mail-oi0-f67.google.com with SMTP id q133so13273494oib.1; Fri, 15 Apr 2016 03:51:40 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20130820; h=x-gm-message-state:from:to:cc:subject:date:message-id; bh=xwZ5TvHhksgJwchMm3269xuEogCCfOYobcVM24B5zzM=; b=Ljdet2opEoFlq9D8No5U0Nj8sZEP5Tx41cFDHUj8CHFajnBG+GqRWjIUKDj7fwFxj/ nbyPf/T0a4ODVafnWUhKtzjaTef9Zj+5scXrGa9vgCM1qnb6ynNRUPUfh2Nfo5pRsOQB a/Lzyy8zISaIlWc11eu/BbffOQMbic8oA2Nq5yeQwIy+fJJ4cFbgJQNiGLhZoYUKVW0+ lA7cgJE7Q6j7vDUn+kt+ZeG0Rj7bXuaGGGukGv2p5KTtDvL/F82dt6vkZoxdX5PQ68nx Lj3tOvBd7bmkfOsXyr7oMTxWYiWweLGcNYkMoXE30SZmn100ps3UQXeAbBcCX5gnkAJE +W4g== X-Gm-Message-State: AOPr4FV5qnCtpGDfcmBU8hiU6aOavpkz9CAwg95fhEK/b7sdgnFStDW3cKkDFKR3aYAjbg== X-Received: by 10.157.13.45 with SMTP id 42mr1254984oti.33.1460717499898; Fri, 15 Apr 2016 03:51:39 -0700 (PDT) Received: from localhost ([12.228.154.70]) by smtp.gmail.com with ESMTPSA id cc15sm15009132obb.2.2016.04.15.03.51.39 (version=TLS1_2 cipher=AES128-SHA bits=128/128); Fri, 15 Apr 2016 03:51:39 -0700 (PDT) From: Ming Lei To: Jens Axboe , linux-kernel@vger.kernel.org Cc: linux-block@vger.kernel.org, Christoph Hellwig , Ming Lei , Keith Busch , Al Viro , stable@vger.kernel.org (4.5) Subject: [PATCH] block: loop: fix filesystem corruption in case of aio/dio Date: Fri, 15 Apr 2016 18:51:28 +0800 Message-Id: <1460717488-19796-1-git-send-email-ming.lei@canonical.com> X-Mailer: git-send-email 1.9.1 Sender: linux-block-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-block@vger.kernel.org X-Spam-Status: No, score=-7.9 required=5.0 tests=BAYES_00, RCVD_IN_DNSWL_HI, RP_MATCHES_RCVD, UNPARSEABLE_RELAY autolearn=ham version=3.3.1 X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on mail.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP Starting from commit e36f620428(block: split bios to max possible length), block core starts to split bio in the middle of bvec. Unfortunately loop dio/aio doesn't consider this situation, and always treat 'iter.iov_offset' as zero. Then filesystem corruption is observed. This patch figures out the offset of the base bvevc via 'bio->bi_iter.bi_bvec_done' and fixes the issue by passing the offset to iov iterator. Fixes: e36f6204288088f (block: split bios to max possible length) Cc: Keith Busch Cc: Al Viro Cc: stable@vger.kernel.org (4.5) Signed-off-by: Ming Lei --- drivers/block/loop.c | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/drivers/block/loop.c b/drivers/block/loop.c index 7e5e27a..1fa8cc2 100644 --- a/drivers/block/loop.c +++ b/drivers/block/loop.c @@ -488,6 +488,12 @@ static int lo_rw_aio(struct loop_device *lo, struct loop_cmd *cmd, bvec = __bvec_iter_bvec(bio->bi_io_vec, bio->bi_iter); iov_iter_bvec(&iter, ITER_BVEC | rw, bvec, bio_segments(bio), blk_rq_bytes(cmd->rq)); + /* + * This bio may be started from the middle of the 'bvec' + * because of bio splitting, so offset from the bvec must + * be passed to iov iterator + */ + iter.iov_offset = bio->bi_iter.bi_bvec_done; cmd->iocb.ki_pos = pos; cmd->iocb.ki_filp = file;