Received: by 2002:a25:ab43:0:0:0:0:0 with SMTP id u61csp7039644ybi; Thu, 13 Jun 2019 08:33:37 -0700 (PDT) X-Google-Smtp-Source: APXvYqz1cUrtOERPnkzVQoUdp+nOubda5i0r4Vq8rxgLNUWV5TffReSyqRyJYcRJAdYCZNEcFm4c X-Received: by 2002:aa7:8ac9:: with SMTP id b9mr83404387pfd.260.1560440017663; Thu, 13 Jun 2019 08:33:37 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1560440017; cv=none; d=google.com; s=arc-20160816; b=s6Ntlogbi1OX8W69HNbQrIyfnSsH2aRKDkR+S5Px8NhUNQiv3L34xWYYZIKXTTFD7q diufUovt/efXqWul2hr9E5SGKRY8TFmYE77ZZLXTfIi15oWs+m6fJbDGnr7g/uTcXAs/ RSsyVIyqP0zwxL4D2QaknNIpN5fzT3wgVsFpmzrAZnMmmVOc6DaTJAdldOb+nLPc8UAs gn4ucK2UHPSGfO0dsd8DYAHRpEULoaImkvixYwhETYaNfG0YFk0X8AAI+Snyb9zgXV3m Hwd1SacSD6gMUO/bF0DWaGBoo25Azx8aze32frmXhdSpr/GXAqMiO5Gxte834BUW4TJV SImA== 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 :content-language:in-reply-to:mime-version:user-agent:date :message-id:from:references:cc:to:subject; bh=a6Gh3I2YeGZuFCvmgk6STQ7mUGuO1wt1FSU+nPj3SAw=; b=TSHUaykd7GO3C1/lMiKM9pfMTfZwj8BDbgLD4T9LHetI9fXL3cweKk2p+cYvuGteim wKQHh1HpmQUtfDH01zBohcy2OER6+7fPWG92SDbPhoGh5ofQcuWE5XIFNEvtGIoObWYZ qE9+Q7bRLhLjJ3oam9TshS994RgumfE2Bew+LMkuMXE8UBZDRdMyyA4P4K4zETe95+di EPfXh2H3uOm8AR8Sd1wkhwCzeP3VptclPRmzjY+rYX19r9HRsf3AiqvP8nR+i/fvpPPF wu6B9RHLyXSSpowzMZW17LtloMtZT7ufLbio7sPwaOY/vh2uxTPnSrguewi1qGM3TNgC Czfg== ARC-Authentication-Results: i=1; mx.google.com; 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; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=virtuozzo.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id x4si3284454pll.189.2019.06.13.08.33.22; Thu, 13 Jun 2019 08:33:37 -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; 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; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=virtuozzo.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1731542AbfFMPcW (ORCPT + 99 others); Thu, 13 Jun 2019 11:32:22 -0400 Received: from relay.sw.ru ([185.231.240.75]:40016 "EHLO relay.sw.ru" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1728483AbfFMKtT (ORCPT ); Thu, 13 Jun 2019 06:49:19 -0400 Received: from [172.16.25.12] by relay.sw.ru with esmtp (Exim 4.92) (envelope-from ) id 1hbNI7-0000bh-9J; Thu, 13 Jun 2019 13:49:11 +0300 Subject: Re: [PATCH v3 1/3] lib/test_kasan: Add bitops tests To: Marco Elver , peterz@infradead.org, dvyukov@google.com, glider@google.com, andreyknvl@google.com, mark.rutland@arm.com, hpa@zytor.com Cc: corbet@lwn.net, tglx@linutronix.de, mingo@redhat.com, bp@alien8.de, x86@kernel.org, arnd@arndb.de, jpoimboe@redhat.com, linux-doc@vger.kernel.org, linux-kernel@vger.kernel.org, linux-arch@vger.kernel.org, kasan-dev@googlegroups.com References: <20190531150828.157832-1-elver@google.com> <20190531150828.157832-2-elver@google.com> From: Andrey Ryabinin Message-ID: <5c35bc08-749f-dbc4-09d0-fcf14b1da1b3@virtuozzo.com> Date: Thu, 13 Jun 2019 13:49:23 +0300 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:60.0) Gecko/20100101 Thunderbird/60.7.0 MIME-Version: 1.0 In-Reply-To: <20190531150828.157832-2-elver@google.com> Content-Type: text/plain; charset=utf-8 Content-Language: en-US Content-Transfer-Encoding: 7bit Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On 5/31/19 6:08 PM, Marco Elver wrote: > This adds bitops tests to the test_kasan module. In a follow-up patch, > support for bitops instrumentation will be added. > > Signed-off-by: Marco Elver > --- > Changes in v3: > * Use kzalloc instead of kmalloc. > * Use sizeof(*bits). > > Changes in v2: > * Use BITS_PER_LONG. > * Use heap allocated memory for test, as newer compilers (correctly) > warn on OOB stack access. > --- > lib/test_kasan.c | 75 ++++++++++++++++++++++++++++++++++++++++++++++-- > 1 file changed, 72 insertions(+), 3 deletions(-) > > diff --git a/lib/test_kasan.c b/lib/test_kasan.c > index 7de2702621dc..1ef9702327d2 100644 > --- a/lib/test_kasan.c > +++ b/lib/test_kasan.c > @@ -11,16 +11,17 @@ > > #define pr_fmt(fmt) "kasan test: %s " fmt, __func__ > > +#include > #include > +#include > #include > -#include > #include > +#include > +#include > #include > #include > #include > #include > -#include > -#include > > /* > * Note: test functions are marked noinline so that their names appear in > @@ -623,6 +624,73 @@ static noinline void __init kasan_strings(void) > strnlen(ptr, 1); > } > > +static noinline void __init kasan_bitops(void) > +{ > + long *bits = kzalloc(sizeof(*bits), GFP_KERNEL); It would be safer to do kzalloc(sizeof(*bits) + 1, GFP_KERNEL) and change tests accordingly to: set_bit(BITS_PER_LONG + 1, bits) ... kmalloc will internally round up allocation to 16-bytes, so we won't be actually corrupting someone elses memory. > + if (!bits) > + return; > + > + pr_info("within-bounds in set_bit"); > + set_bit(0, bits); > + > + pr_info("within-bounds in set_bit"); > + set_bit(BITS_PER_LONG - 1, bits); I'd remove these two. There are plenty of within bounds set_bit() in the kernel so they are well tested already.