Received: by 2002:a05:6a10:17d3:0:0:0:0 with SMTP id hz19csp2670444pxb; Mon, 19 Apr 2021 10:52:06 -0700 (PDT) X-Google-Smtp-Source: ABdhPJw38DEbnnFd7DcuOip/U7iJpA5cjOw5tiImV9aIfmL2m3cOv1mv2nU+a4r+0RAsNgMnciqA X-Received: by 2002:aa7:ca04:: with SMTP id y4mr26755893eds.72.1618854726299; Mon, 19 Apr 2021 10:52:06 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1618854726; cv=none; d=google.com; s=arc-20160816; b=lgD6NJrxnBCFbXrVCwRDOjtsFoIx78XEjRUMGIL9QDdXoWvXVSvNo3X+IYvgTGmz08 GS9zA2tRP+S+6rvrH+B4MVmvyiMk4zRkUkRso2q3vVuOBaeI69VC5pjxbktqkSIp21UI 9T7ZkDg41gWJy34V6o0/G4oJgJIGK+kEdvjyo8GTRq74EyDD/cCA10+C5vT6+uhEDgA1 s6UsJy+3GjCIqNI6wVTTrrpn3LTJC+JD8OVMy7itTsDJ9YJ28v9hAINdOLnRj+GV+EoI XZpbkA5m0D/pxljUCFk+NXYF+hB0LKhuHFFCSWzcA+DA3QcCyEpMAvjV/hm8YOvK94xq 4Czg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :user-agent:references:in-reply-to:message-id:date:subject:cc:to :from:dkim-signature; bh=4pfm1M32Ov6llzauQTc+Usf54yE0m+Gp8f5hXsGi/m8=; b=bUuUo2/mM8gQOL/mGkeBwG1fZY8I7fIjG4tXW468wYGnXAJfMeazm8ftl7YqZyMqyK spdkpvYXp5FZcd9iStxNFAeo+1fuXgTudiTYZVpaBDRRORHDlNGd/FJ4TJDfHssP24vi 6Ez4qfS/2pG7MR7eOZc4QuBl8e6bRLzdYyZOzetQaS/6W1DflYE+AOPDpaH1076LQ5Vl ivvHCyBYhuHWxhvR27nBZU7wEwzLnoGbww0AXhBee5ODUxiR4RhlIfyBnqp5P7weAFIw MYV5kcZMcRfzwmkX7pLyWC943wBP3kuF3R951xnGTDCvaH/+GzWwHeG7RlVPdiFuZKMR qTOg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b=1kq4ssc8; 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; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linuxfoundation.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id h18si13180452eds.422.2021.04.19.10.51.41; Mon, 19 Apr 2021 10:52:06 -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; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b=1kq4ssc8; 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; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linuxfoundation.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S240901AbhDSNZh (ORCPT + 99 others); Mon, 19 Apr 2021 09:25:37 -0400 Received: from mail.kernel.org ([198.145.29.99]:56252 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S240999AbhDSNTm (ORCPT ); Mon, 19 Apr 2021 09:19:42 -0400 Received: by mail.kernel.org (Postfix) with ESMTPSA id C0A65613ED; Mon, 19 Apr 2021 13:15:18 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linuxfoundation.org; s=korg; t=1618838119; bh=/0EFt+oC5nkaqB0I+I0+gOt65NBd30fm8mGLACfO6o0=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=1kq4ssc8Ii6a+h1sRAGPF2VK5JKemdjWLcCNgYYnHcWgXfLKGzQIbFeipfLcgl9BI jitugjr6sM+jVpVVslQKEPoCbYH+BrrubpV0ZX75TySsvUiPnPDNnUHcjGTzDvvp1Q fIod+YVtwv8VJgDAf5pnn5ntgxcG/zc+BzuEpskE= From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , stable@vger.kernel.org, Jaegeuk Kim , Mike Snitzer Subject: [PATCH 5.10 050/103] dm verity fec: fix misaligned RS roots IO Date: Mon, 19 Apr 2021 15:06:01 +0200 Message-Id: <20210419130529.533533006@linuxfoundation.org> X-Mailer: git-send-email 2.31.1 In-Reply-To: <20210419130527.791982064@linuxfoundation.org> References: <20210419130527.791982064@linuxfoundation.org> User-Agent: quilt/0.66 MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org From: Jaegeuk Kim commit 8ca7cab82bda4eb0b8064befeeeaa38106cac637 upstream. commit df7b59ba9245 ("dm verity: fix FEC for RS roots unaligned to block size") introduced the possibility for misaligned roots IO relative to the underlying device's logical block size. E.g. Android's default RS roots=2 results in dm_bufio->block_size=1024, which causes the following EIO if the logical block size of the device is 4096, given v->data_dev_block_bits=12: E sd 0 : 0:0:0: [sda] tag#30 request not aligned to the logical block size E blk_update_request: I/O error, dev sda, sector 10368424 op 0x0:(READ) flags 0x0 phys_seg 1 prio class 0 E device-mapper: verity-fec: 254:8: FEC 9244672: parity read failed (block 18056): -5 Fix this by onlu using f->roots for dm_bufio blocksize IFF it is aligned to v->data_dev_block_bits. Fixes: df7b59ba9245 ("dm verity: fix FEC for RS roots unaligned to block size") Cc: stable@vger.kernel.org Signed-off-by: Jaegeuk Kim Signed-off-by: Mike Snitzer Signed-off-by: Greg Kroah-Hartman --- drivers/md/dm-verity-fec.c | 11 ++++++++--- drivers/md/dm-verity-fec.h | 1 + 2 files changed, 9 insertions(+), 3 deletions(-) --- a/drivers/md/dm-verity-fec.c +++ b/drivers/md/dm-verity-fec.c @@ -65,7 +65,7 @@ static u8 *fec_read_parity(struct dm_ver u8 *res; position = (index + rsb) * v->fec->roots; - block = div64_u64_rem(position, v->fec->roots << SECTOR_SHIFT, &rem); + block = div64_u64_rem(position, v->fec->io_size, &rem); *offset = (unsigned)rem; res = dm_bufio_read(v->fec->bufio, block, buf); @@ -154,7 +154,7 @@ static int fec_decode_bufs(struct dm_ver /* read the next block when we run out of parity bytes */ offset += v->fec->roots; - if (offset >= v->fec->roots << SECTOR_SHIFT) { + if (offset >= v->fec->io_size) { dm_bufio_release(buf); par = fec_read_parity(v, rsb, block_offset, &offset, &buf); @@ -742,8 +742,13 @@ int verity_fec_ctr(struct dm_verity *v) return -E2BIG; } + if ((f->roots << SECTOR_SHIFT) & ((1 << v->data_dev_block_bits) - 1)) + f->io_size = 1 << v->data_dev_block_bits; + else + f->io_size = v->fec->roots << SECTOR_SHIFT; + f->bufio = dm_bufio_client_create(f->dev->bdev, - f->roots << SECTOR_SHIFT, + f->io_size, 1, 0, NULL, NULL); if (IS_ERR(f->bufio)) { ti->error = "Cannot initialize FEC bufio client"; --- a/drivers/md/dm-verity-fec.h +++ b/drivers/md/dm-verity-fec.h @@ -36,6 +36,7 @@ struct dm_verity_fec { struct dm_dev *dev; /* parity data device */ struct dm_bufio_client *data_bufio; /* for data dev access */ struct dm_bufio_client *bufio; /* for parity data access */ + size_t io_size; /* IO size for roots */ sector_t start; /* parity data start in blocks */ sector_t blocks; /* number of blocks covered */ sector_t rounds; /* number of interleaving rounds */