From patchwork Wed Aug 19 09:07:32 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: AKASHI Takahiro X-Patchwork-Id: 1347624 X-Patchwork-Delegate: trini@ti.com Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Authentication-Results: ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=lists.denx.de (client-ip=85.214.62.61; helo=phobos.denx.de; envelope-from=u-boot-bounces@lists.denx.de; receiver=) Authentication-Results: ozlabs.org; dmarc=pass (p=none dis=none) header.from=linaro.org Authentication-Results: ozlabs.org; dkim=pass (2048-bit key; unprotected) header.d=linaro.org header.i=@linaro.org header.a=rsa-sha256 header.s=google header.b=wLbwTbWs; dkim-atps=neutral Received: from phobos.denx.de (phobos.denx.de [85.214.62.61]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits) server-digest SHA256) (No client certificate requested) by ozlabs.org (Postfix) with ESMTPS id 4BWhlg15Gfz9sPf for ; Wed, 19 Aug 2020 19:08:28 +1000 (AEST) Received: from h2850616.stratoserver.net (localhost [IPv6:::1]) by phobos.denx.de (Postfix) with ESMTP id 768318222C; Wed, 19 Aug 2020 11:08:24 +0200 (CEST) Authentication-Results: phobos.denx.de; dmarc=pass (p=none dis=none) header.from=linaro.org Authentication-Results: phobos.denx.de; spf=pass smtp.mailfrom=u-boot-bounces@lists.denx.de Authentication-Results: phobos.denx.de; dkim=pass (2048-bit key; unprotected) header.d=linaro.org header.i=@linaro.org header.b="wLbwTbWs"; dkim-atps=neutral Received: by phobos.denx.de (Postfix, from userid 109) id 780C182256; Wed, 19 Aug 2020 11:08:22 +0200 (CEST) X-Spam-Checker-Version: SpamAssassin 3.4.2 (2018-09-13) on phobos.denx.de X-Spam-Level: X-Spam-Status: No, score=-2.0 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,SPF_HELO_NONE,URIBL_BLOCKED autolearn=ham autolearn_force=no version=3.4.2 Received: from mail-pj1-x1041.google.com (mail-pj1-x1041.google.com [IPv6:2607:f8b0:4864:20::1041]) (using TLSv1.3 with cipher TLS_AES_128_GCM_SHA256 (128/128 bits)) (No client certificate requested) by phobos.denx.de (Postfix) with ESMTPS id 7ECE982209 for ; Wed, 19 Aug 2020 11:08:19 +0200 (CEST) Authentication-Results: phobos.denx.de; dmarc=pass (p=none dis=none) header.from=linaro.org Authentication-Results: phobos.denx.de; spf=pass smtp.mailfrom=takahiro.akashi@linaro.org Received: by mail-pj1-x1041.google.com with SMTP id ha11so818908pjb.1 for ; Wed, 19 Aug 2020 02:08:19 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; h=from:to:cc:subject:date:message-id:mime-version :content-transfer-encoding; bh=2S3Y3+3U7JbeOfOYmdGRKCEy1l9JlHbwzf6eC7YVQKI=; b=wLbwTbWs3Vg8TOv/INYyvY0ryZm+eS7Ox6YHeU3gdYdZBb4ZQxL6cEFRavL/toI7+M 4L+mhYU+6VAo/XZs5qud4eru8mrEWjJHvigULGqV1CEJAOg4x3eyRGZ/qoJm60KPXDTM gJmlEpddEp1+hduDZopsZnxPqvm5gpWMMqlkMp1IsZdDzi2WJ5m1qcmUXXstISdq4AeU fnXLwcfpkXR3uVBRskLYMNz/9J8Tyc6XbXU3JHdcw9CVWm12HU7d/HnU5qRlm6xAMLo7 VhM/6ZA/glZfoii6i62HMVkNqL7RnKa+aneOpUFbhLMvfkCj/ppU3S0jUKDJX2pTLItQ 1ODg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:mime-version :content-transfer-encoding; bh=2S3Y3+3U7JbeOfOYmdGRKCEy1l9JlHbwzf6eC7YVQKI=; b=rbEV+RBbUW86B193KEazdACq/Rn7+DuM/wuDkEO+1zRMOldTwSANyYVUIR7+VC5PIA vvVbmwLgeWBWShpbjGc6XbaTAbf5pPTK0CCB0IAkzgxhhh9/N+8ZFN0EjaNMJsHceFCx fe9/pQqdrye43/FbSoy9+l0ZwqFqgTvL8QRdZhrsvbLIPONQED8wORTvps5h4SdiQ4a2 Fl1+7sWa84b+vfK1zoBNbaGMs7F2K3fLrzXb5rSHNmJKdnotr78xNcaf36aNL3FaQw2d olKkVB6MIGjcfaPf63MltRBDxieUPuZi+LyMlKHshz25V3/aODyI2MbtWc3MYtGeVP7z Pq6A== X-Gm-Message-State: AOAM532KHOJUaRD0vHQnCmkbEejRQC9A9dbzNkKFP59iJ2Zjbn6wWSAJ Y+evndyKwbaskuhvL+V+gTRrMg== X-Google-Smtp-Source: ABdhPJwIBGR1N7IUh/aQ6HZ0+8b/Q0qI19mNzXIIgr3T+93oxWn6idNMPJO4JoW/Rm+/dPkRNEj7kg== X-Received: by 2002:a17:90b:154:: with SMTP id em20mr3504443pjb.173.1597828096467; Wed, 19 Aug 2020 02:08:16 -0700 (PDT) Received: from localhost.localdomain (p784a66b9.tkyea130.ap.so-net.ne.jp. [120.74.102.185]) by smtp.gmail.com with ESMTPSA id h14sm27511692pfk.195.2020.08.19.02.08.14 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 19 Aug 2020 02:08:15 -0700 (PDT) From: AKASHI Takahiro To: trini@konsulko.com Cc: tuomas.tynkkynen@iki.fi, bmeng.cn@gmail.com, sjg@chromium.org, u-boot@lists.denx.de, AKASHI Takahiro Subject: [PATCH] virtio_blk: set log2blksz correctly Date: Wed, 19 Aug 2020 18:07:32 +0900 Message-Id: <20200819090732.155299-1-takahiro.akashi@linaro.org> X-Mailer: git-send-email 2.28.0 MIME-Version: 1.0 X-BeenThere: u-boot@lists.denx.de X-Mailman-Version: 2.1.34 Precedence: list List-Id: U-Boot discussion List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: u-boot-bounces@lists.denx.de Sender: "U-Boot" X-Virus-Scanned: clamav-milter 0.102.3 at phobos.denx.de X-Virus-Status: Clean 'log2blksz' in blk_desc structure must always be initialized, otherwise it will cause a lot of weird failures in file operations. For example, fs_set_blk_dev[_with_part]() examines a block device against every file system with its probe function. In particular, ext4 file system's ext4_probe() will calls fs_devread() to fetch a super block. If log2blksz is 0, the actual 'read' size, i.e. block_len >> log2blksz, is much bigger than a buffer's size, and it can end up with memory corruption. Signed-off-by: AKASHI Takahiro Fixes: f4802209e59d ("virtio: Add block driver support") Reviewed-by: Bin Meng --- drivers/virtio/virtio_blk.c | 1 + 1 file changed, 1 insertion(+) diff --git a/drivers/virtio/virtio_blk.c b/drivers/virtio/virtio_blk.c index 992118c60758..1799f5c5eb36 100644 --- a/drivers/virtio/virtio_blk.c +++ b/drivers/virtio/virtio_blk.c @@ -115,6 +115,7 @@ static int virtio_blk_probe(struct udevice *dev) return ret; desc->blksz = 512; + desc->log2blksz = 9; virtio_cread(dev, struct virtio_blk_config, capacity, &cap); desc->lba = cap;