Received: by 2002:a25:7ec1:0:0:0:0:0 with SMTP id z184csp3820908ybc; Thu, 21 Nov 2019 14:24:23 -0800 (PST) X-Google-Smtp-Source: APXvYqzdjYBdgsc6w8ncW1Fmm/tcNiAvywNVHP/J9YNcAY8jiyc+biQklOHPDngNfPKmatrtMOuD X-Received: by 2002:adf:ec42:: with SMTP id w2mr13269423wrn.32.1574375063459; Thu, 21 Nov 2019 14:24:23 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1574375063; cv=none; d=google.com; s=arc-20160816; b=MwwHRZjYXRtPCuW0zOvo3qmxulEOrOvATcqCV7vQHUSH7a+p0zNJgPskUlEEwrVmhf eltFrpguwwbi7ZQyQXeh0bgDR+W2mEAlyRk6QMEsPF8LofaXHeb/kW3QL0eMxYhQsu2k QY3xc19ssd/SWP/k6wJvMUrmR1tfg9LhZQsJGThq/FAbAaBg4hjfmNLev1N89gXAIHHw V77QVYwhAMFrbbABgQd1j96eLsnDD34HD43YzoCeE0IyUaBEJQxsXkVrwHqgFphncSGr GyU0GeTnl3VMGLgC43OlR3dkEE6u9dD/+xbpCJdRJqGTVD95M2tah/hD8YGhL7EH1zx+ d4xQ== 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=ji3gnkCDRPtNWFKJJcjkuQMsuapO/ZRLFz7EqSXe6e0=; b=fB8ON3SmAIdlY/M2SxASl7wfSNJL67/vUs5KgdunE1S0OHAj1kMrpbypQw2Jbc3uzW gjzW2zhp1dafjT4EFq25YQMqazE9acAAJpgiZYidLi3tGg/vJF14KAua5hpgNjqKABBe fU8tsuDJMzPSoU4z+RZNhBDYxH/ETitfcFsIjVMm5NNrxkls3MZCJjrzIqz5RUhYlm+w fybxyMgy0hvfKp5i4H5kb8RlhQjKchf2c1+sf2rTk+kRG1OcozbDtqB+IDX0/uX80b8d XOf36lEdiGLgoAmfGCbt8KCOh+K2rfpEwwTHF+X7hUb+2DcC0JMUrbf3XUdEQ4WG9ErB EHVA== 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 w25si3491897edl.418.2019.11.21.14.23.55; Thu, 21 Nov 2019 14:24:23 -0800 (PST) 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 S1726920AbfKUWWV (ORCPT + 99 others); Thu, 21 Nov 2019 17:22:21 -0500 Received: from relay.sw.ru ([185.231.240.75]:56098 "EHLO relay.sw.ru" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726329AbfKUWWV (ORCPT ); Thu, 21 Nov 2019 17:22:21 -0500 Received: from [192.168.15.154] by relay.sw.ru with esmtp (Exim 4.92.3) (envelope-from ) id 1iXuq2-0007vl-St; Fri, 22 Nov 2019 01:22:11 +0300 Subject: Re: [PATCH v4 1/2] kasan: detect negative size in memory operation function To: Walter Wu , Alexander Potapenko , Dmitry Vyukov , Matthias Brugger Cc: kasan-dev@googlegroups.com, linux-mm@kvack.org, linux-kernel@vger.kernel.org, linux-arm-kernel@lists.infradead.org, wsd_upstream , linux-mediatek@lists.infradead.org, Andrew Morton References: <20191112065302.7015-1-walter-zh.wu@mediatek.com> From: Andrey Ryabinin Message-ID: Date: Fri, 22 Nov 2019 01:20:23 +0300 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:68.0) Gecko/20100101 Thunderbird/68.2.2 MIME-Version: 1.0 In-Reply-To: <20191112065302.7015-1-walter-zh.wu@mediatek.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 11/12/19 9:53 AM, Walter Wu wrote: > KASAN missed detecting size is a negative number in memset(), memcpy(), > and memmove(), it will cause out-of-bounds bug. So needs to be detected > by KASAN. > > If size is a negative number, then it has a reason to be defined as > out-of-bounds bug type. > Casting negative numbers to size_t would indeed turn up as > a large size_t and its value will be larger than ULONG_MAX/2, > so that this can qualify as out-of-bounds. > > KASAN report is shown below: > > BUG: KASAN: out-of-bounds in kmalloc_memmove_invalid_size+0x70/0xa0 > Read of size 18446744073709551608 at addr ffffff8069660904 by task cat/72 > > CPU: 2 PID: 72 Comm: cat Not tainted 5.4.0-rc1-next-20191004ajb-00001-gdb8af2f372b2-dirty #1 > Hardware name: linux,dummy-virt (DT) > Call trace: > dump_backtrace+0x0/0x288 > show_stack+0x14/0x20 > dump_stack+0x10c/0x164 > print_address_description.isra.9+0x68/0x378 > __kasan_report+0x164/0x1a0 > kasan_report+0xc/0x18 > check_memory_region+0x174/0x1d0 > memmove+0x34/0x88 > kmalloc_memmove_invalid_size+0x70/0xa0 > > [1] https://bugzilla.kernel.org/show_bug.cgi?id=199341 > > Signed-off-by: Walter Wu > Reported-by: Dmitry Vyukov > Suggested-by: Dmitry Vyukov > Reviewed-by: Dmitry Vyukov > Cc: Andrey Ryabinin > Cc: Alexander Potapenko > Reported-by: kernel test robot > --- Reviewed-by: Andrey Ryabinin