From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-2.3 required=3.0 tests=DKIMWL_WL_HIGH,DKIM_SIGNED, DKIM_VALID,HEADER_FROM_DIFFERENT_DOMAINS,MAILING_LIST_MULTI,SPF_HELO_NONE, SPF_PASS,UNPARSEABLE_RELAY,USER_AGENT_SANE_2 autolearn=no autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 58EF5C10DCE for ; Thu, 12 Mar 2020 05:07:59 +0000 (UTC) Received: from bombadil.infradead.org (bombadil.infradead.org [198.137.202.133]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPS id 3B0E120737 for ; Thu, 12 Mar 2020 05:07:59 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (2048-bit key) header.d=lists.infradead.org header.i=@lists.infradead.org header.b="IdUOUg08"; dkim=fail reason="signature verification failed" (1024-bit key) header.d=mediatek.com header.i=@mediatek.com header.b="WXCgrUwv" DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org 3B0E120737 Authentication-Results: mail.kernel.org; dmarc=fail (p=none dis=none) header.from=mediatek.com Authentication-Results: mail.kernel.org; spf=none smtp.mailfrom=linux-arm-kernel-bounces+infradead-linux-arm-kernel=archiver.kernel.org@lists.infradead.org DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=bombadil.20170209; h=Sender: Content-Transfer-Encoding:Content-Type:Cc:List-Subscribe:List-Help:List-Post: List-Archive:List-Unsubscribe:List-Id:MIME-Version:References:In-Reply-To: Date:To:From:Subject:Message-ID:Reply-To:Content-ID:Content-Description: Resent-Date:Resent-From:Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID: List-Owner; bh=UtcK8M6Z3zgaF6iJBHRvEoUtsXRmIkk4p3W3PlEYKu0=; b=IdUOUg08bbtJLw GdPqgf00I30f/5DKjDSkwWCyIaoN/Q+QGYXS94j+fK7yaPECCYTIGCIIUvgvV7XIMBn3WQ4CDWSmg sJ91k3NqOpQVsRWDSCtLVzFAZndLvR1bfFUPH/EJarNkc4+7ujl3CYKfSnnufharRMLJA2y467uRE +h/6U+5C5zxHVyOl3fXsMW9h42ztsDkDXAsh64A/lQjuFnIW9UJB08wVepgxvHcCSQCKJru8BqAWL Nhz/zKMJHRKD92jHs5s7XKt6CELZcK/s89mVM5n2nKKP0kq1Sz/c1qXDIPZQDh5z9pEJUEoZrkSjR LLWGbxH7yn7IqJSfRNDg==; Received: from localhost ([127.0.0.1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.92.3 #3 (Red Hat Linux)) id 1jCG4c-0006uf-Fj; Thu, 12 Mar 2020 05:07:58 +0000 Received: from mailgw01.mediatek.com ([216.200.240.184]) by bombadil.infradead.org with esmtps (Exim 4.92.3 #3 (Red Hat Linux)) id 1jCG4Z-0006uG-3q for linux-arm-kernel@lists.infradead.org; Thu, 12 Mar 2020 05:07:56 +0000 X-UUID: 98fdcdc0608741739cbbb2d3fa3fe28e-20200311 DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=mediatek.com; s=dk; h=Content-Transfer-Encoding:MIME-Version:Content-Type:References:In-Reply-To:Date:CC:To:From:Subject:Message-ID; bh=EiH9wliZJ7SlCOgjGr1o9krpwAx0Yhk57Jmk6JMcvtA=; b=WXCgrUwvwPckPJtrgli7CI1U5PziZL60rSUU1If/uRKOocJn2Bf7DiMVvg1bW13c5lC7uTkCP6KBN8KunoFOwNYhV1Mnb0qSB42mvG7PgydgKaDLk6l7YrlSI6ZMLBgFkx1DDTSfkPPFRz16ibhCCTruDcXwWLcaJdzXQN2W9pU=; X-UUID: 98fdcdc0608741739cbbb2d3fa3fe28e-20200311 Received: from mtkcas66.mediatek.inc [(172.29.193.44)] by mailgw01.mediatek.com (envelope-from ) (musrelay.mediatek.com ESMTP with TLS) with ESMTP id 1255333377; Wed, 11 Mar 2020 21:07:51 -0800 Received: from mtkmbs07n1.mediatek.inc (172.21.101.16) by MTKMBS62N2.mediatek.inc (172.29.193.42) with Microsoft SMTP Server (TLS) id 15.0.1395.4; Wed, 11 Mar 2020 22:04:19 -0700 Received: from mtkcas09.mediatek.inc (172.21.101.178) by mtkmbs07n1.mediatek.inc (172.21.101.16) with Microsoft SMTP Server (TLS) id 15.0.1395.4; Thu, 12 Mar 2020 13:02:47 +0800 Received: from [172.21.84.99] (172.21.84.99) by mtkcas09.mediatek.inc (172.21.101.73) with Microsoft SMTP Server id 15.0.1395.4 via Frontend Transport; Thu, 12 Mar 2020 13:02:55 +0800 Message-ID: <1583989425.17522.29.camel@mtksdccf07> Subject: Re: [PATCH -next] kasan: fix -Wstringop-overflow warning From: Walter Wu To: Andrew Morton Date: Thu, 12 Mar 2020 13:03:45 +0800 In-Reply-To: <20200311163800.a264d4ec8f26cca7bb5046fb@linux-foundation.org> References: <20200311134244.13016-1-walter-zh.wu@mediatek.com> <20200311163800.a264d4ec8f26cca7bb5046fb@linux-foundation.org> X-Mailer: Evolution 3.2.3-0ubuntu6 MIME-Version: 1.0 X-MTK: N X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20200311_220755_162809_F6A8DAEC X-CRM114-Status: GOOD ( 15.60 ) X-BeenThere: linux-arm-kernel@lists.infradead.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Stephen Rothwell , wsd_upstream , linux-kernel@vger.kernel.org, kasan-dev@googlegroups.com, linux-mm@kvack.org, Qian Cai , linux-arm-kernel@lists.infradead.org, Andrey Ryabinin , Alexander Potapenko , Dmitry Vyukov Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: 7bit Sender: "linux-arm-kernel" Errors-To: linux-arm-kernel-bounces+infradead-linux-arm-kernel=archiver.kernel.org@lists.infradead.org On Wed, 2020-03-11 at 16:38 -0700, Andrew Morton wrote: > On Wed, 11 Mar 2020 21:42:44 +0800 Walter Wu wrote: > > > Compiling with gcc-9.2.1 points out below warnings. > > > > In function 'memmove', > > inlined from 'kmalloc_memmove_invalid_size' at lib/test_kasan.c:301:2: > > include/linux/string.h:441:9: warning: '__builtin_memmove' specified > > bound 18446744073709551614 exceeds maximum object size > > 9223372036854775807 [-Wstringop-overflow=] > > > > Why generate this warnings? > > Because our test function deliberately pass a negative number in memmove(), > > so we need to make it "volatile" so that compiler doesn't see it. > > > > ... > > > > --- a/lib/test_kasan.c > > +++ b/lib/test_kasan.c > > @@ -289,6 +289,7 @@ static noinline void __init kmalloc_memmove_invalid_size(void) > > { > > char *ptr; > > size_t size = 64; > > + volatile size_t invalid_size = -2; > > > > pr_info("invalid size in memmove\n"); > > ptr = kmalloc(size, GFP_KERNEL); > > @@ -298,7 +299,7 @@ static noinline void __init kmalloc_memmove_invalid_size(void) > > } > > > > memset((char *)ptr, 0, 64); > > - memmove((char *)ptr, (char *)ptr + 4, -2); > > + memmove((char *)ptr, (char *)ptr + 4, invalid_size); > > kfree(ptr); > > } > > Huh. Why does this trick suppress the warning? > We read below the document, so we try to verify whether it is work for another checking. After we changed the code, It is ok. https://gcc.gnu.org/onlinedocs/gcc-9.2.0/gcc/Warning-Options.html#Warning-Options "They do not occur for variables or elements declared volatile. Because these warnings depend on optimization, the exact variables or elements for which there are warnings depends on the precise optimization options and version of GCC used." > Do we have any guarantee that this it will contiue to work in future > gcc's? > Sorry, I am not compiler expert, so I can't guarantee gcc will not modify the rule, but at least it is work before gcc-9. > _______________________________________________ linux-arm-kernel mailing list linux-arm-kernel@lists.infradead.org http://lists.infradead.org/mailman/listinfo/linux-arm-kernel