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,INCLUDES_PATCH,MAILING_LIST_MULTI, SPF_HELO_NONE,SPF_PASS,UNPARSEABLE_RELAY,URIBL_BLOCKED,USER_AGENT_SANE_2 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 2A16DC432C0 for ; Thu, 21 Nov 2019 13:09:28 +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 EFD8420731 for ; Thu, 21 Nov 2019 13:09:27 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (2048-bit key) header.d=lists.infradead.org header.i=@lists.infradead.org header.b="QYHrJRp5"; dkim=fail reason="signature verification failed" (1024-bit key) header.d=mediatek.com header.i=@mediatek.com header.b="K8JOzSEH" DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org EFD8420731 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=OG1btiM6RQ+MMJ0vVaHA+wJuqFOVIKApsm6IezIe8io=; b=QYHrJRp5wY0LzE a4gpLjLc7pGL1ZpjybbZLxpE6GZxSUccSv7pg4/sgIi7GlLT4EFEnLcAAQseNOro7nwsRUlcLsvtx NTRNITa3kkIlsU6xSoYNs7KDINiTewtX0uRGWg7H1nXKcoLsEsGbQ5DZFLaKoYjzk7D8GbvZKoSFO JjB1umxuCp7U5ZYCe2sPtsV9eF0YWTHCWnDpKD4V/lO6kVRnaE19cOk0EwhRrTCcysTNCisRhvwGQ UXSKMMXFUdF/a4H4v+k8OnzzphXBq2vI/krQti0ELD/NPnFmZiJFGPFrGaSoifLI5yDlgsBgnSJVh KHxuGVcd4YC80b27R+SQ==; 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 1iXmD9-00007o-1r; Thu, 21 Nov 2019 13:09:27 +0000 Received: from mailgw02.mediatek.com ([216.200.240.185]) by bombadil.infradead.org with esmtps (Exim 4.92.3 #3 (Red Hat Linux)) id 1iXmD5-00006n-QI; Thu, 21 Nov 2019 13:09:25 +0000 X-UUID: e8743b01cd844a68aa452d3cf31c6ac1-20191121 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=GKRpbk2ZaobBcrGmB5jVBprxNIO5Hbu7SfyTwGSrIKk=; b=K8JOzSEHkHL3MO8oyOwdXAKMIDqQpcxBEwEqlODopZEl7MFXIVymzFGDLqKxfOdWdz+LHf5P3vSb6Ev8xRUjc3ht/ru5qp7u3wwEn62wMugngeCHGIBNxYKJrFS3DSsAjRBqZ9xW9UcDmEt38gUd8ubGNI3FuTjP7915/GxBVws=; X-UUID: e8743b01cd844a68aa452d3cf31c6ac1-20191121 Received: from mtkcas66.mediatek.inc [(172.29.193.44)] by mailgw02.mediatek.com (envelope-from ) (musrelay.mediatek.com ESMTP with TLS) with ESMTP id 2052480214; Thu, 21 Nov 2019 05:09:16 -0800 Received: from MTKMBS07N2.mediatek.inc (172.21.101.141) by MTKMBS62N1.mediatek.inc (172.29.193.41) with Microsoft SMTP Server (TLS) id 15.0.1395.4; Thu, 21 Nov 2019 05:09:35 -0800 Received: from mtkcas08.mediatek.inc (172.21.101.126) by mtkmbs07n2.mediatek.inc (172.21.101.141) with Microsoft SMTP Server (TLS) id 15.0.1395.4; Thu, 21 Nov 2019 21:09:07 +0800 Received: from [172.21.84.99] (172.21.84.99) by mtkcas08.mediatek.inc (172.21.101.73) with Microsoft SMTP Server id 15.0.1395.4 via Frontend Transport; Thu, 21 Nov 2019 21:09:08 +0800 Message-ID: <1574341753.8338.7.camel@mtksdccf07> Subject: Re: [PATCH v4 1/2] kasan: detect negative size in memory operation function From: Walter Wu To: Andrey Ryabinin Date: Thu, 21 Nov 2019 21:09:13 +0800 In-Reply-To: <217bd537-e6b7-3acc-b6bb-ac9c5d94da89@virtuozzo.com> References: <20191112065302.7015-1-walter-zh.wu@mediatek.com> <040479c3-6f96-91c6-1b1a-9f3e947dac06@virtuozzo.com> <1574341376.8338.4.camel@mtksdccf07> <217bd537-e6b7-3acc-b6bb-ac9c5d94da89@virtuozzo.com> 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-20191121_050923_858103_04A527F1 X-CRM114-Status: GOOD ( 10.69 ) 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: wsd_upstream , linux-kernel@vger.kernel.org, kasan-dev@googlegroups.com, linux-mm@kvack.org, Alexander Potapenko , linux-arm-kernel@lists.infradead.org, Matthias Brugger , linux-mediatek@lists.infradead.org, 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 Thu, 2019-11-21 at 16:03 +0300, Andrey Ryabinin wrote: > > On 11/21/19 4:02 PM, Walter Wu wrote: > > On Thu, 2019-11-21 at 15:26 +0300, Andrey Ryabinin wrote: > >> > >> On 11/12/19 9:53 AM, Walter Wu wrote: > >> > >>> diff --git a/mm/kasan/common.c b/mm/kasan/common.c > >>> index 6814d6d6a023..4bfce0af881f 100644 > >>> --- a/mm/kasan/common.c > >>> +++ b/mm/kasan/common.c > >>> @@ -102,7 +102,8 @@ EXPORT_SYMBOL(__kasan_check_write); > >>> #undef memset > >>> void *memset(void *addr, int c, size_t len) > >>> { > >>> - check_memory_region((unsigned long)addr, len, true, _RET_IP_); > >>> + if (!check_memory_region((unsigned long)addr, len, true, _RET_IP_)) > >>> + return NULL; > >>> > >>> return __memset(addr, c, len); > >>> } > >>> @@ -110,8 +111,9 @@ void *memset(void *addr, int c, size_t len) > >>> #undef memmove > >>> void *memmove(void *dest, const void *src, size_t len) > >>> { > >>> - check_memory_region((unsigned long)src, len, false, _RET_IP_); > >>> - check_memory_region((unsigned long)dest, len, true, _RET_IP_); > >>> + if (!check_memory_region((unsigned long)src, len, false, _RET_IP_) || > >>> + !check_memory_region((unsigned long)dest, len, true, _RET_IP_)) > >>> + return NULL; > >>> > >>> return __memmove(dest, src, len); > >>> } > >>> @@ -119,8 +121,9 @@ void *memmove(void *dest, const void *src, size_t len) > >>> #undef memcpy > >>> void *memcpy(void *dest, const void *src, size_t len) > >>> { > >>> - check_memory_region((unsigned long)src, len, false, _RET_IP_); > >>> - check_memory_region((unsigned long)dest, len, true, _RET_IP_); > >>> + if (!check_memory_region((unsigned long)src, len, false, _RET_IP_) || > >>> + !check_memory_region((unsigned long)dest, len, true, _RET_IP_)) > >>> + return NULL; > >>> > >> > >> I realized that we are going a wrong direction here. Entirely skipping mem*() operation on any > >> poisoned shadow value might only make things worse. Some bugs just don't have any serious consequences, > >> but skipping the mem*() ops entirely might introduce such consequences, which wouldn't happen otherwise. > >> > >> So let's keep this code as this, no need to check the result of check_memory_region(). > >> > >> > > Ok, we just need to determine whether size is negative number. If yes > > then KASAN produce report and continue to execute mem*(). right? > > > > Yes. Thanks for your suggestion. I will send a new v5 patch tomorrow. Walter _______________________________________________ linux-arm-kernel mailing list linux-arm-kernel@lists.infradead.org http://lists.infradead.org/mailman/listinfo/linux-arm-kernel