From patchwork Thu Mar 28 15:00:16 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Christophe Leroy X-Patchwork-Id: 10875087 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id 24DEF922 for ; Thu, 28 Mar 2019 15:00:26 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 0F06F28CC4 for ; Thu, 28 Mar 2019 15:00:26 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 0335C28D42; Thu, 28 Mar 2019 15:00:25 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-3.0 required=2.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,MAILING_LIST_MULTI,RCVD_IN_DNSWL_NONE autolearn=ham version=3.3.1 Received: from kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id DF3B128CC4 for ; Thu, 28 Mar 2019 15:00:21 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id CA8E66B0006; Thu, 28 Mar 2019 11:00:20 -0400 (EDT) Delivered-To: linux-mm-outgoing@kvack.org Received: by kanga.kvack.org (Postfix, from userid 40) id C57416B0007; Thu, 28 Mar 2019 11:00:20 -0400 (EDT) X-Original-To: int-list-linux-mm@kvack.org X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id B46E06B0008; Thu, 28 Mar 2019 11:00:20 -0400 (EDT) X-Original-To: linux-mm@kvack.org X-Delivered-To: linux-mm@kvack.org Received: from mail-wm1-f69.google.com (mail-wm1-f69.google.com [209.85.128.69]) by kanga.kvack.org (Postfix) with ESMTP id 662D56B0006 for ; Thu, 28 Mar 2019 11:00:20 -0400 (EDT) Received: by mail-wm1-f69.google.com with SMTP id 187so3931912wmc.1 for ; Thu, 28 Mar 2019 08:00:20 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:dkim-signature:message-id:from:subject:to:cc :date; bh=T+J229KlSwmDE+sECLswESBH4a6GRbtFc9G5p7ym4qU=; b=pneael/4mA1Z6yoHm3Ab3WeAq5VvEwsCB5eSkXQ3zP+0lhxGUcUeroqG/pDv+5dJKo HKWkZfTLjCEIL8fWqhxsE+eCLTHPP/5JwadMFWKDjgK45s49T9gXRLc91KqcKx9S5tOB d68sLRGG2h1r85tuDis4g1ZNGT0mRu88RfdjfTBcd/Lpb+ZhExa/cW/5sQfpk0Wkj924 q3dJNjUfI+HdEseSrnlAL5IXxDq3Jc4jwVnPYO3Z63TKvnf4mDXMxQ+dzi+3qptyrQ3c 50s+nHR95UWGbVhy2oY0133fn09xPPuUi8sNepsP6nu/yLaVxQRTdbASLjbdOyvSc4ac pT2A== X-Gm-Message-State: APjAAAXMrrlMymcp6OmcL4Ophvh+8y+RQdQ23q5bSZEOjUOJd2YT1Fi4 TXPnchxcBvVDTiWKeTSBUYAKeS0Sc8R0CbTd1IiMgWL5bGZuEsRHZfsn1rlSMHaXPGj0x+Xf7bq rpvbR70rMWuSxqddiLSWKypNiLeVX9fCU2iCBxXbu/mjuPxp92j8X5ZqInKm7m9XEkg== X-Received: by 2002:a7b:c309:: with SMTP id k9mr271320wmj.139.1553785219923; Thu, 28 Mar 2019 08:00:19 -0700 (PDT) X-Google-Smtp-Source: APXvYqyyybg3QkH1MjU3eN6Xaz6FJPRlYJIB5iZq+IYmWuC2iy5MGNQkmJmTUN+oFI1nj0nC8Anu X-Received: by 2002:a7b:c309:: with SMTP id k9mr271230wmj.139.1553785218496; Thu, 28 Mar 2019 08:00:18 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1553785218; cv=none; d=google.com; s=arc-20160816; b=k3nxoIQWdkcx2Td0xMPGbsjjwcOlo+ZYHQYndKbXIT4aDISNcHOaWf3/FCOohIKu9X XgsqEMi1nnyPCcl1XzupJl1eLQQHwvMkgKeK1XR95mTVRz7DFNsSao/BbJ3HTQHX2/L+ AmAS63Ij8qbF6uQBeRipK0sbmVJ6qQh0cqb91c4IeRiXI2mdynCSB6Xz5nHTftViByAk 2gFfNRZodGANU491UOGJdx0MFE7t0M870s77K+zZ6bDrjQcJ0Qv17qvpEXqatkjIG6xm lXKqykxDdSVsuv5Xrcu7N7V/MZnrTEDpMYPRlK4SzwvnJHsTW9H1QFeyjZOn4ImBwuMC QOvw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=date:cc:to:subject:from:message-id:dkim-signature; bh=T+J229KlSwmDE+sECLswESBH4a6GRbtFc9G5p7ym4qU=; b=G+rkSXo4D2zs+8zo7rvXFsWQT1fCADBuZxHdm65x5maDXj928Uluo5fHVOCUPAH28O +BFfK8rfcerv6MAh1UmRQAI5pJj8VEdjms0+InuRpf6eSBrJIDi9vKeYB1GPxWdi0VBK odtNf/UCZVncAQsFsn3dsBe/QDkh9Pwj0ZcI8bK2yWn8kcpy05Dku+zYNOvhtZQAR8qX j8QB28ryBMWI17iI4tOUqU6rrmcvEMOejh1a/ipg/5fxhh2algiZ0jKEJQ0KEPJ5NUnj /l/4deR6gntagtX01sWy2swC+2EFMaj9bb4LqdHMv5X+rUPpdEt7aVWUd0IZ2EYVJArT UmvQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@c-s.fr header.s=mail header.b=FriXieDa; spf=pass (google.com: domain of christophe.leroy@c-s.fr designates 93.17.236.30 as permitted sender) smtp.mailfrom=christophe.leroy@c-s.fr Received: from pegase1.c-s.fr (pegase1.c-s.fr. [93.17.236.30]) by mx.google.com with ESMTPS id s133si1977890wme.164.2019.03.28.08.00.18 for (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Thu, 28 Mar 2019 08:00:18 -0700 (PDT) Received-SPF: pass (google.com: domain of christophe.leroy@c-s.fr designates 93.17.236.30 as permitted sender) client-ip=93.17.236.30; Authentication-Results: mx.google.com; dkim=pass header.i=@c-s.fr header.s=mail header.b=FriXieDa; spf=pass (google.com: domain of christophe.leroy@c-s.fr designates 93.17.236.30 as permitted sender) smtp.mailfrom=christophe.leroy@c-s.fr Received: from localhost (mailhub1-int [192.168.12.234]) by localhost (Postfix) with ESMTP id 44VShw3Sq9z9v2Hd; Thu, 28 Mar 2019 16:00:16 +0100 (CET) Authentication-Results: localhost; dkim=pass reason="1024-bit key; insecure key" header.d=c-s.fr header.i=@c-s.fr header.b=FriXieDa; dkim-adsp=pass; dkim-atps=neutral X-Virus-Scanned: Debian amavisd-new at c-s.fr Received: from pegase1.c-s.fr ([192.168.12.234]) by localhost (pegase1.c-s.fr [192.168.12.234]) (amavisd-new, port 10024) with ESMTP id ZDF9MEr-EH3G; Thu, 28 Mar 2019 16:00:16 +0100 (CET) Received: from messagerie.si.c-s.fr (messagerie.si.c-s.fr [192.168.25.192]) by pegase1.c-s.fr (Postfix) with ESMTP id 44VShw2C2Bz9v2HP; Thu, 28 Mar 2019 16:00:16 +0100 (CET) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=c-s.fr; s=mail; t=1553785216; bh=T+J229KlSwmDE+sECLswESBH4a6GRbtFc9G5p7ym4qU=; h=From:Subject:To:Cc:Date:From; b=FriXieDaYZYFCgEwwz6EiADVaeeRtqV6w8F7LRDUsr0QB/roc/vF55BaP6X/vwVRE CRRNP0EARS2ndxDIxNXsu5DTu1jJPkxeNYCFJhyR2JlO5gUwZ4XzRSY0dgqV6u/CAJ NVeqw9du4IMVXMpsmflMfg+VWdLL3CyeaZiXoSk0= Received: from localhost (localhost [127.0.0.1]) by messagerie.si.c-s.fr (Postfix) with ESMTP id 969DC8B924; Thu, 28 Mar 2019 16:00:17 +0100 (CET) X-Virus-Scanned: amavisd-new at c-s.fr Received: from messagerie.si.c-s.fr ([127.0.0.1]) by localhost (messagerie.si.c-s.fr [127.0.0.1]) (amavisd-new, port 10023) with ESMTP id FZGcjbU8hIEW; Thu, 28 Mar 2019 16:00:17 +0100 (CET) Received: from po16846vm.idsi0.si.c-s.fr (unknown [192.168.4.90]) by messagerie.si.c-s.fr (Postfix) with ESMTP id 486128B923; Thu, 28 Mar 2019 16:00:17 +0100 (CET) Received: by po16846vm.idsi0.si.c-s.fr (Postfix, from userid 0) id 0DD3E6FC84; Thu, 28 Mar 2019 15:00:16 +0000 (UTC) Message-Id: From: Christophe Leroy Subject: [RFC PATCH v2 1/3] kasan: move memset/memmove/memcpy interceptors in a dedicated file To: Benjamin Herrenschmidt , Paul Mackerras , Michael Ellerman , Nicholas Piggin , Aneesh Kumar K.V , Andrey Ryabinin , Alexander Potapenko , Dmitry Vyukov , Daniel Axtens Cc: linux-kernel@vger.kernel.org, linuxppc-dev@lists.ozlabs.org, kasan-dev@googlegroups.com, linux-mm@kvack.org Date: Thu, 28 Mar 2019 15:00:16 +0000 (UTC) X-Bogosity: Ham, tests=bogofilter, spamicity=0.000000, version=1.2.4 Sender: owner-linux-mm@kvack.org Precedence: bulk X-Loop: owner-majordomo@kvack.org List-ID: X-Virus-Scanned: ClamAV using ClamSMTP In preparation of the addition of interceptors for other string functions, this patch moves memset/memmove/memcpy interceptions in string.c Signed-off-by: Christophe Leroy --- v2: added missing includes mm/kasan/Makefile | 5 ++++- mm/kasan/common.c | 26 -------------------------- mm/kasan/string.c | 54 ++++++++++++++++++++++++++++++++++++++++++++++++++++++ 3 files changed, 58 insertions(+), 27 deletions(-) create mode 100644 mm/kasan/string.c diff --git a/mm/kasan/Makefile b/mm/kasan/Makefile index 5d1065efbd47..85e91e301404 100644 --- a/mm/kasan/Makefile +++ b/mm/kasan/Makefile @@ -1,11 +1,13 @@ # SPDX-License-Identifier: GPL-2.0 KASAN_SANITIZE := n UBSAN_SANITIZE_common.o := n +UBSAN_SANITIZE_string.o := n UBSAN_SANITIZE_generic.o := n UBSAN_SANITIZE_tags.o := n KCOV_INSTRUMENT := n CFLAGS_REMOVE_common.o = -pg +CFLAGS_REMOVE_string.o = -pg CFLAGS_REMOVE_generic.o = -pg CFLAGS_REMOVE_tags.o = -pg @@ -13,9 +15,10 @@ CFLAGS_REMOVE_tags.o = -pg # see: https://gcc.gnu.org/bugzilla/show_bug.cgi?id=63533 CFLAGS_common.o := $(call cc-option, -fno-conserve-stack -fno-stack-protector) +CFLAGS_string.o := $(call cc-option, -fno-conserve-stack -fno-stack-protector) CFLAGS_generic.o := $(call cc-option, -fno-conserve-stack -fno-stack-protector) CFLAGS_tags.o := $(call cc-option, -fno-conserve-stack -fno-stack-protector) -obj-$(CONFIG_KASAN) := common.o init.o report.o +obj-$(CONFIG_KASAN) := common.o init.o report.o string.o obj-$(CONFIG_KASAN_GENERIC) += generic.o generic_report.o quarantine.o obj-$(CONFIG_KASAN_SW_TAGS) += tags.o tags_report.o diff --git a/mm/kasan/common.c b/mm/kasan/common.c index 80bbe62b16cd..3b94f484bf78 100644 --- a/mm/kasan/common.c +++ b/mm/kasan/common.c @@ -109,32 +109,6 @@ void kasan_check_write(const volatile void *p, unsigned int size) } 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_); - - return __memset(addr, c, 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_); - - return __memmove(dest, src, 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_); - - return __memcpy(dest, src, len); -} - /* * Poisons the shadow memory for 'size' bytes starting from 'addr'. * Memory addresses should be aligned to KASAN_SHADOW_SCALE_SIZE. diff --git a/mm/kasan/string.c b/mm/kasan/string.c new file mode 100644 index 000000000000..083b967255a2 --- /dev/null +++ b/mm/kasan/string.c @@ -0,0 +1,54 @@ +// SPDX-License-Identifier: GPL-2.0 +/* + * This file contains strings functions for KASAN + * + */ + +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include + +#include "kasan.h" + +#undef memset +void *memset(void *addr, int c, size_t len) +{ + check_memory_region((unsigned long)addr, len, true, _RET_IP_); + + return __memset(addr, c, 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_); + + return __memmove(dest, src, 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_); + + return __memcpy(dest, src, len); +} From patchwork Thu Mar 28 15:00:18 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Christophe Leroy X-Patchwork-Id: 10875089 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id 54A91922 for ; Thu, 28 Mar 2019 15:00:29 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 4169028B9C for ; Thu, 28 Mar 2019 15:00:29 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 35BB528D7F; Thu, 28 Mar 2019 15:00:29 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-3.0 required=2.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,MAILING_LIST_MULTI,RCVD_IN_DNSWL_NONE autolearn=ham version=3.3.1 Received: from kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id D39B028B9C for ; Thu, 28 Mar 2019 15:00:24 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id B74326B0007; Thu, 28 Mar 2019 11:00:21 -0400 (EDT) Delivered-To: linux-mm-outgoing@kvack.org Received: by kanga.kvack.org (Postfix, from userid 40) id AF74F6B0008; Thu, 28 Mar 2019 11:00:21 -0400 (EDT) X-Original-To: int-list-linux-mm@kvack.org X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 9C04E6B000A; Thu, 28 Mar 2019 11:00:21 -0400 (EDT) X-Original-To: linux-mm@kvack.org X-Delivered-To: linux-mm@kvack.org Received: from mail-wr1-f72.google.com (mail-wr1-f72.google.com [209.85.221.72]) by kanga.kvack.org (Postfix) with ESMTP id 4B20A6B0007 for ; Thu, 28 Mar 2019 11:00:21 -0400 (EDT) Received: by mail-wr1-f72.google.com with SMTP id u18so9307068wrp.19 for ; Thu, 28 Mar 2019 08:00:21 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:dkim-signature:message-id:in-reply-to:references :from:subject:to:cc:date; bh=wvpTucTNUo5TPeOa8kyd7/Y99PlFK6jfFJo0+kyHjCQ=; b=SV51U1t+smZyL0qOe/sLsgAdc/PquJMUBUHM5VUEHhSIfTM6F5cRLOtVuthhtU18Kb OZM4LAURNksUm08OGSkPXowh/CWhEPANhxvB8ozux4MGtUF3aljStOdmkfX3tj0Gx/ko FPh3i5MEkHIfx64sapj+X7rG8KlV6hxT5ID1VirMTEyRwUrbwGU6ACuLMmfBgNPTSc/p V9DSTGiLCxdkwRe9PYAzIjFACPT+gxbOL8INR1nM6jI4wkPkwsNQTs1cnkzyYz9E6oC5 HoABe6EI9EWfnwEqCy6wStzPY7L+4XDVJbko2DaNKvE48CnTeO3jAjcrI0bamSSWcXxd 5ttg== X-Gm-Message-State: APjAAAViemw98I3qmxyZ4RxLzdIFqpikDU34VCICKRtTHa5km3WrvmgE 9nOZnzVR3HJsn5B5lJ6MTW2ITTuO+Ug/bo+5yA85WvesluwyzcTfVuQwiiBvCXcAEBd9mLeQ08/ rGUc5BEwo2bK6Q4ohs/hWtxSbc7aczkcvJnxVPaK0hDH2MwkreRZyJa709iaaeVT+Yw== X-Received: by 2002:a7b:c00e:: with SMTP id c14mr292786wmb.110.1553785220724; Thu, 28 Mar 2019 08:00:20 -0700 (PDT) X-Google-Smtp-Source: APXvYqyyycmw7/EjhNp5tqPHQpZESdgN3qR9DzAcHnBC9V7vOVx7gF5vBET29uaBszOn7IenogL5 X-Received: by 2002:a7b:c00e:: with SMTP id c14mr292710wmb.110.1553785219460; Thu, 28 Mar 2019 08:00:19 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1553785219; cv=none; d=google.com; s=arc-20160816; b=x/wYnB3C0JhAAp+WdxBFoyd9w2pVGloPlRSVRtl0kNtJJSyWzui5SYXQ9Gf2Db+9iJ 2ooanxnRMoVc6kFIzK3VQwM7VwVkapTAM6IZXRfX54B6OoorGNJ2xrIqszZEMU/6MrYr +T8jVPfI4eTiivNXzN2Tu8xca6KU0mxOr2Af5cvtJOsxrjGNatX1OxXSoLvvNOs8/QR+ GMoQlcu1TBeB9WxLz3JoY1PEPnvp4dCYllZbAMrRvKnmIfmYEz5GfQMs2yTlbMH7UM81 Xz5yjlphEdgHZAxBD3/hVBtXgaJz+/S4ak0vzOaZaRIacjX0dyCE7RegJVuytBibjih4 +bwQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=date:cc:to:subject:from:references:in-reply-to:message-id :dkim-signature; bh=wvpTucTNUo5TPeOa8kyd7/Y99PlFK6jfFJo0+kyHjCQ=; b=xSdmAS0Zq8aZQ1w2pp/VeDWZ3LhScly1jg1mnoa4jr0JI52n6GQmheHAgKnOLPOusx O/oMyX7+t/ZZUKDdR/zUcIJd9251X6vvJ/YtdgvwcElpZv7XSXzcRPtBUN2ct1vVuFyw z8pGb2I53hVtJ7IJnP5akiqpuUL0lRyizsDYSmCdaqFkjt8g2/o7W8dhke7hX8YMDlMj cOOvXTyBPqO7yJkA4PcC8igTpS2PVDW4GWQtNkbs09LQBPApAwUXG9viDnB61LKnarcs 9fHiBLyth8pepCAlhyIsZS5Shru7DxkLQRw0ryGugeYIu6AyEf+JGoEiKoNSHS7cKUxG 1UGA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@c-s.fr header.s=mail header.b=W6LsTVjH; spf=pass (google.com: domain of christophe.leroy@c-s.fr designates 93.17.236.30 as permitted sender) smtp.mailfrom=christophe.leroy@c-s.fr Received: from pegase1.c-s.fr (pegase1.c-s.fr. [93.17.236.30]) by mx.google.com with ESMTPS id c16si13069658wro.273.2019.03.28.08.00.19 for (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Thu, 28 Mar 2019 08:00:19 -0700 (PDT) Received-SPF: pass (google.com: domain of christophe.leroy@c-s.fr designates 93.17.236.30 as permitted sender) client-ip=93.17.236.30; Authentication-Results: mx.google.com; dkim=pass header.i=@c-s.fr header.s=mail header.b=W6LsTVjH; spf=pass (google.com: domain of christophe.leroy@c-s.fr designates 93.17.236.30 as permitted sender) smtp.mailfrom=christophe.leroy@c-s.fr Received: from localhost (mailhub1-int [192.168.12.234]) by localhost (Postfix) with ESMTP id 44VShx2vGFz9v2Hg; Thu, 28 Mar 2019 16:00:17 +0100 (CET) Authentication-Results: localhost; dkim=pass reason="1024-bit key; insecure key" header.d=c-s.fr header.i=@c-s.fr header.b=W6LsTVjH; dkim-adsp=pass; dkim-atps=neutral X-Virus-Scanned: Debian amavisd-new at c-s.fr Received: from pegase1.c-s.fr ([192.168.12.234]) by localhost (pegase1.c-s.fr [192.168.12.234]) (amavisd-new, port 10024) with ESMTP id K2HjoE25HR_r; Thu, 28 Mar 2019 16:00:17 +0100 (CET) Received: from messagerie.si.c-s.fr (messagerie.si.c-s.fr [192.168.25.192]) by pegase1.c-s.fr (Postfix) with ESMTP id 44VShx1Ktxz9v2HP; Thu, 28 Mar 2019 16:00:17 +0100 (CET) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=c-s.fr; s=mail; t=1553785217; bh=wvpTucTNUo5TPeOa8kyd7/Y99PlFK6jfFJo0+kyHjCQ=; h=In-Reply-To:References:From:Subject:To:Cc:Date:From; b=W6LsTVjHKr5KWIF4f5oiZ5nY3dlsndSmK/1nKns9QSFvcx3u4hN9TyMHgKFksONrT PIMKb+LUNfx3XIbLw7WkPYA1Kwu7QFREPjkUORDikvyBukG331e2sLeGeLMtV/7cDK IwtECME/Nz+/TnHnporAMm2Gkgoi9OHa98mKwwzY= Received: from localhost (localhost [127.0.0.1]) by messagerie.si.c-s.fr (Postfix) with ESMTP id 82CAD8B923; Thu, 28 Mar 2019 16:00:18 +0100 (CET) X-Virus-Scanned: amavisd-new at c-s.fr Received: from messagerie.si.c-s.fr ([127.0.0.1]) by localhost (messagerie.si.c-s.fr [127.0.0.1]) (amavisd-new, port 10023) with ESMTP id CE8y7EQb9ba3; Thu, 28 Mar 2019 16:00:18 +0100 (CET) Received: from po16846vm.idsi0.si.c-s.fr (unknown [192.168.4.90]) by messagerie.si.c-s.fr (Postfix) with ESMTP id 2EC518B91C; Thu, 28 Mar 2019 16:00:18 +0100 (CET) Received: by po16846vm.idsi0.si.c-s.fr (Postfix, from userid 0) id 05E3B6FC84; Thu, 28 Mar 2019 15:00:18 +0000 (UTC) Message-Id: In-Reply-To: References: From: Christophe Leroy Subject: [RFC PATCH v2 2/3] lib/string: move sysfs string functions out of string.c To: Benjamin Herrenschmidt , Paul Mackerras , Michael Ellerman , Nicholas Piggin , Aneesh Kumar K.V , Andrey Ryabinin , Alexander Potapenko , Dmitry Vyukov , Daniel Axtens Cc: linux-kernel@vger.kernel.org, linuxppc-dev@lists.ozlabs.org, kasan-dev@googlegroups.com, linux-mm@kvack.org Date: Thu, 28 Mar 2019 15:00:18 +0000 (UTC) X-Bogosity: Ham, tests=bogofilter, spamicity=0.000000, version=1.2.4 Sender: owner-linux-mm@kvack.org Precedence: bulk X-Loop: owner-majordomo@kvack.org List-ID: X-Virus-Scanned: ClamAV using ClamSMTP In order to implement interceptors for string functions, move higher level sysfs related string functions out of string.c This patch creates a new file named string_sysfs.c Signed-off-by: Christophe Leroy --- v2: restored sysfs_streq() which had been lost in the move. lib/Makefile | 3 +- lib/string.c | 79 ------------------------------------------------ lib/string_sysfs.c | 88 ++++++++++++++++++++++++++++++++++++++++++++++++++++++ 3 files changed, 90 insertions(+), 80 deletions(-) create mode 100644 lib/string_sysfs.c diff --git a/lib/Makefile b/lib/Makefile index 3b08673e8881..30b9b0bfbba9 100644 --- a/lib/Makefile +++ b/lib/Makefile @@ -12,12 +12,13 @@ endif # flaky coverage that is not a function of syscall inputs. For example, # rbtree can be global and individual rotations don't correlate with inputs. KCOV_INSTRUMENT_string.o := n +KCOV_INSTRUMENT_string_sysfs.o := n KCOV_INSTRUMENT_rbtree.o := n KCOV_INSTRUMENT_list_debug.o := n KCOV_INSTRUMENT_debugobjects.o := n KCOV_INSTRUMENT_dynamic_debug.o := n -lib-y := ctype.o string.o vsprintf.o cmdline.o \ +lib-y := ctype.o string.o string_sysfs.o vsprintf.o cmdline.o \ rbtree.o radix-tree.o timerqueue.o xarray.o \ idr.o int_sqrt.o extable.o \ sha1.o chacha.o irq_regs.o argv_split.o \ diff --git a/lib/string.c b/lib/string.c index 38e4ca08e757..f3886c5175ac 100644 --- a/lib/string.c +++ b/lib/string.c @@ -605,85 +605,6 @@ char *strsep(char **s, const char *ct) EXPORT_SYMBOL(strsep); #endif -/** - * sysfs_streq - return true if strings are equal, modulo trailing newline - * @s1: one string - * @s2: another string - * - * This routine returns true iff two strings are equal, treating both - * NUL and newline-then-NUL as equivalent string terminations. It's - * geared for use with sysfs input strings, which generally terminate - * with newlines but are compared against values without newlines. - */ -bool sysfs_streq(const char *s1, const char *s2) -{ - while (*s1 && *s1 == *s2) { - s1++; - s2++; - } - - if (*s1 == *s2) - return true; - if (!*s1 && *s2 == '\n' && !s2[1]) - return true; - if (*s1 == '\n' && !s1[1] && !*s2) - return true; - return false; -} -EXPORT_SYMBOL(sysfs_streq); - -/** - * match_string - matches given string in an array - * @array: array of strings - * @n: number of strings in the array or -1 for NULL terminated arrays - * @string: string to match with - * - * Return: - * index of a @string in the @array if matches, or %-EINVAL otherwise. - */ -int match_string(const char * const *array, size_t n, const char *string) -{ - int index; - const char *item; - - for (index = 0; index < n; index++) { - item = array[index]; - if (!item) - break; - if (!strcmp(item, string)) - return index; - } - - return -EINVAL; -} -EXPORT_SYMBOL(match_string); - -/** - * __sysfs_match_string - matches given string in an array - * @array: array of strings - * @n: number of strings in the array or -1 for NULL terminated arrays - * @str: string to match with - * - * Returns index of @str in the @array or -EINVAL, just like match_string(). - * Uses sysfs_streq instead of strcmp for matching. - */ -int __sysfs_match_string(const char * const *array, size_t n, const char *str) -{ - const char *item; - int index; - - for (index = 0; index < n; index++) { - item = array[index]; - if (!item) - break; - if (sysfs_streq(item, str)) - return index; - } - - return -EINVAL; -} -EXPORT_SYMBOL(__sysfs_match_string); - #ifndef __HAVE_ARCH_MEMSET /** * memset - Fill a region of memory with the given value diff --git a/lib/string_sysfs.c b/lib/string_sysfs.c new file mode 100644 index 000000000000..6c6bae70e6f7 --- /dev/null +++ b/lib/string_sysfs.c @@ -0,0 +1,88 @@ +// SPDX-License-Identifier: GPL-2.0 +/* + * stupid library routines for sysfs + * + */ + +#include +#include +#include + +/** + * sysfs_streq - return true if strings are equal, modulo trailing newline + * @s1: one string + * @s2: another string + * + * This routine returns true iff two strings are equal, treating both + * NUL and newline-then-NUL as equivalent string terminations. It's + * geared for use with sysfs input strings, which generally terminate + * with newlines but are compared against values without newlines. + */ +bool sysfs_streq(const char *s1, const char *s2) +{ + while (*s1 && *s1 == *s2) { + s1++; + s2++; + } + + if (*s1 == *s2) + return true; + if (!*s1 && *s2 == '\n' && !s2[1]) + return true; + if (*s1 == '\n' && !s1[1] && !*s2) + return true; + return false; +} +EXPORT_SYMBOL(sysfs_streq); + +/** + * match_string - matches given string in an array + * @array: array of strings + * @n: number of strings in the array or -1 for NULL terminated arrays + * @string: string to match with + * + * Return: + * index of a @string in the @array if matches, or %-EINVAL otherwise. + */ +int match_string(const char * const *array, size_t n, const char *string) +{ + int index; + const char *item; + + for (index = 0; index < n; index++) { + item = array[index]; + if (!item) + break; + if (!strcmp(item, string)) + return index; + } + + return -EINVAL; +} +EXPORT_SYMBOL(match_string); + +/** + * __sysfs_match_string - matches given string in an array + * @array: array of strings + * @n: number of strings in the array or -1 for NULL terminated arrays + * @str: string to match with + * + * Returns index of @str in the @array or -EINVAL, just like match_string(). + * Uses sysfs_streq instead of strcmp for matching. + */ +int __sysfs_match_string(const char * const *array, size_t n, const char *str) +{ + const char *item; + int index; + + for (index = 0; index < n; index++) { + item = array[index]; + if (!item) + break; + if (sysfs_streq(item, str)) + return index; + } + + return -EINVAL; +} +EXPORT_SYMBOL(__sysfs_match_string); From patchwork Thu Mar 28 15:00:19 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Christophe Leroy X-Patchwork-Id: 10875091 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id 82063922 for ; Thu, 28 Mar 2019 15:00:33 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 6D0FC28D8A for ; Thu, 28 Mar 2019 15:00:33 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 6116228B9C; Thu, 28 Mar 2019 15:00:33 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-3.0 required=2.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,MAILING_LIST_MULTI,RCVD_IN_DNSWL_NONE autolearn=ham version=3.3.1 Received: from kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id E6A8228D40 for ; Thu, 28 Mar 2019 15:00:28 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 8B1436B0008; Thu, 28 Mar 2019 11:00:23 -0400 (EDT) Delivered-To: linux-mm-outgoing@kvack.org Received: by kanga.kvack.org (Postfix, from userid 40) id 862C46B000A; Thu, 28 Mar 2019 11:00:23 -0400 (EDT) X-Original-To: int-list-linux-mm@kvack.org X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 72AF16B000C; Thu, 28 Mar 2019 11:00:23 -0400 (EDT) X-Original-To: linux-mm@kvack.org X-Delivered-To: linux-mm@kvack.org Received: from mail-wm1-f71.google.com (mail-wm1-f71.google.com [209.85.128.71]) by kanga.kvack.org (Postfix) with ESMTP id 050186B0008 for ; Thu, 28 Mar 2019 11:00:23 -0400 (EDT) Received: by mail-wm1-f71.google.com with SMTP id a206so1891128wmh.2 for ; Thu, 28 Mar 2019 08:00:22 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:dkim-signature:message-id:in-reply-to:references :from:subject:to:cc:date; bh=q9NT2Llm953rb4Q2ZgieB5DwdmFzg9pvg6k5+wKs1Pk=; b=DbAsVJX6JNa4IZ6sFVMVp1teUqXSTrI9Gt5BllfO1EFXfOY1Bm9+coD6TMJjQhCMP1 tquXr3JpHQFgLaDq0DWg1l/cUbHHGFPGc8G3tNRnStYhG87MzMe0tL/urKSvNi2fctMR pKGPN49SfHv9G+U/+iAU7ntm6K5Qv63am+V5cY2H1/Z03ZXEX+iKDlC15M8oOllnuAFF X3XR+SjBSkEtC4SfKbG3mw+MlQ+FyYySGn1qR6JrZjvXgpZlkpwk0jc+27MJv08phrz4 eNNIilVANlueN1+JaFbeLO0RA12zIGRvm8X5JyokwNu1rMlzCzivZkT1C07b4uJO9tr1 ICTg== X-Gm-Message-State: APjAAAV392dwmnkoXHXqazZ53pjrEwm0OGKDGzB2mMo3wYZQU/fqu8YF aQJnzfGpN+1GS0PRuOVND+8cnLUDaijPJp4+rVKwuzH6ptO1miMSfbxYhqQZet0cAi0Ulv5kzsC Wkgc3PLlNldYcmtEZ4hya3yczWvBc52IBpizVA19+07tVw/cAiEcEwf01s3QqNlwRbw== X-Received: by 2002:a1c:bd8b:: with SMTP id n133mr283196wmf.73.1553785222402; Thu, 28 Mar 2019 08:00:22 -0700 (PDT) X-Google-Smtp-Source: APXvYqz+SWjz9Fdv8O/S+CuFu5YO5eZ1aWJVnluNsAsyGlnMGhcg65dsJd6yEbHAR1xX1uCzTPca X-Received: by 2002:a1c:bd8b:: with SMTP id n133mr283083wmf.73.1553785220366; Thu, 28 Mar 2019 08:00:20 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1553785220; cv=none; d=google.com; s=arc-20160816; b=avfHFX1ngMyp5bi4dWEAzY3uOIW4x7cJGa259JWF9AT36+h24v7tldMzSHcCASbCVb 6rr74jcU2lSJDmuSP9h+42rNSRpMhjl9++HxSk5iWvdFi/7c8gCs4+2JN4PGNXpcQeLr WwD4o0xS/qXaanr9P4v1iI3U/hS3FNIxoIHQMtXau6yDwj3lsr9f9OWYw/UcJHOPX1He M29CrY503KYO2Ga8D96DFJhpf/eHfE/25c8dozo1WBQWsmKqVtIy4oH7PfM36VCItmXB c6AQsc5GDJqua3+Kx5kNxFRctE1/1wyLSkHaS/IL+7U3tbFbmehkksN2MYpSHhweGv/6 UB0w== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=date:cc:to:subject:from:references:in-reply-to:message-id :dkim-signature; bh=q9NT2Llm953rb4Q2ZgieB5DwdmFzg9pvg6k5+wKs1Pk=; b=wn/VN9E/iYNorU1T9j1vvHEhLJ3VN7AKZm0tWQ6c4JLhSYoIQo8uKLf4Z5vTNEIfHM seFLO08cXcnkihUoUHkjSoLMPfe8quzvV186jdRUaaj45KBMeEzCW5W9/2YeIuLu4csJ EY1oPO7zUuJOhwey/do91sUe+yc766EQNHZBKIUx2UR50NE9TLMo5cu4j23rQAI7RE6q S/bx09sn1aOdiX2dV1/Wy20Grnry2WT3abpaB9yn67h9qpc3zF4G+0NhXz6jdLV3U+PK 1Y9NDKZU8BC4JqroFRiHX9e4nKM9QD9aYlXS2162AQwMgXXu04X7SZ0ZUtScQktrUZoU fJgA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@c-s.fr header.s=mail header.b=ja91P3I0; spf=pass (google.com: domain of christophe.leroy@c-s.fr designates 93.17.236.30 as permitted sender) smtp.mailfrom=christophe.leroy@c-s.fr Received: from pegase1.c-s.fr (pegase1.c-s.fr. [93.17.236.30]) by mx.google.com with ESMTPS id d16si5491716wru.316.2019.03.28.08.00.20 for (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Thu, 28 Mar 2019 08:00:20 -0700 (PDT) Received-SPF: pass (google.com: domain of christophe.leroy@c-s.fr designates 93.17.236.30 as permitted sender) client-ip=93.17.236.30; Authentication-Results: mx.google.com; dkim=pass header.i=@c-s.fr header.s=mail header.b=ja91P3I0; spf=pass (google.com: domain of christophe.leroy@c-s.fr designates 93.17.236.30 as permitted sender) smtp.mailfrom=christophe.leroy@c-s.fr Received: from localhost (mailhub1-int [192.168.12.234]) by localhost (Postfix) with ESMTP id 44VShy2gDJz9v2Hj; Thu, 28 Mar 2019 16:00:18 +0100 (CET) Authentication-Results: localhost; dkim=pass reason="1024-bit key; insecure key" header.d=c-s.fr header.i=@c-s.fr header.b=ja91P3I0; dkim-adsp=pass; dkim-atps=neutral X-Virus-Scanned: Debian amavisd-new at c-s.fr Received: from pegase1.c-s.fr ([192.168.12.234]) by localhost (pegase1.c-s.fr [192.168.12.234]) (amavisd-new, port 10024) with ESMTP id i0zdvdNMqUVU; Thu, 28 Mar 2019 16:00:18 +0100 (CET) Received: from messagerie.si.c-s.fr (messagerie.si.c-s.fr [192.168.25.192]) by pegase1.c-s.fr (Postfix) with ESMTP id 44VShy1Djgz9v2HP; Thu, 28 Mar 2019 16:00:18 +0100 (CET) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=c-s.fr; s=mail; t=1553785218; bh=q9NT2Llm953rb4Q2ZgieB5DwdmFzg9pvg6k5+wKs1Pk=; h=In-Reply-To:References:From:Subject:To:Cc:Date:From; b=ja91P3I0DLiWITV5Z+cBccJVCMrjSdDJSJvN6mZ1oKbJUuijbEzEAmH/M0qj0+jPl CMKPf8bZK3eChaq02f3oiRpcXxlipsE3/1cAMv+wnwV1Lzu6ZN8HmV9Svq7Bl4vwa0 2XFG6gF5FtItjw+J9QB2Lt6qAieA0daOTAgY9i9M= Received: from localhost (localhost [127.0.0.1]) by messagerie.si.c-s.fr (Postfix) with ESMTP id 9186A8B923; Thu, 28 Mar 2019 16:00:19 +0100 (CET) X-Virus-Scanned: amavisd-new at c-s.fr Received: from messagerie.si.c-s.fr ([127.0.0.1]) by localhost (messagerie.si.c-s.fr [127.0.0.1]) (amavisd-new, port 10023) with ESMTP id CBK5Tgf_LUxV; Thu, 28 Mar 2019 16:00:19 +0100 (CET) Received: from po16846vm.idsi0.si.c-s.fr (unknown [192.168.4.90]) by messagerie.si.c-s.fr (Postfix) with ESMTP id 353A88B91C; Thu, 28 Mar 2019 16:00:19 +0100 (CET) Received: by po16846vm.idsi0.si.c-s.fr (Postfix, from userid 0) id 0B8CB6FC84; Thu, 28 Mar 2019 15:00:19 +0000 (UTC) Message-Id: <51a6d9d7185de310f37ccbd7e4ebfdd6c7e9791f.1553785020.git.christophe.leroy@c-s.fr> In-Reply-To: References: From: Christophe Leroy Subject: [RFC PATCH v2 3/3] kasan: add interceptors for all string functions To: Benjamin Herrenschmidt , Paul Mackerras , Michael Ellerman , Nicholas Piggin , Aneesh Kumar K.V , Andrey Ryabinin , Alexander Potapenko , Dmitry Vyukov , Daniel Axtens Cc: linux-kernel@vger.kernel.org, linuxppc-dev@lists.ozlabs.org, kasan-dev@googlegroups.com, linux-mm@kvack.org Date: Thu, 28 Mar 2019 15:00:19 +0000 (UTC) X-Bogosity: Ham, tests=bogofilter, spamicity=0.000000, version=1.2.4 Sender: owner-linux-mm@kvack.org Precedence: bulk X-Loop: owner-majordomo@kvack.org List-ID: X-Virus-Scanned: ClamAV using ClamSMTP In the same spirit as commit 393f203f5fd5 ("x86_64: kasan: add interceptors for memset/memmove/memcpy functions"), this patch adds interceptors for string manipulation functions so that we can compile lib/string.o without kasan support hence allow the string functions to also be used from places where kasan has to be disabled. Signed-off-by: Christophe Leroy --- v2: Fixed a few checkpatch stuff and added missing EXPORT_SYMBOL() and missing #undefs include/linux/string.h | 79 ++++++++++ lib/Makefile | 2 + lib/string.c | 8 + mm/kasan/string.c | 394 +++++++++++++++++++++++++++++++++++++++++++++++++ 4 files changed, 483 insertions(+) diff --git a/include/linux/string.h b/include/linux/string.h index 7927b875f80c..3d2aff2ed402 100644 --- a/include/linux/string.h +++ b/include/linux/string.h @@ -19,54 +19,117 @@ extern void *memdup_user_nul(const void __user *, size_t); */ #include +#if defined(CONFIG_KASAN) && !defined(__SANITIZE_ADDRESS__) +/* + * For files that are not instrumented (e.g. mm/slub.c) we + * should use not instrumented version of mem* functions. + */ +#define memset16 __memset16 +#define memset32 __memset32 +#define memset64 __memset64 +#define memzero_explicit __memzero_explicit +#define strcpy __strcpy +#define strncpy __strncpy +#define strlcpy __strlcpy +#define strscpy __strscpy +#define strcat __strcat +#define strncat __strncat +#define strlcat __strlcat +#define strcmp __strcmp +#define strncmp __strncmp +#define strcasecmp __strcasecmp +#define strncasecmp __strncasecmp +#define strchr __strchr +#define strchrnul __strchrnul +#define strrchr __strrchr +#define strnchr __strnchr +#define skip_spaces __skip_spaces +#define strim __strim +#define strstr __strstr +#define strnstr __strnstr +#define strlen __strlen +#define strnlen __strnlen +#define strpbrk __strpbrk +#define strsep __strsep +#define strspn __strspn +#define strcspn __strcspn +#define memscan __memscan +#define memcmp __memcmp +#define memchr __memchr +#define memchr_inv __memchr_inv +#define strreplace __strreplace + +#ifndef __NO_FORTIFY +#define __NO_FORTIFY /* FORTIFY_SOURCE uses __builtin_memcpy, etc. */ +#endif + +#endif + #ifndef __HAVE_ARCH_STRCPY extern char * strcpy(char *,const char *); +char *__strcpy(char *, const char *); #endif #ifndef __HAVE_ARCH_STRNCPY extern char * strncpy(char *,const char *, __kernel_size_t); +char *__strncpy(char *, const char *, __kernel_size_t); #endif #ifndef __HAVE_ARCH_STRLCPY size_t strlcpy(char *, const char *, size_t); +size_t __strlcpy(char *, const char *, size_t); #endif #ifndef __HAVE_ARCH_STRSCPY ssize_t strscpy(char *, const char *, size_t); +ssize_t __strscpy(char *, const char *, size_t); #endif #ifndef __HAVE_ARCH_STRCAT extern char * strcat(char *, const char *); +char *__strcat(char *, const char *); #endif #ifndef __HAVE_ARCH_STRNCAT extern char * strncat(char *, const char *, __kernel_size_t); +char *__strncat(char *, const char *, __kernel_size_t); #endif #ifndef __HAVE_ARCH_STRLCAT extern size_t strlcat(char *, const char *, __kernel_size_t); +size_t __strlcat(char *, const char *, __kernel_size_t); #endif #ifndef __HAVE_ARCH_STRCMP extern int strcmp(const char *,const char *); +int __strcmp(const char *, const char *); #endif #ifndef __HAVE_ARCH_STRNCMP extern int strncmp(const char *,const char *,__kernel_size_t); +int __strncmp(const char *, const char *, __kernel_size_t); #endif #ifndef __HAVE_ARCH_STRCASECMP extern int strcasecmp(const char *s1, const char *s2); +int __strcasecmp(const char *s1, const char *s2); #endif #ifndef __HAVE_ARCH_STRNCASECMP extern int strncasecmp(const char *s1, const char *s2, size_t n); +int __strncasecmp(const char *s1, const char *s2, size_t n); #endif #ifndef __HAVE_ARCH_STRCHR extern char * strchr(const char *,int); +char *__strchr(const char *, int); #endif #ifndef __HAVE_ARCH_STRCHRNUL extern char * strchrnul(const char *,int); +char *__strchrnul(const char *, int); #endif #ifndef __HAVE_ARCH_STRNCHR extern char * strnchr(const char *, size_t, int); +char *__strnchr(const char *, size_t, int); #endif #ifndef __HAVE_ARCH_STRRCHR extern char * strrchr(const char *,int); +char *__strrchr(const char *, int); #endif extern char * __must_check skip_spaces(const char *); +char * __must_check __skip_spaces(const char *); extern char *strim(char *); +char *__strim(char *); static inline __must_check char *strstrip(char *str) { @@ -75,27 +138,35 @@ static inline __must_check char *strstrip(char *str) #ifndef __HAVE_ARCH_STRSTR extern char * strstr(const char *, const char *); +char *__strstr(const char *, const char *); #endif #ifndef __HAVE_ARCH_STRNSTR extern char * strnstr(const char *, const char *, size_t); +char *__strnstr(const char *, const char *, size_t); #endif #ifndef __HAVE_ARCH_STRLEN extern __kernel_size_t strlen(const char *); +__kernel_size_t __strlen(const char *); #endif #ifndef __HAVE_ARCH_STRNLEN extern __kernel_size_t strnlen(const char *,__kernel_size_t); +__kernel_size_t __strnlen(const char *, __kernel_size_t); #endif #ifndef __HAVE_ARCH_STRPBRK extern char * strpbrk(const char *,const char *); +char *__strpbrk(const char *, const char *); #endif #ifndef __HAVE_ARCH_STRSEP extern char * strsep(char **,const char *); +char *__strsep(char **, const char *); #endif #ifndef __HAVE_ARCH_STRSPN extern __kernel_size_t strspn(const char *,const char *); +__kernel_size_t __strspn(const char *, const char *); #endif #ifndef __HAVE_ARCH_STRCSPN extern __kernel_size_t strcspn(const char *,const char *); +__kernel_size_t __strcspn(const char *, const char *); #endif #ifndef __HAVE_ARCH_MEMSET @@ -104,14 +175,17 @@ extern void * memset(void *,int,__kernel_size_t); #ifndef __HAVE_ARCH_MEMSET16 extern void *memset16(uint16_t *, uint16_t, __kernel_size_t); +void *__memset16(uint16_t *, uint16_t, __kernel_size_t); #endif #ifndef __HAVE_ARCH_MEMSET32 extern void *memset32(uint32_t *, uint32_t, __kernel_size_t); +void *__memset32(uint32_t *, uint32_t, __kernel_size_t); #endif #ifndef __HAVE_ARCH_MEMSET64 extern void *memset64(uint64_t *, uint64_t, __kernel_size_t); +void *__memset64(uint64_t *, uint64_t, __kernel_size_t); #endif static inline void *memset_l(unsigned long *p, unsigned long v, @@ -146,12 +220,15 @@ extern void * memmove(void *,const void *,__kernel_size_t); #endif #ifndef __HAVE_ARCH_MEMSCAN extern void * memscan(void *,int,__kernel_size_t); +void *__memscan(void *, int, __kernel_size_t); #endif #ifndef __HAVE_ARCH_MEMCMP extern int memcmp(const void *,const void *,__kernel_size_t); +int __memcmp(const void *, const void *, __kernel_size_t); #endif #ifndef __HAVE_ARCH_MEMCHR extern void * memchr(const void *,int,__kernel_size_t); +void *__memchr(const void *, int, __kernel_size_t); #endif #ifndef __HAVE_ARCH_MEMCPY_MCSAFE static inline __must_check unsigned long memcpy_mcsafe(void *dst, @@ -168,7 +245,9 @@ static inline void memcpy_flushcache(void *dst, const void *src, size_t cnt) } #endif void *memchr_inv(const void *s, int c, size_t n); +void *__memchr_inv(const void *s, int c, size_t n); char *strreplace(char *s, char old, char new); +char *__strreplace(char *s, char old, char new); extern void kfree_const(const void *x); diff --git a/lib/Makefile b/lib/Makefile index 30b9b0bfbba9..19d0237f9b9c 100644 --- a/lib/Makefile +++ b/lib/Makefile @@ -18,6 +18,8 @@ KCOV_INSTRUMENT_list_debug.o := n KCOV_INSTRUMENT_debugobjects.o := n KCOV_INSTRUMENT_dynamic_debug.o := n +KASAN_SANITIZE_string.o := n + lib-y := ctype.o string.o string_sysfs.o vsprintf.o cmdline.o \ rbtree.o radix-tree.o timerqueue.o xarray.o \ idr.o int_sqrt.o extable.o \ diff --git a/lib/string.c b/lib/string.c index f3886c5175ac..31a253201bba 100644 --- a/lib/string.c +++ b/lib/string.c @@ -85,7 +85,9 @@ EXPORT_SYMBOL(strcasecmp); * @dest: Where to copy the string to * @src: Where to copy the string from */ +#ifndef CONFIG_KASAN #undef strcpy +#endif char *strcpy(char *dest, const char *src) { char *tmp = dest; @@ -243,7 +245,9 @@ EXPORT_SYMBOL(strscpy); * @dest: The string to be appended to * @src: The string to append to it */ +#ifndef CONFIG_KASAN #undef strcat +#endif char *strcat(char *dest, const char *src) { char *tmp = dest; @@ -319,7 +323,9 @@ EXPORT_SYMBOL(strlcat); * @cs: One string * @ct: Another string */ +#ifndef CONFIG_KASAN #undef strcmp +#endif int strcmp(const char *cs, const char *ct) { unsigned char c1, c2; @@ -773,7 +779,9 @@ EXPORT_SYMBOL(memmove); * @ct: Another area of memory * @count: The size of the area. */ +#ifndef CONFIG_KASAN #undef memcmp +#endif __visible int memcmp(const void *cs, const void *ct, size_t count) { const unsigned char *su1, *su2; diff --git a/mm/kasan/string.c b/mm/kasan/string.c index 083b967255a2..0db31bbbf643 100644 --- a/mm/kasan/string.c +++ b/mm/kasan/string.c @@ -35,6 +35,42 @@ void *memset(void *addr, int c, size_t len) return __memset(addr, c, len); } +#undef memset16 +void *memset16(uint16_t *s, uint16_t v, size_t count) +{ + check_memory_region((unsigned long)s, count << 1, true, _RET_IP_); + + return __memset16(s, v, count); +} +EXPORT_SYMBOL(memset16); + +#undef memset32 +void *memset32(uint32_t *s, uint32_t v, size_t count) +{ + check_memory_region((unsigned long)s, count << 2, true, _RET_IP_); + + return __memset32(s, v, count); +} +EXPORT_SYMBOL(memset32); + +#undef memset64 +void *memset64(uint64_t *s, uint64_t v, size_t count) +{ + check_memory_region((unsigned long)s, count << 3, true, _RET_IP_); + + return __memset64(s, v, count); +} +EXPORT_SYMBOL(memset64); + +#undef memzero_explicit +void memzero_explicit(void *s, size_t count) +{ + check_memory_region((unsigned long)s, count, true, _RET_IP_); + + return __memzero_explicit(s, count); +} +EXPORT_SYMBOL(memzero_explicit); + #undef memmove void *memmove(void *dest, const void *src, size_t len) { @@ -52,3 +88,361 @@ void *memcpy(void *dest, const void *src, size_t len) return __memcpy(dest, src, len); } + +#undef strcpy +char *strcpy(char *dest, const char *src) +{ + size_t len = __strlen(src) + 1; + + check_memory_region((unsigned long)src, len, false, _RET_IP_); + check_memory_region((unsigned long)dest, len, true, _RET_IP_); + + return __strcpy(dest, src); +} +EXPORT_SYMBOL(strcpy); + +#undef strncpy +char *strncpy(char *dest, const char *src, size_t count) +{ + size_t len = min(__strlen(src) + 1, count); + + check_memory_region((unsigned long)src, len, false, _RET_IP_); + check_memory_region((unsigned long)dest, count, true, _RET_IP_); + + return __strncpy(dest, src, count); +} +EXPORT_SYMBOL(strncpy); + +#undef strlcpy +size_t strlcpy(char *dest, const char *src, size_t size) +{ + size_t len = __strlen(src) + 1; + + check_memory_region((unsigned long)src, len, false, _RET_IP_); + check_memory_region((unsigned long)dest, min(len, size), true, _RET_IP_); + + return __strlcpy(dest, src, size); +} +EXPORT_SYMBOL(strlcpy); + +#undef strscpy +ssize_t strscpy(char *dest, const char *src, size_t count) +{ + int len = min(__strlen(src) + 1, count); + + check_memory_region((unsigned long)src, len, false, _RET_IP_); + check_memory_region((unsigned long)dest, len, true, _RET_IP_); + + return __strscpy(dest, src, count); +} +EXPORT_SYMBOL(strscpy); + +#undef strcat +char *strcat(char *dest, const char *src) +{ + size_t slen = __strlen(src) + 1; + size_t dlen = __strlen(dest); + + check_memory_region((unsigned long)src, slen, false, _RET_IP_); + check_memory_region((unsigned long)dest, dlen, false, _RET_IP_); + check_memory_region((unsigned long)(dest + dlen), slen, true, _RET_IP_); + + return __strcat(dest, src); +} +EXPORT_SYMBOL(strcat); + +#undef strncat +char *strncat(char *dest, const char *src, size_t count) +{ + size_t slen = min(__strlen(src) + 1, count); + size_t dlen = __strlen(dest); + + check_memory_region((unsigned long)src, slen, false, _RET_IP_); + check_memory_region((unsigned long)dest, dlen, false, _RET_IP_); + check_memory_region((unsigned long)(dest + dlen), slen, true, _RET_IP_); + + return __strncat(dest, src, count); +} +EXPORT_SYMBOL(strncat); + +#undef strlcat +size_t strlcat(char *dest, const char *src, size_t count) +{ + size_t slen = min(__strlen(src) + 1, count); + size_t dlen = __strlen(dest); + + check_memory_region((unsigned long)src, slen, false, _RET_IP_); + check_memory_region((unsigned long)dest, dlen, false, _RET_IP_); + check_memory_region((unsigned long)(dest + dlen), slen, true, _RET_IP_); + + return __strlcat(dest, src, count); +} +EXPORT_SYMBOL(strlcat); + +#undef strcmp +int strcmp(const char *cs, const char *ct) +{ + size_t len = min(__strlen(cs) + 1, __strlen(ct) + 1); + + check_memory_region((unsigned long)cs, len, false, _RET_IP_); + check_memory_region((unsigned long)ct, len, false, _RET_IP_); + + return __strcmp(cs, ct); +} +EXPORT_SYMBOL(strcmp); + +#undef strncmp +int strncmp(const char *cs, const char *ct, size_t count) +{ + size_t len = min3(__strlen(cs) + 1, __strlen(ct) + 1, count); + + check_memory_region((unsigned long)cs, len, false, _RET_IP_); + check_memory_region((unsigned long)ct, len, false, _RET_IP_); + + return __strncmp(cs, ct, count); +} +EXPORT_SYMBOL(strncmp); + +#undef strcasecmp +int strcasecmp(const char *s1, const char *s2) +{ + size_t len = min(__strlen(s1) + 1, __strlen(s2) + 1); + + check_memory_region((unsigned long)s1, len, false, _RET_IP_); + check_memory_region((unsigned long)s2, len, false, _RET_IP_); + + return __strcasecmp(s1, s2); +} +EXPORT_SYMBOL(strcasecmp); + +#undef strncasecmp +int strncasecmp(const char *s1, const char *s2, size_t len) +{ + size_t sz = min3(__strlen(s1) + 1, __strlen(s2) + 1, len); + + check_memory_region((unsigned long)s1, sz, false, _RET_IP_); + check_memory_region((unsigned long)s2, sz, false, _RET_IP_); + + return __strncasecmp(s1, s2, len); +} +EXPORT_SYMBOL(strncasecmp); + +#undef strchr +char *strchr(const char *s, int c) +{ + size_t len = __strlen(s) + 1; + + check_memory_region((unsigned long)s, len, false, _RET_IP_); + + return __strchr(s, c); +} +EXPORT_SYMBOL(strchr); + +#undef strchrnul +char *strchrnul(const char *s, int c) +{ + size_t len = __strlen(s) + 1; + + check_memory_region((unsigned long)s, len, false, _RET_IP_); + + return __strchrnul(s, c); +} +EXPORT_SYMBOL(strchrnul); + +#undef strrchr +char *strrchr(const char *s, int c) +{ + size_t len = __strlen(s) + 1; + + check_memory_region((unsigned long)s, len, false, _RET_IP_); + + return __strrchr(s, c); +} +EXPORT_SYMBOL(strrchr); + +#undef strnchr +char *strnchr(const char *s, size_t count, int c) +{ + size_t len = __strlen(s) + 1; + + check_memory_region((unsigned long)s, len, false, _RET_IP_); + + return __strnchr(s, count, c); +} +EXPORT_SYMBOL(strnchr); + +#undef skip_spaces +char *skip_spaces(const char *str) +{ + size_t len = __strlen(str) + 1; + + check_memory_region((unsigned long)str, len, false, _RET_IP_); + + return __skip_spaces(str); +} +EXPORT_SYMBOL(skip_spaces); + +#undef strim +char *strim(char *s) +{ + size_t len = __strlen(s) + 1; + + check_memory_region((unsigned long)s, len, false, _RET_IP_); + + return __strim(s); +} +EXPORT_SYMBOL(strim); + +#undef strstr +char *strstr(const char *s1, const char *s2) +{ + size_t l1 = __strlen(s1) + 1; + size_t l2 = __strlen(s2) + 1; + + check_memory_region((unsigned long)s1, l1, false, _RET_IP_); + check_memory_region((unsigned long)s2, l2, false, _RET_IP_); + + return __strstr(s1, s2); +} +EXPORT_SYMBOL(strstr); + +#undef strnstr +char *strnstr(const char *s1, const char *s2, size_t len) +{ + size_t l1 = min(__strlen(s1) + 1, len); + size_t l2 = __strlen(s2) + 1; + + check_memory_region((unsigned long)s1, l1, false, _RET_IP_); + check_memory_region((unsigned long)s2, l2, false, _RET_IP_); + + return __strnstr(s1, s2, len); +} +EXPORT_SYMBOL(strnstr); + +#undef strlen +size_t strlen(const char *s) +{ + size_t len = __strlen(s); + + check_memory_region((unsigned long)s, len + 1, false, _RET_IP_); + + return len; +} +EXPORT_SYMBOL(strlen); + +#undef strnlen +size_t strnlen(const char *s, size_t count) +{ + size_t len = __strnlen(s, count); + + check_memory_region((unsigned long)s, min(len + 1, count), false, _RET_IP_); + + return len; +} +EXPORT_SYMBOL(strnlen); + +#undef strpbrk +char *strpbrk(const char *cs, const char *ct) +{ + size_t ls = __strlen(cs) + 1; + size_t lt = __strlen(ct) + 1; + + check_memory_region((unsigned long)cs, ls, false, _RET_IP_); + check_memory_region((unsigned long)ct, lt, false, _RET_IP_); + + return __strpbrk(cs, ct); +} +EXPORT_SYMBOL(strpbrk); + +#undef strsep +char *strsep(char **s, const char *ct) +{ + char *cs = *s; + + check_memory_region((unsigned long)s, sizeof(*s), true, _RET_IP_); + + if (cs) { + int ls = __strlen(cs) + 1; + int lt = __strlen(ct) + 1; + + check_memory_region((unsigned long)cs, ls, false, _RET_IP_); + check_memory_region((unsigned long)ct, lt, false, _RET_IP_); + } + + return __strsep(s, ct); +} +EXPORT_SYMBOL(strsep); + +#undef strspn +size_t strspn(const char *s, const char *accept) +{ + size_t ls = __strlen(s) + 1; + size_t la = __strlen(accept) + 1; + + check_memory_region((unsigned long)s, ls, false, _RET_IP_); + check_memory_region((unsigned long)accept, la, false, _RET_IP_); + + return __strspn(s, accept); +} +EXPORT_SYMBOL(strspn); + +#undef strcspn +size_t strcspn(const char *s, const char *reject) +{ + size_t ls = __strlen(s) + 1; + size_t lr = __strlen(reject) + 1; + + check_memory_region((unsigned long)s, ls, false, _RET_IP_); + check_memory_region((unsigned long)reject, lr, false, _RET_IP_); + + return __strcspn(s, reject); +} +EXPORT_SYMBOL(strcspn); + +#undef memscan +void *memscan(void *addr, int c, size_t size) +{ + check_memory_region((unsigned long)addr, size, false, _RET_IP_); + + return __memscan(addr, c, size); +} +EXPORT_SYMBOL(memscan); + +#undef memcmp +int memcmp(const void *cs, const void *ct, size_t count) +{ + check_memory_region((unsigned long)cs, count, false, _RET_IP_); + check_memory_region((unsigned long)ct, count, false, _RET_IP_); + + return __memcmp(cs, ct, count); +} +EXPORT_SYMBOL(memcmp); + +#undef memchr +void *memchr(const void *s, int c, size_t n) +{ + check_memory_region((unsigned long)s, n, false, _RET_IP_); + + return __memchr(s, c, n); +} +EXPORT_SYMBOL(memchr); + +#undef memchr_inv +void *memchr_inv(const void *start, int c, size_t bytes) +{ + check_memory_region((unsigned long)start, bytes, false, _RET_IP_); + + return __memchr_inv(start, c, bytes); +} +EXPORT_SYMBOL(memchr_inv); + +#undef strreplace +char *strreplace(char *s, char old, char new) +{ + size_t len = __strlen(s) + 1; + + check_memory_region((unsigned long)s, len, true, _RET_IP_); + + return __strreplace(s, old, new); +} +EXPORT_SYMBOL(strreplace);