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=-5.2 required=3.0 tests=DKIMWL_WL_HIGH,DKIM_SIGNED, DKIM_VALID,HEADER_FROM_DIFFERENT_DOMAINS,MAILING_LIST_MULTI,SIGNED_OFF_BY, SPF_HELO_NONE,SPF_PASS,URIBL_BLOCKED,USER_AGENT_SANE_1 autolearn=ham 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 84ED7C432C0 for ; Thu, 21 Nov 2019 22:22:20 +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 519C7206D7 for ; Thu, 21 Nov 2019 22:22:20 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (2048-bit key) header.d=lists.infradead.org header.i=@lists.infradead.org header.b="tHAHmPQq" DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org 519C7206D7 Authentication-Results: mail.kernel.org; dmarc=fail (p=none dis=none) header.from=virtuozzo.com Authentication-Results: mail.kernel.org; spf=none smtp.mailfrom=linux-mediatek-bounces+linux-mediatek=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:In-Reply-To:MIME-Version:Date: Message-ID:From:References:To:Subject:Reply-To:Content-ID:Content-Description :Resent-Date:Resent-From:Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID: List-Owner; bh=bZRFHe0+TmofOjJMKimOWDbRELXAzhPUH0enoBxAdjw=; b=tHAHmPQq6oDU12 Zdnb3ABBkEl/mx4Tgn9tISVQB+7EvDOp3T/4JqC/ASv3SSbRpgIPjn3FT9So8k2zLnkhyDGR8oBcn DiPfZBMPKhOuUo3VgXghaSRf66J2/WsIEP+mWEYBKFlEgiwQS+JDdGSmZS/0+lDgqE2qXoAPxVOfy R3zgPEAI3XQdWm0s7cnNBNj359zaZ1pbc1G179WCy71OSRtqGct7737o2DkikFtmsYxnUnqU3FlqJ 2KlA1LKvfJd/A9+3EEz0cr92NRiYDxl2zA8VVQJVTVww+T7UtNw/7jGRgAamgJaicFAeug9+yYoSh vGOi2GfgFuAKJ52wGDWA==; 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 1iXuqC-0003Vl-1G; Thu, 21 Nov 2019 22:22:20 +0000 Received: from relay.sw.ru ([185.231.240.75]) by bombadil.infradead.org with esmtps (Exim 4.92.3 #3 (Red Hat Linux)) id 1iXuq9-0003VI-6c; Thu, 21 Nov 2019 22:22:18 +0000 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 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-Language: en-US X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20191121_142217_239698_42267878 X-CRM114-Status: GOOD ( 11.29 ) X-BeenThere: linux-mediatek@lists.infradead.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: wsd_upstream , linux-kernel@vger.kernel.org, kasan-dev@googlegroups.com, linux-mm@kvack.org, linux-mediatek@lists.infradead.org, Andrew Morton , linux-arm-kernel@lists.infradead.org Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: 7bit Sender: "Linux-mediatek" Errors-To: linux-mediatek-bounces+linux-mediatek=archiver.kernel.org@lists.infradead.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 _______________________________________________ Linux-mediatek mailing list Linux-mediatek@lists.infradead.org http://lists.infradead.org/mailman/listinfo/linux-mediatek