From patchwork Wed Jun 30 12:20:53 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Arnd Bergmann X-Patchwork-Id: 468689 Delivered-To: patch@linaro.org Received: by 2002:a02:c94a:0:0:0:0:0 with SMTP id u10csp292982jao; Wed, 30 Jun 2021 05:21:03 -0700 (PDT) X-Google-Smtp-Source: ABdhPJxILJmA+X6Vmx5GMgQX8O96XrDYGXWV5V+Ho9DUdLs+pWx/lcfykBsEZJOAO5SCAM37IIu4 X-Received: by 2002:a17:906:a3d7:: with SMTP id ca23mr35354289ejb.176.1625055663434; Wed, 30 Jun 2021 05:21:03 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1625055663; cv=none; d=google.com; s=arc-20160816; b=a2w0/scFKHNuNydDuUT483+Aqf4mMPeLuAOl4KUeo5/IMv9dRvSUDVRsDXZhIkqHjW RXGhtN9OZPQjoQH+ih+ZYAan3JWpiGNHKgHNIoTrCj07ELZ4plkeNmC0Nnl7ZYyq2J3q XRATXPhW6S/qVSqcBu5I0MorokO4IkUXC6KwnrHfauOjwfW8vCNPxsD/e3gbGQ2F4icc /COlDE/kXDaWi6jjyu+yArxZXFgLYHjX43Yw7abNi/Knteuq7COs1vIvC0RgSv+W+KWl 55NfNdiYFvQs2uSeyx5H7m2S/m36augeSu4ZuhpHA78xkZsWTy3f28lpJFtvK+52kjsq mtOg== 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 :message-id:date:subject:cc:to:from:dkim-signature; bh=TR4vjEL/DUobHPQ667oxC9mowuXCyLU1eHe26tpi3rw=; b=b//NKTqhZMuhhRWQUOduP2s2plD3av/KWnnew82QBmuJRP7izP/2vsGXAWTRvNVuUZ iscU1+6rIOmUSZB7OVV+gbSWtytA6Zxh1pUrqwm9uSdqGYoGuDkUGBjxYXUqclGxkhyn eb2u6mRtflrvCjQPaUp4C7x+Ot9+iDBn+Afqr601cpWqcDWuNXT+XBAj3tXoZq+A9ul7 recb8B4IT8TZgsfyy0FIqS3MGuI/Db4/gjXvCfVxxkDv7Avj9BgToVwLO+thyUQ/G6HB MjhVgUenQvykd1GWvkLxyLqiFE9kGcw45m0AAYLL8X33trIubqz3+IlSpRB0wFnd9hmh IrTA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=k20201202 header.b=OHbUhu85; spf=pass (google.com: domain of linux-mmc-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-mmc-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id c16si20247511edw.522.2021.06.30.05.21.03; Wed, 30 Jun 2021 05:21:03 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-mmc-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=@kernel.org header.s=k20201202 header.b=OHbUhu85; spf=pass (google.com: domain of linux-mmc-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-mmc-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S234403AbhF3MXa (ORCPT + 4 others); Wed, 30 Jun 2021 08:23:30 -0400 Received: from mail.kernel.org ([198.145.29.99]:43538 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S234444AbhF3MXa (ORCPT ); Wed, 30 Jun 2021 08:23:30 -0400 Received: by mail.kernel.org (Postfix) with ESMTPSA id 91B8E61622; Wed, 30 Jun 2021 12:21:00 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1625055661; bh=urERl5tO5goZ6TLzzaZEftHjA9owertzkVYQiHZYC24=; h=From:To:Cc:Subject:Date:From; b=OHbUhu85T7wIqIbKJ59ahiYZeAhW53VDukQrN+MVx14r3o8Ymtkbk89qd+Z4Yso9X yt7337ycHuf0hyCooJTQxYhQWhTxDWTVuNR/Ew71HQvjAEnENFigbZs2JO3zWQ6HTz GjuLEZXpqUFTf9L0Y2niSZEM/iwsJWQnQ90/wKenMfGh4v5hrpOJ2A3bGOQkS5Yryk Mu5TVxhZuWQ6LKv/hfffzIXFK5D+uMVE/la5BYd0Cs6+YjeBIRjV4PvEVcIAqHKqt5 h3D1q330Simm5KK6RNHjqw/5RE2sXJxkkp9IJQEUiVZgaXmUAlWNvYvnUPdkV0kAZl oxJETBz+fJk7A== From: Arnd Bergmann To: Ulf Hansson Cc: Arnd Bergmann , Jernej Skrabec , Adrian Hunter , linux-mmc@vger.kernel.org, linux-kernel@vger.kernel.org Subject: [PATCH] mmc: warn for invalid SDIO data buffers Date: Wed, 30 Jun 2021 14:20:53 +0200 Message-Id: <20210630122057.2795882-1-arnd@kernel.org> X-Mailer: git-send-email 2.29.2 MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: linux-mmc@vger.kernel.org From: Arnd Bergmann Jernej Skrabec reported a problem with the cw1200 driver failing on arm64 systems with CONFIG_VMAP_STACK=y. The driver in this case passes a pointer to a stack variable (in vmalloc space) into the sdio layer, which gets translated into an invalid DMA address. Even without CONFIG_VMAP_STACK, the driver is still unreliable, as cache invalidations on the DMA buffer may cause random data corruption in adjacent stack slots. This could be worked around in the SDIO core, but in the discussion we decided that passing a stack variable into SDIO should always be considered a bug, as it is for USB drivers. Change the sdio core to produce a one-time warning for any on-stack (both with and without CONFIG_VMAP_STACK) as well as any vmalloc or module-local address that would have the same translation problem. Cc: Jernej Skrabec Link: https://lore.kernel.org/lkml/20210622202345.795578-1-jernej.skrabec@gmail.com/ Signed-off-by: Arnd Bergmann --- drivers/mmc/core/sdio_ops.c | 2 ++ 1 file changed, 2 insertions(+) -- 2.29.2 Reported-by: kernel test robot diff --git a/drivers/mmc/core/sdio_ops.c b/drivers/mmc/core/sdio_ops.c index 4c229dd2b6e5..14e983faf223 100644 --- a/drivers/mmc/core/sdio_ops.c +++ b/drivers/mmc/core/sdio_ops.c @@ -6,6 +6,7 @@ */ #include +#include #include #include @@ -124,6 +125,7 @@ int mmc_io_rw_extended(struct mmc_card *card, int write, unsigned fn, int err; WARN_ON(blksz == 0); + WARN_ON_ONCE(is_vmalloc_or_module_addr(buf) || object_is_on_stack(buf)); /* sanity check */ if (addr & ~0x1FFFF)