Received: by 2002:a05:6358:4e97:b0:b3:742d:4702 with SMTP id ce23csp4301097rwb; Tue, 16 Aug 2022 19:20:44 -0700 (PDT) X-Google-Smtp-Source: AA6agR5K/0IinWGXIsbRa4b8ylUF3DkFNwoszRevmupIUcO3R/VUHUzVQb+uKG3SJn7SBh17evbw X-Received: by 2002:a17:903:230e:b0:16f:784:ea3f with SMTP id d14-20020a170903230e00b0016f0784ea3fmr24424041plh.160.1660702843888; Tue, 16 Aug 2022 19:20:43 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1660702843; cv=none; d=google.com; s=arc-20160816; b=OOx/DJ6xqpIz1Kgyr1oONh4dDQDeSxU4bQ8Zeuy5bZ5BYMSB+9lLx782F/C76YE15l 9U8/0+Onq8PFz/iXuBq2XYxphII/p/Wko+m1al8brI7vwGF/ZqywjGkZiaGtL9sS+cvs Y1KOZRUVNsn2bUXUk26WrQlWDv6OT5FR2ZxZHmvVmurxa1sz/xRXzXd+cuDH50Fyl/cV 1O9Tu9Q83iB32rurQ3tjSLzG4BKnGgF2ygfbSjX6RWb1vK1oaFvZ76lcNXWcdowRGeN/ fRHSijIZ8Tnx42UD9q+qn/Ys8Sb2h69CT5jq8yrOGwlm6++ypJGLjUgELgKL7JDseRb5 M78Q== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:cc:to:subject :message-id:date:from:in-reply-to:references:mime-version :dkim-signature; bh=fs4Zw8pySDSqaoEJWdBDfrMG3gZcqDenZx3uRmVVluc=; b=0PEozkkYpPDDABb1k0s6EliUbMTyqulMtrTFu+wgGgsMS+52No/peKtY/uGYJtuf8I /TF3DjW73LSbO8ccb4LSWoFBAtpwYVHbSm40pxfYQ+CFeMufFmj4yykxlUe3GT6ODWT3 GxsfstPErINh/LMS+utqQQ20Arzff6FzQ+UD8YCOltbVCH4nF4lHGZG6izO6zPWPU+nN 8/aoje3nlLAXRWf4f6o3+khsvE6LVKvixIBZ65xu63vXK/gUGYfpt4JjBjOl4Iwd2aGl 6z9AkRvTSj9dKUB96+NkH1KW4egW2nSfgTlsnb0UychHk+iagoPh9Y2AulS750AB2kI9 GOog== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@igel-co-jp.20210112.gappssmtp.com header.s=20210112 header.b=iFZ48bJI; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Return-Path: Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id om7-20020a17090b3a8700b001f28dc085bfsi660128pjb.115.2022.08.16.19.20.32; Tue, 16 Aug 2022 19:20:43 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) client-ip=2620:137:e000::1:20; Authentication-Results: mx.google.com; dkim=pass header.i=@igel-co-jp.20210112.gappssmtp.com header.s=20210112 header.b=iFZ48bJI; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S238282AbiHQBoO (ORCPT + 99 others); Tue, 16 Aug 2022 21:44:14 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:38160 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S238083AbiHQBoK (ORCPT ); Tue, 16 Aug 2022 21:44:10 -0400 Received: from mail-lf1-x135.google.com (mail-lf1-x135.google.com [IPv6:2a00:1450:4864:20::135]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id F25D65D13C for ; Tue, 16 Aug 2022 18:44:08 -0700 (PDT) Received: by mail-lf1-x135.google.com with SMTP id d14so17201399lfl.13 for ; Tue, 16 Aug 2022 18:44:08 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=igel-co-jp.20210112.gappssmtp.com; s=20210112; h=content-transfer-encoding:cc:to:subject:message-id:date:from :in-reply-to:references:mime-version:from:to:cc; bh=fs4Zw8pySDSqaoEJWdBDfrMG3gZcqDenZx3uRmVVluc=; b=iFZ48bJIT68QElZCnFGUJUzGaz0sNHdt9olCCsZx4p6aGWH+FzZdGPSrMrsg14GGPq euhAqHesA3zbWdcRTuCB2jDU0LslO6XoHB0vDi4S4+ZXoeDjguzqP5d/D1Oy0ec6IDjA ldjcjiWucUdEBigxod9CT22gmyOyVQV1jGs/N8upQ5Ca9TiIaJVS6NZtFjlMVq/d0j/N uDwVC2Qh2aJPjwd/OHo49gbA6KQ/AnexhGG0S7B7R+tS1LZXnMW2sRPIj0Jnl2/2UmT0 dE8QSsCTIfOqZmLYH0f0L0yVkCN7C4uQdS6rHEkc92JC9ArDJ9HSo4T6HixIHap1Rtr7 nSeg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=content-transfer-encoding:cc:to:subject:message-id:date:from :in-reply-to:references:mime-version:x-gm-message-state:from:to:cc; bh=fs4Zw8pySDSqaoEJWdBDfrMG3gZcqDenZx3uRmVVluc=; b=xp0/2DVtfr0ZzS3+joolibmqH7q4QZQZuKVXECXEunqCTA5bpZ4npnUidyMiFaSWhk u9+AywjEZRo5QVmieU0v7YZD15O2mrrJMMco9dfFiV1+80T+FH0n84b0+gcktnmdvl+d 36REHla0GTD76dEo2Ko1PbrkNNCTIqt5drSchtfu0NQQEzUFPVF5Y719sqDrGIAGYR2U fqBD8g+FnUIVTy7Z/OUScRlvNdUXjYEwQpVqVQkEYNfpCvJjzSu3VY0gDvhrbihDOmLq vo+kHaiNmQVKzjY/jvZ3oqGyEJbRVRFw9Vg2FF0APgQ8299bl7lfLae8KukY7w2TRGcd kwBA== X-Gm-Message-State: ACgBeo3W1XSmJZyrjpS6VNj0QgALv3Vb7l5Jq/8aakpAWlnFy2NOA423 /v375mZxD9sLPM+T8pU7xUby1QliOQDq3WcZKAqyDCNfNn09ag== X-Received: by 2002:a05:6512:687:b0:48b:3b50:ba56 with SMTP id t7-20020a056512068700b0048b3b50ba56mr8249358lfe.32.1660700647348; Tue, 16 Aug 2022 18:44:07 -0700 (PDT) MIME-Version: 1.0 References: <20220816100617.90720-1-mie@igel.co.jp> In-Reply-To: From: Shunsuke Mie Date: Wed, 17 Aug 2022 10:43:50 +0900 Message-ID: Subject: Re: [PATCH] misc: pci_endpoint_test: Fix pci_endpoint_test_{copy,write,read}() panic To: Greg Kroah-Hartman Cc: Kishon Vijay Abraham I , Lorenzo Pieralisi , =?UTF-8?Q?Krzysztof_Wilczy=C5=84ski?= , Arnd Bergmann , linux-pci@vger.kernel.org, Linux Kernel Mailing List Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: quoted-printable X-Spam-Status: No, score=-1.9 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,RCVD_IN_DNSWL_NONE,SPF_HELO_NONE,SPF_PASS, T_SCC_BODY_TEXT_LINE autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org 2022=E5=B9=B48=E6=9C=8816=E6=97=A5(=E7=81=AB) 19:27 Greg Kroah-Hartman : > > On Tue, Aug 16, 2022 at 07:06:17PM +0900, Shunsuke Mie wrote: > > Although dma_map_single() doesn't permit zero length mapping, the each > > test functions called the function without zero checking. > > > > A panic was reported on arm64: > > > > [ 60.137988] ------------[ cut here ]------------ > > [ 60.142630] kernel BUG at kernel/dma/swiotlb.c:624! > > [ 60.147508] Internal error: Oops - BUG: 0 [#1] PREEMPT SMP > > [ 60.152992] Modules linked in: dw_hdmi_cec crct10dif_ce simple_bridg= e rcar_fdp1 vsp1 rcar_vin videobuf2_vmalloc rcar_csi2 v4l > > 2_mem2mem videobuf2_dma_contig videobuf2_memops pci_endpoint_test video= buf2_v4l2 videobuf2_common rcar_fcp v4l2_fwnode v4l2_asyn > > c videodev mc gpio_bd9571mwv max9611 pwm_rcar ccree at24 authenc libdes= phy_rcar_gen3_usb3 usb_dmac display_connector pwm_bl > > [ 60.186252] CPU: 0 PID: 508 Comm: pcitest Not tainted 6.0.0-rc1rpci-= dev+ #237 > > [ 60.193387] Hardware name: Renesas Salvator-X 2nd version board base= d on r8a77951 (DT) > > [ 60.201302] pstate: 00000005 (nzcv daif -PAN -UAO -TCO -DIT -SSBS BT= YPE=3D--) > > [ 60.208263] pc : swiotlb_tbl_map_single+0x2c0/0x590 > > [ 60.213149] lr : swiotlb_map+0x88/0x1f0 > > [ 60.216982] sp : ffff80000a883bc0 > > [ 60.220292] x29: ffff80000a883bc0 x28: 0000000000000000 x27: 0000000= 000000000 > > [ 60.227430] x26: 0000000000000000 x25: ffff0004c0da20d0 x24: ffff800= 00a1f77c0 > > [ 60.234567] x23: 0000000000000002 x22: 0001000040000010 x21: 0000000= 07a000000 > > [ 60.241703] x20: 0000000000200000 x19: 0000000000000000 x18: 0000000= 000000000 > > [ 60.248840] x17: 0000000000000000 x16: 0000000000000000 x15: ffff000= 6ff7b9180 > > [ 60.255977] x14: ffff0006ff7b9180 x13: 0000000000000000 x12: 0000000= 000000000 > > [ 60.263113] x11: 0000000000000000 x10: 0000000000000000 x9 : 0000000= 000000000 > > [ 60.270249] x8 : 0001000000000010 x7 : ffff0004c6754b20 x6 : 0000000= 000000000 > > [ 60.277385] x5 : ffff0004c0da2090 x4 : 0000000000000000 x3 : 0000000= 000000001 > > [ 60.284521] x2 : 0000000040000000 x1 : 0000000000000000 x0 : 0000000= 040000010 > > [ 60.291658] Call trace: > > [ 60.294100] swiotlb_tbl_map_single+0x2c0/0x590 > > [ 60.298629] swiotlb_map+0x88/0x1f0 > > [ 60.302115] dma_map_page_attrs+0x188/0x230 > > [ 60.306299] pci_endpoint_test_ioctl+0x5e4/0xd90 [pci_endpoint_test] > > [ 60.312660] __arm64_sys_ioctl+0xa8/0xf0 > > [ 60.316583] invoke_syscall+0x44/0x108 > > [ 60.320334] el0_svc_common.constprop.0+0xcc/0xf0 > > [ 60.325038] do_el0_svc+0x2c/0xb8 > > [ 60.328351] el0_svc+0x2c/0x88 > > [ 60.331406] el0t_64_sync_handler+0xb8/0xc0 > > [ 60.335587] el0t_64_sync+0x18c/0x190 > > [ 60.339251] Code: 52800013 d2e00414 35fff45c d503201f (d4210000) > > [ 60.345344] ---[ end trace 0000000000000000 ]--- > > > > To fix it, this patch adds checkings the payload length if it is zero. > > > > Fixes: 343dc693f7b7 ("misc: pci_endpoint_test: Prevent some integer ove= rflows") > > Signed-off-by: Shunsuke Mie > > --- > > drivers/misc/pci_endpoint_test.c | 6 +++--- > > 1 file changed, 3 insertions(+), 3 deletions(-) > > > > diff --git a/drivers/misc/pci_endpoint_test.c b/drivers/misc/pci_endpoi= nt_test.c > > index 8f786a225dcf..d45426a73396 100644 > > --- a/drivers/misc/pci_endpoint_test.c > > +++ b/drivers/misc/pci_endpoint_test.c > > @@ -364,7 +364,7 @@ static bool pci_endpoint_test_copy(struct pci_endpo= int_test *test, > > } > > > > size =3D param.size; > > - if (size > SIZE_MAX - alignment) > > + if (size > SIZE_MAX - alignment || !size) > > goto err; > > Can we test size first? And do it in the ioctl handler in one place so > you don't have to add it everywhere? > > Or have a "validate all parameters" function that you do it in one > place? Yes, it is reasonable I think. I'll unify validations to the function. > Also, all of these ioctl handlers are wrong, they are returning "0" to > userspace if they fail, which is not correct at all. > thanks, > > greg k-h