From patchwork Fri Mar 22 14:00:05 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Christophe Leroy X-Patchwork-Id: 10865821 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 3240115AC for ; Fri, 22 Mar 2019 14:00:11 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 17D742A7DB for ; Fri, 22 Mar 2019 14:00:11 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 0C2912A7DF; Fri, 22 Mar 2019 14:00:11 +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 78E732A7DB for ; Fri, 22 Mar 2019 14:00:10 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 3CE136B0003; Fri, 22 Mar 2019 10:00:09 -0400 (EDT) Delivered-To: linux-mm-outgoing@kvack.org Received: by kanga.kvack.org (Postfix, from userid 40) id 37CDC6B0006; Fri, 22 Mar 2019 10:00:09 -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 246346B0007; Fri, 22 Mar 2019 10:00:09 -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 C86E16B0003 for ; Fri, 22 Mar 2019 10:00:08 -0400 (EDT) Received: by mail-wr1-f72.google.com with SMTP id y7so1077420wrq.4 for ; Fri, 22 Mar 2019 07:00:08 -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=l///YPAie6uypUB1yNuBRWNf9RJugCs+/QmoUcS6Zx0=; b=JCwIQ5RQuKDYFNLpx7A2jCijJGDuv3TDXvu3ImHUGAdpKmrTSPEltGjrtMK8U2cCwD 5IHHWNCXhy5MVvaHLcgrD2r5CIDT9Xruy9UFBNwGENJ+X1L6eL7SM5GswPUzcrJpm4mc mM4Dml/kG1HS78pvSeK2KJHo36CQ2V5ne9wwYKqOl+opLCAQgdTQZcGHW/VDcpM9gAaD hABdi9c38edEw3x4Os0BUdDbpgv2c2Cf8k0WEcriMP9M4au2xQ2ptqmEd+fWcxZ762/M LuCzBwAgltclVy5iVahYMrrMp5sPfNN6aHFgLam+yKQA7VK6gjtFyxmcNZ3HymEHXp3p GPFg== X-Gm-Message-State: APjAAAV1xuRuWa5Z5ge34mrKkM9EEwSvpxwLfDfPbUMRf8G/MVwvgA/6 /3JPIiWLBwOzWsxYy7S5Jg9caI2giMLgdt3PYMkSMcFbESZU8JXmkdM8h1h8P2MzhUOU2PhwjLH 1NvMn5QxKHgjXPXvAE+M5yS1C8gPWKhBXGZk3OPx16bKf/8I2koLyccgIbnEeZFFnMg== X-Received: by 2002:adf:f786:: with SMTP id q6mr6308810wrp.125.1553263208274; Fri, 22 Mar 2019 07:00:08 -0700 (PDT) X-Google-Smtp-Source: APXvYqwcorzaC7CLysNts21JYUTvVLvheqVrDZR0wQ2XTxwvW1XHb+0ePXL9FK78CKrDIPjqa8Ex X-Received: by 2002:adf:f786:: with SMTP id q6mr6308733wrp.125.1553263207208; Fri, 22 Mar 2019 07:00:07 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1553263207; cv=none; d=google.com; s=arc-20160816; b=gtq4dcDilguCYG1cCe5zczXgQsazM5plmMzLsVUx4GN2Px2296Nj/ESISPa2EVwT5Y Nwal81cCIwdsNs7O8xKK7rWwKaV6CqWGh4wsg+t9uKDzcKR20QTSUTHA+6k3/ok71WGb e1o/gbbc2mD7ufmQ3CPl5nOvo1VVNFse4mgJnUD+z3RWj1PQIk9XJBrmywbi0FstR4t+ GnO/H4G7fVXfLKfdZHKNwyKYcot1ge4iaxUeDrC4D0StDFC+JcBnHgB/bIJVzNyrYtjf sm6mlm6xvnC+HEXKWEuUZ3wk2CPo6XuRlHU2EeKvvs39MUUIyOb+eAqC8TaOfbZK5a3g rwuw== 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=l///YPAie6uypUB1yNuBRWNf9RJugCs+/QmoUcS6Zx0=; b=RoKH79G/bPMAPW22z3Cw+nipmwa98sTpmqCw1EifxXkkgNko9IqCN1yK9yQ5yE5Od/ rbdKK4jRM8rdDowzqQ/v26SOl3Ajap3554KrzW6eT/SichkdgIyPRUyPbBHOuh2zR+sm 4y96UKjqFPXzcKQdg8JvtVlpJLMJkBoHg6rEkPDgIMZeCJPOkKQQiKvY6jjPeQEIm36V GRhgE3pVuSlmvau4+rW+EWJrk8DI4DDSQX4q0/DLJ+LZMe0bQres0KJaRxr/M5hXR+aZ V7eHaFxWIXjz1YkbS04KhsjcAX9Fz65KSF7zmSp9TGYYXmy3WbEfX2qWfDbEnosYyMLt i8QA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@c-s.fr header.s=mail header.b=TVD3t75R; 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 s23si5362590wmc.62.2019.03.22.07.00.06 for (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Fri, 22 Mar 2019 07:00:07 -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=TVD3t75R; 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 44QlfD5myfz9tydW; Fri, 22 Mar 2019 15:00:04 +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=TVD3t75R; 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 xPLK5FWV0xo7; Fri, 22 Mar 2019 15:00:04 +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 44QlfD4bHHz9tydV; Fri, 22 Mar 2019 15:00:04 +0100 (CET) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=c-s.fr; s=mail; t=1553263204; bh=l///YPAie6uypUB1yNuBRWNf9RJugCs+/QmoUcS6Zx0=; h=From:Subject:To:Cc:Date:From; b=TVD3t75RzjncfGO+RukbpauQg6uI80vUDWLYyiU0cmGK2tADoEKMnA9EDqo4mH7SC xEU6OVubJ5ndZubeSwVVggp5Y2lHFaYTtoKgyA1BwNTPPi1ru6okwUD3vrIJJ4of9n NfTVntuDHQPZS/lEcJGozAj7O42qvByZ7/R2CgKI= Received: from localhost (localhost [127.0.0.1]) by messagerie.si.c-s.fr (Postfix) with ESMTP id 0F0388BB1B; Fri, 22 Mar 2019 15:00:06 +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 4Uyy-m5EOo7f; Fri, 22 Mar 2019 15:00:05 +0100 (CET) Received: from po16846vm.idsi0.si.c-s.fr (po15451.idsi0.si.c-s.fr [172.25.231.2]) by messagerie.si.c-s.fr (Postfix) with ESMTP id D1A368B848; Fri, 22 Mar 2019 15:00:05 +0100 (CET) Received: by po16846vm.idsi0.si.c-s.fr (Postfix, from userid 0) id ACA3C6CE54; Fri, 22 Mar 2019 14:00:05 +0000 (UTC) Message-Id: <45a5e13683694fc8d4574b52c4851ffb7f5e5fbd.1553263058.git.christophe.leroy@c-s.fr> From: Christophe Leroy Subject: [RFC PATCH v1 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: Fri, 22 Mar 2019 14:00:05 +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 --- mm/kasan/Makefile | 5 ++++- mm/kasan/common.c | 26 -------------------------- mm/kasan/string.c | 35 +++++++++++++++++++++++++++++++++++ 3 files changed, 39 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..f23a740ff985 --- /dev/null +++ b/mm/kasan/string.c @@ -0,0 +1,35 @@ +// SPDX-License-Identifier: GPL-2.0 +/* + * This file contains strings functions for KASAN + * + */ + +#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 Fri Mar 22 14:00:06 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Christophe Leroy X-Patchwork-Id: 10865825 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 21DDC139A for ; Fri, 22 Mar 2019 14:00:14 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 095582A7DD for ; Fri, 22 Mar 2019 14:00:14 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id F1D6D2A7E1; Fri, 22 Mar 2019 14:00:13 +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 4F75C2A7DD for ; Fri, 22 Mar 2019 14:00:13 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id A36306B0006; Fri, 22 Mar 2019 10:00:09 -0400 (EDT) Delivered-To: linux-mm-outgoing@kvack.org Received: by kanga.kvack.org (Postfix, from userid 40) id A0C386B0007; Fri, 22 Mar 2019 10:00:09 -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 8D4196B0008; Fri, 22 Mar 2019 10:00:09 -0400 (EDT) X-Original-To: linux-mm@kvack.org X-Delivered-To: linux-mm@kvack.org Received: from mail-wr1-f70.google.com (mail-wr1-f70.google.com [209.85.221.70]) by kanga.kvack.org (Postfix) with ESMTP id 3F79F6B0007 for ; Fri, 22 Mar 2019 10:00:09 -0400 (EDT) Received: by mail-wr1-f70.google.com with SMTP id x9so529984wrw.20 for ; Fri, 22 Mar 2019 07:00:09 -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=6pKbJUhzwfrOg+zuaOVcnvHacHuKUUR6Ss5vQGOV0qY=; b=OTzQw48ASdL1KayJoYH6PXBRd+aUwhsgCsoRbaUOsZJKpkh7/pv94i0pk8wirjoFmR HavQlGZSU5XtbGDShmVClW3QwSquYLDAiudVkvjeTbpDor03vtfFRFuBmdi2Gb4CEd6/ GjpLbZbgSiHseWtWnin+63qMUaPxLoBIEYprnPHFg5Uv0DsYHQTJg4aN2BWI3DuptHvf ikRSMsxonhXg670AlZOy/+NZjNRNiKhuMTFk6+P15xIW3UNZtK9x5X2x5idhxz5BoSKX tgokhQkhjUlbb/8Hx52UrQmyac79XsjxE+5BPAgXG1i1IRW6X22ZZIa+nfSSB8uQcV77 P8mQ== X-Gm-Message-State: APjAAAWLStkiyhTuGaCTMgPgwcqCTwqrD9p6JdJ+qGXvp9K8/IMweKmG twbobnF9wwwGGrxZKJSlYegf+GgSqmj608jkHx5U52T4sGM2I95gmiiT8MyMUR0wRgj3xiG6OBY IwMPjQWxIGM/K3wjBRzLowG3gIgJc5GPz9xY5upnFEfhzJtRBryLvYSMdHBCIDYDgSA== X-Received: by 2002:a7b:c044:: with SMTP id u4mr3364468wmc.88.1553263208690; Fri, 22 Mar 2019 07:00:08 -0700 (PDT) X-Google-Smtp-Source: APXvYqyf7mrSzhQR/uAostK6QvYDrVRwatagjFtZYfMzMZSENfqRA1OSnNJ7lRcWmAjh7j0d2ISd X-Received: by 2002:a7b:c044:: with SMTP id u4mr3364405wmc.88.1553263207612; Fri, 22 Mar 2019 07:00:07 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1553263207; cv=none; d=google.com; s=arc-20160816; b=rVS9CgkV3Wo3QSwkrwdo1k3WWz5rl0tGbYOIivjfpINUXFJV9VXDxxuAgPD7BRKxce ktPr1dTDezpf8C1ab6aMJ/N5IyyCSaW+S3j9ACpbOZmp3lXy5rpfoD5GqPfkn+red4XU D8G72zTR+X83SDiQqgMJ5ntXJPCdvtAYk1P2wKSsWX8fsYZwfREhX5dpRuZoy/MW2tRi gelD2QxcaTvMGi9ctMmpNL8hMmBgMYK32SQUGLEyrM+x8b8IxOzrRUd0FxwmjAFIi7fX mjtlJYMX62IgXK0Wy8Dk6UNB8bK80SqSsh+7HFEoyDSOZtjJIf6fIcLd1VO9hQJKqKF8 gcEQ== 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=6pKbJUhzwfrOg+zuaOVcnvHacHuKUUR6Ss5vQGOV0qY=; b=zWSmPOZJ6LjSWQfpWscnCJ8Hg+kikvHPZW3UkffcSiyw81I1RWUB6v8UNke+nawsaz FNbJt/jw3AAZiT4nfJsAX0Wb/uO4jioBMsuUppjQL4Utk/kg3T+OoBjnoh3jKIN9MK3l RZsVmJtRM1S95zpet48GQDRiDnaJ6O//D3xH/hD1Vm3kCfu5UyZhw4GfFnowuprE5eEK FYY4HFDTvPSbMSQWW8kAumnrUpNYtPS0YoW8tfsJlP1rLoCMDGsBskdsH8FH6ErVSEcd mQXe7Qu/sEfT6CLpCrq+shWHDemgmi0N6nTJqk8CBhpmj87iU84hq8DwLMsRCRAHKNZg 6+tw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@c-s.fr header.s=mail header.b=OqAGCDS8; 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 j9si2770844wrs.321.2019.03.22.07.00.07 for (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Fri, 22 Mar 2019 07:00:07 -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=OqAGCDS8; 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 44QlfF4wC3z9tydZ; Fri, 22 Mar 2019 15:00:05 +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=OqAGCDS8; 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 klewezSXLrDD; Fri, 22 Mar 2019 15:00:05 +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 44QlfF3hFLz9tydV; Fri, 22 Mar 2019 15:00:05 +0100 (CET) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=c-s.fr; s=mail; t=1553263205; bh=6pKbJUhzwfrOg+zuaOVcnvHacHuKUUR6Ss5vQGOV0qY=; h=In-Reply-To:References:From:Subject:To:Cc:Date:From; b=OqAGCDS8At6//wE2UY00XYmAziFxOQJEVJ9WW1SdQKvW4E8EZlSRAYu9nxM8Pw/zE Phv3ky+3ndMPsQsMkIi94DQqiS5PGXfjB6+60cyjXgcVQtZ5J8NTlieYZcI4/sWxYv bsei7Ywv12y/xVfh0P1q5895wfWrtJ58jqSH4njU= Received: from localhost (localhost [127.0.0.1]) by messagerie.si.c-s.fr (Postfix) with ESMTP id DDB448BB1E; Fri, 22 Mar 2019 15:00:06 +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 oQ8iRHHhZNZl; Fri, 22 Mar 2019 15:00:06 +0100 (CET) Received: from po16846vm.idsi0.si.c-s.fr (po15451.idsi0.si.c-s.fr [172.25.231.2]) by messagerie.si.c-s.fr (Postfix) with ESMTP id AA9B38B848; Fri, 22 Mar 2019 15:00:06 +0100 (CET) Received: by po16846vm.idsi0.si.c-s.fr (Postfix, from userid 0) id A27676CE54; Fri, 22 Mar 2019 14:00:06 +0000 (UTC) Message-Id: In-Reply-To: <45a5e13683694fc8d4574b52c4851ffb7f5e5fbd.1553263058.git.christophe.leroy@c-s.fr> References: <45a5e13683694fc8d4574b52c4851ffb7f5e5fbd.1553263058.git.christophe.leroy@c-s.fr> From: Christophe Leroy Subject: [RFC PATCH v1 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: Fri, 22 Mar 2019 14:00:06 +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 --- lib/Makefile | 3 ++- lib/string.c | 79 ------------------------------------------------------ lib/string_sysfs.c | 61 +++++++++++++++++++++++++++++++++++++++++ 3 files changed, 63 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..f2dd384be20d --- /dev/null +++ b/lib/string_sysfs.c @@ -0,0 +1,61 @@ +// SPDX-License-Identifier: GPL-2.0 +/* + * stupid library routines for sysfs + * + */ + +#include +#include +#include + +/** + * 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 Fri Mar 22 14:00:07 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Christophe Leroy X-Patchwork-Id: 10865827 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 8DC3C15AC for ; Fri, 22 Mar 2019 14:00:17 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 6D4A72A7DD for ; Fri, 22 Mar 2019 14:00:17 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 613762A7E2; Fri, 22 Mar 2019 14:00:17 +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 18A5D2A7DD for ; Fri, 22 Mar 2019 14:00:16 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 5F1966B0007; Fri, 22 Mar 2019 10:00:11 -0400 (EDT) Delivered-To: linux-mm-outgoing@kvack.org Received: by kanga.kvack.org (Postfix, from userid 40) id 5A1936B0008; Fri, 22 Mar 2019 10:00:11 -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 4433E6B000A; Fri, 22 Mar 2019 10:00:11 -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 D3D846B0007 for ; Fri, 22 Mar 2019 10:00:10 -0400 (EDT) Received: by mail-wm1-f69.google.com with SMTP id b133so590414wmg.7 for ; Fri, 22 Mar 2019 07:00:10 -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=CJiDtZpK8H5hjB+KPYUIhceGLlQqjCl3ug5QA7inh50=; b=kg+LbYNeS7bt8BoT4utsXicvSOZEfipz/fjzooGXpWKgF+XliRl8bth+jAxTM4F4AJ 5vgFers2bMcsSIoWK6pSsCKVunlZxULmhGImcajsst/HoqjFiydV8GsudSeNio+Gw6tN 7oCPMFLwcRqPQO9dQTfkxC8hI7CZzhXA3Hic6cGMhgxtUc/N66crCpSNic2yRAXn4Ip0 wJ+L+/4bhuJofF5opie2wLNUIdaw+pzZk1zlt95Yvti/YcUcSBWYNxdHs+plv2gi+PEi jceafG7R1cVoBjRn+s42SZUw1EEvxl23ZhJHCzUj0rhkJWfOb1PR15IM081WM5/FL5vr TiLg== X-Gm-Message-State: APjAAAU12MV6mST05Xr4Xkyw3duA2zHFiPVjKjlOL+zNCXX4xrf4qo6o xAi+2zUT4PaF4ve9U/HsTMx+m3IoXhZojd3Sb1NiT6bl26Lk006vOF1qEx6Sl3FMz1E20740n/N G7hmaA81eDcyXrmtrSNbUEywEtleeDOIIzt6g9o2YHI3CtKQqP6bsVyZ/wh0u/rrk2w== X-Received: by 2002:a7b:c769:: with SMTP id x9mr3289185wmk.103.1553263210290; Fri, 22 Mar 2019 07:00:10 -0700 (PDT) X-Google-Smtp-Source: APXvYqxStLw9QLIIfnv9SfZu3icZ5lucxXkh2LXUD9RqR5qq/z3xsKMTKsldfc5oU3eXF64Fqur6 X-Received: by 2002:a7b:c769:: with SMTP id x9mr3289088wmk.103.1553263208758; Fri, 22 Mar 2019 07:00:08 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1553263208; cv=none; d=google.com; s=arc-20160816; b=LuoqrhIkpMfn3BirFH8PLsnFZ9E4izn5F1h3pNH3MU2zJPBrsX2c9KOAtGtf5L9/S3 dpObonFEdilmAeYZ7LE7O1R7xix1CaAlN7re4uGkXsmv0R5+xrHMi9oUXkCneFzXQmQ6 fxTs08/I6ifAJyzEJOd+vPbQ8EgC9d5D0TtKUEME3YM8RuUAVLLV3k1R4neLTO06jTAk 6+jgMCaieaOhe2kTg5vnkzd9PYIds6lfhZCrKoYQYFtv0Rb6DxusfOpd7ZW9eyYs9tQx TUMqCrqGCdH8330KQGr+wEUO9AN9UWfVBtwnw59viniGdLANUbXLcmAuAsfEs62BBj6q HCaA== 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=CJiDtZpK8H5hjB+KPYUIhceGLlQqjCl3ug5QA7inh50=; b=CZZX7mfm6/CqSDhlilVDqoFkOhetqMWpmU3YmItOleu8Aouwgb6qhC5Ig5Y3LxD/Ka DOor5DR/uWEvR/IZKNFzkFPGsTs0riJT0bfQqtMyWhD49uqH2xRQN7OHODW3ZTRQg7gQ A/diQQ1bNU79klQUUKmggYeIcKG3AzRdUtsHvjqamxg0zVtQTsosdaMbiRmn/vERS79q V+CIKjVnUaGQiA5LdyQhxjgo5fvPbN6aeg7kGEoUJgGoRi9Zrobtp9ruZAqF4XaEXitK bF09+uf/5FEK9OD9aTLU4BdLd1RMqcXvsAt4yI7V6zr1PKfOplKVboLGpdK2IecbSC5G nryw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@c-s.fr header.s=mail header.b=jn+HRRQ2; 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 h7si5045981wru.58.2019.03.22.07.00.08 for (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Fri, 22 Mar 2019 07:00:08 -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=jn+HRRQ2; 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 44QlfG60Llz9tydX; Fri, 22 Mar 2019 15:00:06 +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=jn+HRRQ2; 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 N-Gfaqsg-HFZ; Fri, 22 Mar 2019 15:00:06 +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 44QlfG4lzjz9tydV; Fri, 22 Mar 2019 15:00:06 +0100 (CET) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=c-s.fr; s=mail; t=1553263206; bh=CJiDtZpK8H5hjB+KPYUIhceGLlQqjCl3ug5QA7inh50=; h=In-Reply-To:References:From:Subject:To:Cc:Date:From; b=jn+HRRQ2LeTrJM62w8zAfDxjmpTdEete5jM8mL5QlOnEluucDQLXE6ne0YShvYBg5 IdfKaNGInjswixPqOBw7FHuUpqom6ZhWn1G+WOtNyJwPTC5FYRktezsUDhq5UsObbH 4QghM/0tMpbQT/QqUiXkPKn30BTA/LXa5e6Qu3Xg= Received: from localhost (localhost [127.0.0.1]) by messagerie.si.c-s.fr (Postfix) with ESMTP id EA52D8BB1E; Fri, 22 Mar 2019 15:00:07 +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 lzf0JGiAYaV6; Fri, 22 Mar 2019 15:00:07 +0100 (CET) Received: from po16846vm.idsi0.si.c-s.fr (po15451.idsi0.si.c-s.fr [172.25.231.2]) by messagerie.si.c-s.fr (Postfix) with ESMTP id B343F8BB1B; Fri, 22 Mar 2019 15:00:07 +0100 (CET) Received: by po16846vm.idsi0.si.c-s.fr (Postfix, from userid 0) id A93C96CE54; Fri, 22 Mar 2019 14:00:07 +0000 (UTC) Message-Id: <59d08c6ce4a36cafdbf270360fb77d67995b2ab9.1553263058.git.christophe.leroy@c-s.fr> In-Reply-To: <45a5e13683694fc8d4574b52c4851ffb7f5e5fbd.1553263058.git.christophe.leroy@c-s.fr> References: <45a5e13683694fc8d4574b52c4851ffb7f5e5fbd.1553263058.git.christophe.leroy@c-s.fr> From: Christophe Leroy Subject: [RFC PATCH v1 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: Fri, 22 Mar 2019 14:00:07 +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 --- This is the generic part. If we agree on the principle, then I'll go through the arches and see if adaptations need to be done there. include/linux/string.h | 79 ++++++++++++ lib/Makefile | 2 + mm/kasan/string.c | 334 +++++++++++++++++++++++++++++++++++++++++++++++++ 3 files changed, 415 insertions(+) diff --git a/include/linux/string.h b/include/linux/string.h index 7927b875f80c..7e7441f4c420 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/mm/kasan/string.c b/mm/kasan/string.c index f23a740ff985..9a86b422e2e7 100644 --- a/mm/kasan/string.c +++ b/mm/kasan/string.c @@ -16,6 +16,38 @@ 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); +} + +#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); +} + +#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); +} + +#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); +} + #undef memmove void *memmove(void *dest, const void *src, size_t len) { @@ -33,3 +65,305 @@ 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); +} + +#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); +} + +#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); +} + +#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); +} + +#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); +} + +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); +} + +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); +} + +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); +} + +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); +} + +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); +} + +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); +} + +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); +} + +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); +} + +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); +} + +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); +} + +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); +} + +char *strim(char *s) +{ + size_t len = __strlen(s) + 1; + + check_memory_region((unsigned long)s, len, false, _RET_IP_); + + return __strim(s); +} + +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); +} + +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); +} + +size_t strlen(const char *s) +{ + size_t len = __strlen(s); + + check_memory_region((unsigned long)s, len + 1, false, _RET_IP_); + + return len; +} + +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; +} + +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); +} +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); +} + +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); +} + +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); +} + +void *memscan(void *addr, int c, size_t size) +{ + check_memory_region((unsigned long)addr, size, false, _RET_IP_); + + return __memscan(addr, c, size); +} + +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); +} + +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); +} + +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); +} + +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); +}