Received: by 2002:a5b:505:0:0:0:0:0 with SMTP id o5csp831711ybp; Fri, 11 Oct 2019 05:11:09 -0700 (PDT) X-Google-Smtp-Source: APXvYqw0Bxh4yYZGNodv13pU3zBlAgaohtgo5egmEHq61hoD30qXSd0g4hZevZKuW24LaKzpXuwG X-Received: by 2002:a17:906:d7ab:: with SMTP id pk11mr13718289ejb.283.1570795869257; Fri, 11 Oct 2019 05:11:09 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1570795869; cv=none; d=google.com; s=arc-20160816; b=CvIq91fS/dOofWq9J4tblWVyecseDfBAux87+bO6mcH5MKxUTwD7YhYtuuyrSIL0p0 cccY3eKiKM23sohcq9y77LMDC6BOt34LPddX/i3yE422cEZYd8c0pJ3J3IN+1MLX2dQU iSPABh01Is6cFX1IWIeHsu+zqU9Opz9CDYNxterodIhSnKlenX20ECu8dCjhxjxkuO6J jKP5otrX3OqsQ3EG7bsW8nCXPG78W6dj/Mw5OjQyWinE6Md0ElC/XduPd2fbRYtGV9Aa cgeevwa2MeX1FZ6NpEQga9ufy9tIk2xtlGrfWBO7vD9eTJrHjW1MEhOvqgYCRaUFxK7z vKHA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:user-agent:in-reply-to :content-disposition:mime-version:references:message-id:subject:cc :to:from:date:dkim-signature; bh=llGbQ3vva8vkDy6lKORP4YgV1RlcQ2iQmhzFKoDm2Xw=; b=BR5XQiMamAb3TJrd4cXFc0aAIKC8p8/KR2GajkXPEUx+pKdhsZCZpDrr2B0VrXtCCY 6CAHp0/bmJgXV6IzdULK9u9dqe+hfLaSKGhm1vcaMQa1pPcP290pcrWA/43d1W1qiJks N39b0dgRuBTBHsE+51j6hzBpbqM8fjg7PDE8gsVLsFS8KrFFEVxhA/hS7fWSMyh/q62B kfkjK8OFfQ5ghx0x9VfjATBA5wQjXJvfQrKd2el6OhLkbxeBsGCN1mtVpGugjtg6VCqF EuV/m5eZT3xT2w1yew6oVTnoUkaygSkOIdHU1tyAvNNIdE5oB+cz88XWrVOoCcJmrh3n n/0w== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=default header.b=HAhZOker; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id i17si4889658ejy.374.2019.10.11.05.10.45; Fri, 11 Oct 2019 05:11:09 -0700 (PDT) Received-SPF: pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; dkim=pass header.i=@kernel.org header.s=default header.b=HAhZOker; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1727950AbfJKMJv (ORCPT + 99 others); Fri, 11 Oct 2019 08:09:51 -0400 Received: from mail.kernel.org ([198.145.29.99]:55898 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1727709AbfJKMJv (ORCPT ); Fri, 11 Oct 2019 08:09:51 -0400 Received: from willie-the-truck (236.31.169.217.in-addr.arpa [217.169.31.236]) (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 CDCB5214E0; Fri, 11 Oct 2019 12:09:34 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1570795790; bh=e0k/MZXeZ8iSfaf9YCQWVrhAlEuXi+xlo5m4GcQ3Bho=; h=Date:From:To:Cc:Subject:References:In-Reply-To:From; b=HAhZOkerWZeMzD3HPXqDap273VI9oEEoBKnzcPZgxuxkiFEDLn7ZCbC7L2B2vgtiv 9ik6eIn5g91HnxSeDc5kMY0ki1F7K8mbjx3EYRtZK7nvvzsbT7TXuwF33lmAd3CGmB 2LQiVOFO+k2GbC8qkt83ijDBVYo7ScCmlnKv9d4Q= Date: Fri, 11 Oct 2019 13:09:18 +0100 From: Will Deacon To: Kees Cook Cc: linux-kernel@vger.kernel.org, Ingo Molnar , Elena Reshetova , Peter Zijlstra , Ard Biesheuvel , Hanjun Guo , Jan Glauber Subject: Re: [PATCH v3 06/10] lib/refcount: Move saturation warnings out of line Message-ID: <20191011120918.3o7z6p5degsnpzzc@willie-the-truck> References: <20191007154703.5574-1-will@kernel.org> <20191007154703.5574-7-will@kernel.org> <201910101342.B6B4B3B6@keescook> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <201910101342.B6B4B3B6@keescook> User-Agent: NeoMutt/20170113 (1.7.2) Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Thu, Oct 10, 2019 at 01:48:20PM -0700, Kees Cook wrote: > On Mon, Oct 07, 2019 at 04:46:59PM +0100, Will Deacon wrote: > > Having the refcount saturation and warnings inline bloats the text, > > despite the fact that these paths should never be executed in normal > > operation. > > > > Move the refcount saturation and warnings out of line to reduce the > > image size when refcount_t checking is enabled. Relative to an x86_64 > > defconfig, the sizes reported by bloat-o-meter are: > > > > # defconfig+REFCOUNT_FULL, inline saturation (i.e. before this patch) > > Total: Before=14762076, After=14915442, chg +1.04% > > > > # defconfig+REFCOUNT_FULL, out-of-line saturation (i.e. after this patch) > > Total: Before=14762076, After=14835497, chg +0.50% > > The downside of this change is that this means we get one warning per > refcount_saturation_type, where as before it was once per refcount > usage. I think, ultimately, this is okay, but it is a behavioral change > that might be worth pointing out. Good point; I'll add something to the commit message. > > diff --git a/lib/refcount.c b/lib/refcount.c > > index 3a534fbebdcc..6a61d39f9390 100644 > > --- a/lib/refcount.c > > +++ b/lib/refcount.c > > @@ -8,6 +8,34 @@ > > #include > > #include > > > > +#define REFCOUNT_WARN(str) WARN_ONCE(1, "refcount_t: " str ".\n") > > This define seems like overkill for just adding a prefix to 5 uses... I dunno. It doesn't hurt and I did get bored of typing that prefix. > > +void refcount_warn_saturate(refcount_t *r, enum refcount_saturation_type t) > > +{ > > + refcount_set(r, REFCOUNT_SATURATED); > > + > > + switch (t) { > > + case REFCOUNT_ADD_NOT_ZERO_OVF: > > + REFCOUNT_WARN("saturated; leaking memory"); > > + break; > > + case REFCOUNT_ADD_OVF: > > + REFCOUNT_WARN("saturated; leaking memory"); > > + break; > > + case REFCOUNT_ADD_UAF: > > + REFCOUNT_WARN("addition on 0; use-after-free"); > > + break; > > + case REFCOUNT_SUB_UAF: > > + REFCOUNT_WARN("underflow; use-after-free"); > > + break; > > + case REFCOUNT_DEC_LEAK: > > + REFCOUNT_WARN("decrement hit 0; leaking memory"); > > Even the longest doesn't line wrap: > > WARN_ONCE(1, "refcount_t: decrement hit 0; leaking memory\n"); > > > + break; > > + default: > > + WARN_ON(1); > > This deserves a string too, yes? > > WARN_ONCE(1, "refcount_t: unknown saturation event!?\n"); Ok. > > > + } > > +} > > +EXPORT_SYMBOL(refcount_warn_saturate); > > + > > /** > > * refcount_dec_if_one - decrement a refcount if it is 1 > > * @r: the refcount > > -- > > 2.23.0.581.g78d2f28ef7-goog > > > > Otherwise, okay, I grudgingly accept the loss of warnings when running > the lkdtm tests in order to gain back some text size... :) Thanks :) Will