From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1754837AbdBHPYz (ORCPT ); Wed, 8 Feb 2017 10:24:55 -0500 Received: from mail-qt0-f196.google.com ([209.85.216.196]:35270 "EHLO mail-qt0-f196.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1753797AbdBHPYq (ORCPT ); Wed, 8 Feb 2017 10:24:46 -0500 MIME-Version: 1.0 In-Reply-To: References: <20170203163607.3488037-1-arnd@arndb.de> <20170206.120318.1268240226202516488.davem@davemloft.net> <4910112.l20yySyWnA@wuerfel> <1486556665.24745.6.camel@sipsolutions.net> From: Andrey Ryabinin Date: Wed, 8 Feb 2017 17:58:44 +0300 Message-ID: Subject: Re: KASAN+netlink, was: [PATCH] [net-next?] hns: avoid stack overflow with CONFIG_KASAN To: Arnd Bergmann Cc: Johannes Berg , David Miller , Networking , stable@vger.kernel.org, Linux Kernel Mailing List , nikolay@cumulusnetworks.com, nicolas.dichtel@6wind.com, adobriyan@gmail.com, linux-wireless Content-Type: text/plain; charset=UTF-8 Sender: linux-kernel-owner@vger.kernel.org List-ID: X-Mailing-List: linux-kernel@vger.kernel.org 2017-02-08 16:10 GMT+03:00 Arnd Bergmann : > On Wed, Feb 8, 2017 at 1:24 PM, Johannes Berg wrote: > >> Btw, what's causing this to start with? Can't the compiler reuse the >> stack places? > > I have no idea. It's trying to find out of bounds accesses for > objects on the stack, so maybe it gives each variable a separate > stack location in order to see which one caused problems? > If compiler cannot prove that access to the local variable is valid it will add redzones around that variable to be able to detect out of bounds accesses. For example: static inline int nla_put_u8(struct sk_buff *skb, int attrtype, u8 value) { return nla_put(skb, attrtype, sizeof(u8), &value); } compiler will surround 'value' with redzones to catch potential oob access in nla_put(). Another way to fix this, would be something like this: #ifdef CONFIG_KASAN /* don't bloat stack */ #define __noinline_for_kasan __noinline __maybe_unused #else #define __noinline_for_kasan inline #endif static __noinline_for_kasan int nla_put_u8(struct sk_buff *skb, int attrtype, u8 value) { return nla_put(skb, attrtype, sizeof(u8), &value); }