Received: by 2002:a25:e7d8:0:0:0:0:0 with SMTP id e207csp1055720ybh; Wed, 11 Mar 2020 16:39:05 -0700 (PDT) X-Google-Smtp-Source: ADFU+vtsIq0ZBKwJpVcwTZGDWStTEeUj9z3oVfpdddQhuoHhDQkfVHK+t/VJp0uIltWN0knif08P X-Received: by 2002:aca:4183:: with SMTP id o125mr726809oia.125.1583969945746; Wed, 11 Mar 2020 16:39:05 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1583969945; cv=none; d=google.com; s=arc-20160816; b=Cbu3v/fDMMQG+agT7lvRk1ubp6ud6DddjcrC14Tvniamk/2GGeViYT/ZNb04C6LYtD E+ed7e4dqlxg4Bps2isTuFERoEAyNgoHSjdQljHXhOuoGi1L+KOpqWvG7wsHInSSgja7 7gyRm/QCgnXlyrbvE3/g1VB4bbTGIcPPxkE2HbDyILrthsI+/mvpt3UWsKg3D1fPiu+1 8YJe71GlpRGaqWWhEBVDTTafqgszXdn2k3yTWI9zU3O7gJPV+d5+6CapfzzfJStDX92O pHoN/ucBhTtvdi6+kGvowN76Y67yMrTWYijsIofDcPEsy1q3R7t/Qc95pZJDWIksvpos 0yDw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:content-transfer-encoding:mime-version :references:in-reply-to:message-id:subject:cc:to:from:date :dkim-signature; bh=9CBLe6sHcUgeeYntR7oN91GJg4OzoiFrSoZ5delPU9o=; b=QlAwxejkaJ5rFX5zRYn/caKFskSvJnqe6bHWn/e4MuuH+lOGUmCTUW9KLGvD+qZeN5 p1i2IxEG31D92LHbj2AocBXxaREHlMvUfPn1OgQoKPG5Db5JSCWTbzLHkyNM+g5p+kd/ 1yXQG+GBz32rlEl2JFeWuZ3EPZXeMsq8ZTtYHPaxAuwIiTv2u00hBj5QhF4X5iOcdWvM 0kIsaBX+d7xvbH3Ei6saaD68KYiFCOnmSwELGLENWLUACQVwnlg5b8Dyr8++L2KWVcro tmvc7TbxLdfAMUSv2eZlzeOzs30M6Th9FYReMhnvp6UuHmAz+MRAJK1CneFqdJAfq4Oq Xj8Q== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=default header.b=fRsZjvD6; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id d10si1806023oti.226.2020.03.11.16.38.52; Wed, 11 Mar 2020 16:39:05 -0700 (PDT) Received-SPF: pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; dkim=pass header.i=@kernel.org header.s=default header.b=fRsZjvD6; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1731481AbgCKXiE (ORCPT + 99 others); Wed, 11 Mar 2020 19:38:04 -0400 Received: from mail.kernel.org ([198.145.29.99]:41342 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726194AbgCKXiD (ORCPT ); Wed, 11 Mar 2020 19:38:03 -0400 Received: from localhost.localdomain (c-73-231-172-41.hsd1.ca.comcast.net [73.231.172.41]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPSA id 61D4A20754; Wed, 11 Mar 2020 23:38:01 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1583969881; bh=tYse/b2VgvRrHBIlQlCMRUOHJDMPsP7MDl/1tT5CHKA=; h=Date:From:To:Cc:Subject:In-Reply-To:References:From; b=fRsZjvD6guoPFk2BEwdeTGQoG+yB0UFjHX5rYzIeElepPrrkmGa8tHDNkI/3bJcjw c6HaCi4KjYzlUuyPlnw5PKl3e2cpomqfzDKAFyF0Ka8sRL4rq/8GhcXDVckxbfx5x/ ++T4pZu93SiPDvEq388UoOwzyE2RnNP1+OiqA2Z0= Date: Wed, 11 Mar 2020 16:38:00 -0700 From: Andrew Morton To: Walter Wu Cc: Andrey Ryabinin , Alexander Potapenko , Dmitry Vyukov , Qian Cai , Stephen Rothwell , , , , , wsd_upstream Subject: Re: [PATCH -next] kasan: fix -Wstringop-overflow warning Message-Id: <20200311163800.a264d4ec8f26cca7bb5046fb@linux-foundation.org> In-Reply-To: <20200311134244.13016-1-walter-zh.wu@mediatek.com> References: <20200311134244.13016-1-walter-zh.wu@mediatek.com> X-Mailer: Sylpheed 3.5.1 (GTK+ 2.24.31; x86_64-pc-linux-gnu) Mime-Version: 1.0 Content-Type: text/plain; charset=US-ASCII Content-Transfer-Encoding: 7bit Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org 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? Do we have any guarantee that this it will contiue to work in future gcc's?