Received: by 2002:a05:6a10:9e8c:0:0:0:0 with SMTP id y12csp158943pxx; Wed, 28 Oct 2020 01:04:51 -0700 (PDT) X-Google-Smtp-Source: ABdhPJxo4ha4EEkR0FiwKqduHM6KkMNY4xEn3uicU1eLNS4LN04slnDdJLvkdZrBUpWeaOqo5uCz X-Received: by 2002:a50:eb45:: with SMTP id z5mr6341999edp.144.1603872291760; Wed, 28 Oct 2020 01:04:51 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1603872291; cv=none; d=google.com; s=arc-20160816; b=S5sVKFFHBCcNN+QjZuzL7+Mc7RkCaUTrYXOf4bvKSbuvSFhFmkqk69b4rWRwhrtEZR CFSFRK7twdOpTIeDZxz5Y8gI+JoJEEsy1qYpgygV7f1Tq61XbkzcL6+Q9gnsIOZKPCim 7cwb+xZyGxCQvHn2DgPrIiDTuJYgQpC3gzQvCXKUnxDHYVa1KZWOwpiC/fG5Okh0ttxT 0EFvxt+uL2og2kz9bKzPhMgZTw4yEz88GYlWXfWjscPfecXlSvPJJLuDj0khO2HxAtQK ttbKyTx3yDX/tUZDvlIsKT4bUoj+oN9D47uAgez2P4DSdTUcQFbORM6YpSWsq5hCqsZj /8Zw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :user-agent:references:in-reply-to:message-id:date:subject:cc:to :from:dkim-signature; bh=rH9XKg+hdFXF0nGpY+pEpxA4I9dGC/n4KQxlTmE4wbI=; b=i+BDHQw6eiZiUNT/0z/ztN46WpiLOZ354DBPN2eFmZvoBdrwrqlkJpLEQTcGCm7Kk3 bvbJjhYCSNBF6JGMN+5zhMld18oYcA4pYRmjwAMWCqYLhKrXhIDNOdvOd7d3FMgm7oGQ +c8g+6bTXmar+g45jPulQfBuIts7Cg2HAPsPoM9x2l65KKCRWBjS4UU5ss22nTWn4l0k hXbRvGTh//BrhzkdHPWTXXpeYdUOlHPcqUznYsFHm3uO1F0VW8oK4hLFP8if/C/BiSYY vDGXa6RaD65AYUhnlVw2WJJaUuSfy058lkWjMgpgbprVi3GCmmKh3ejbA/7sq48RhEKX p2ng== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=default header.b=HGsveU3l; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=linuxfoundation.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id t1si2868715ejb.712.2020.10.28.01.04.29; Wed, 28 Oct 2020 01:04:51 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) client-ip=23.128.96.18; Authentication-Results: mx.google.com; dkim=pass header.i=@kernel.org header.s=default header.b=HGsveU3l; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=linuxfoundation.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1752934AbgJ0N5p (ORCPT + 99 others); Tue, 27 Oct 2020 09:57:45 -0400 Received: from mail.kernel.org ([198.145.29.99]:44720 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1752925AbgJ0N5m (ORCPT ); Tue, 27 Oct 2020 09:57:42 -0400 Received: from localhost (83-86-74-64.cable.dynamic.v4.ziggo.nl [83.86.74.64]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPSA id BC7ED2068D; Tue, 27 Oct 2020 13:57:40 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1603807061; bh=LCumXXTkjflgXPLc//C6IVax3GR9mLvWZH5iIaXZROM=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=HGsveU3lNB+rH+od6nY5zHnFM/fwY8fMmIZngUcJpsYXx5MdwPLN5nV2d4BK9zL3i KFqSY2NekyO2mVCaNJDVVJdSWpw/GqM3aA+1KgzAj/Wnpnb+kJtFvrP7Jmn/lQwa3Y OfrTWOB0Ix/PEjTAobi5ebdKnkX5bOKFcr52Vhwk= From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , stable@vger.kernel.org, Andrey Ryabinin , Alexander Potapenko , Dmitry Vyukov , Ingo Molnar , "H. Peter Anvin" , Thomas Gleixner , Andrew Morton , Linus Torvalds , Ben Hutchings Subject: [PATCH 4.4 006/112] mm/kasan: print name of mem[set,cpy,move]() caller in report Date: Tue, 27 Oct 2020 14:48:36 +0100 Message-Id: <20201027134900.841952859@linuxfoundation.org> X-Mailer: git-send-email 2.29.1 In-Reply-To: <20201027134900.532249571@linuxfoundation.org> References: <20201027134900.532249571@linuxfoundation.org> User-Agent: quilt/0.66 MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org From: Andrey Ryabinin commit 936bb4bbbb832f81055328b84e5afe1fc7246a8d upstream. When bogus memory access happens in mem[set,cpy,move]() it's usually caller's fault. So don't blame mem[set,cpy,move]() in bug report, blame the caller instead. Before: BUG: KASAN: out-of-bounds access in memset+0x23/0x40 at
After: BUG: KASAN: out-of-bounds access in at
Link: http://lkml.kernel.org/r/1462538722-1574-2-git-send-email-aryabinin@virtuozzo.com Signed-off-by: Andrey Ryabinin Acked-by: Alexander Potapenko Cc: Dmitry Vyukov Cc: Ingo Molnar Cc: "H. Peter Anvin" Cc: Thomas Gleixner Signed-off-by: Andrew Morton Signed-off-by: Linus Torvalds Signed-off-by: Ben Hutchings Signed-off-by: Greg Kroah-Hartman --- mm/kasan/kasan.c | 64 +++++++++++++++++++++++++++++-------------------------- 1 file changed, 34 insertions(+), 30 deletions(-) --- a/mm/kasan/kasan.c +++ b/mm/kasan/kasan.c @@ -252,32 +252,36 @@ static __always_inline bool memory_is_po return memory_is_poisoned_n(addr, size); } - -static __always_inline void check_memory_region(unsigned long addr, - size_t size, bool write) +static __always_inline void check_memory_region_inline(unsigned long addr, + size_t size, bool write, + unsigned long ret_ip) { if (unlikely(size == 0)) return; if (unlikely((void *)addr < kasan_shadow_to_mem((void *)KASAN_SHADOW_START))) { - kasan_report(addr, size, write, _RET_IP_); + kasan_report(addr, size, write, ret_ip); return; } if (likely(!memory_is_poisoned(addr, size))) return; - kasan_report(addr, size, write, _RET_IP_); + kasan_report(addr, size, write, ret_ip); } -void __asan_loadN(unsigned long addr, size_t size); -void __asan_storeN(unsigned long addr, size_t size); +static void check_memory_region(unsigned long addr, + size_t size, bool write, + unsigned long ret_ip) +{ + check_memory_region_inline(addr, size, write, ret_ip); +} #undef memset void *memset(void *addr, int c, size_t len) { - __asan_storeN((unsigned long)addr, len); + check_memory_region((unsigned long)addr, len, true, _RET_IP_); return __memset(addr, c, len); } @@ -285,8 +289,8 @@ void *memset(void *addr, int c, size_t l #undef memmove void *memmove(void *dest, const void *src, size_t len) { - __asan_loadN((unsigned long)src, len); - __asan_storeN((unsigned long)dest, 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); } @@ -294,8 +298,8 @@ void *memmove(void *dest, const void *sr #undef memcpy void *memcpy(void *dest, const void *src, size_t len) { - __asan_loadN((unsigned long)src, len); - __asan_storeN((unsigned long)dest, 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); } @@ -484,22 +488,22 @@ void __asan_unregister_globals(struct ka } EXPORT_SYMBOL(__asan_unregister_globals); -#define DEFINE_ASAN_LOAD_STORE(size) \ - void __asan_load##size(unsigned long addr) \ - { \ - check_memory_region(addr, size, false); \ - } \ - EXPORT_SYMBOL(__asan_load##size); \ - __alias(__asan_load##size) \ - void __asan_load##size##_noabort(unsigned long); \ - EXPORT_SYMBOL(__asan_load##size##_noabort); \ - void __asan_store##size(unsigned long addr) \ - { \ - check_memory_region(addr, size, true); \ - } \ - EXPORT_SYMBOL(__asan_store##size); \ - __alias(__asan_store##size) \ - void __asan_store##size##_noabort(unsigned long); \ +#define DEFINE_ASAN_LOAD_STORE(size) \ + void __asan_load##size(unsigned long addr) \ + { \ + check_memory_region_inline(addr, size, false, _RET_IP_);\ + } \ + EXPORT_SYMBOL(__asan_load##size); \ + __alias(__asan_load##size) \ + void __asan_load##size##_noabort(unsigned long); \ + EXPORT_SYMBOL(__asan_load##size##_noabort); \ + void __asan_store##size(unsigned long addr) \ + { \ + check_memory_region_inline(addr, size, true, _RET_IP_); \ + } \ + EXPORT_SYMBOL(__asan_store##size); \ + __alias(__asan_store##size) \ + void __asan_store##size##_noabort(unsigned long); \ EXPORT_SYMBOL(__asan_store##size##_noabort) DEFINE_ASAN_LOAD_STORE(1); @@ -510,7 +514,7 @@ DEFINE_ASAN_LOAD_STORE(16); void __asan_loadN(unsigned long addr, size_t size) { - check_memory_region(addr, size, false); + check_memory_region(addr, size, false, _RET_IP_); } EXPORT_SYMBOL(__asan_loadN); @@ -520,7 +524,7 @@ EXPORT_SYMBOL(__asan_loadN_noabort); void __asan_storeN(unsigned long addr, size_t size) { - check_memory_region(addr, size, true); + check_memory_region(addr, size, true, _RET_IP_); } EXPORT_SYMBOL(__asan_storeN);