Received: by 2002:a05:6a10:a0d1:0:0:0:0 with SMTP id j17csp1362789pxa; Sat, 15 Aug 2020 17:43:34 -0700 (PDT) X-Google-Smtp-Source: ABdhPJxCVtH5EKLZPbvb+NM3aou10ePcT4bXyazgvLch6jls7RKCF4wbVRBAlQ4ttBrRmDrFq92o X-Received: by 2002:a17:906:2f07:: with SMTP id v7mr9252958eji.313.1597538614098; Sat, 15 Aug 2020 17:43:34 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1597538614; cv=none; d=google.com; s=arc-20160816; b=v8QT/J2xB72hhNR6/IiEkvSLWQ6YUmNw4Nm+5PCRvPPr3yxm7F0yqHASSEO59DGhQW vwGNgwnwlhrLVzBdn8UllIRGO0stq/ihmZNrTl8nFT9v2sJ9ynrJMXmj5xr7jYLEkefL ntpM/f43+Sej+kmxOW4s6srDGYVYXMUQ1ixq0LEZ9GYHxdyGNhDvGKAQ9km0s8+io154 MJ+Ne1YB8Jcb+I87YxT3OpncZ8EdmB/n/U8FEDST7HwTJlSBBVTnaorRN9P1EAljKXea NWWc8d6EQUGyUNeU1Nfp/2DnFCaBmKJzzHTa5NOaZ76TV/eR9u/WgCfuQ/AfyH161nTQ wfoQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:in-reply-to:content-disposition :mime-version:references:message-id:subject:cc:to:from:date :dkim-signature; bh=BAVB1g/G59WljuvEwZfLgQcZGsyMrz+xF+J2CpCEONs=; b=Bxa7RcfobKG3S9pSkzY4lVKu4pEC3BJ+ihykg4q72Iwgi+I9T1dF/Dta2MX8AfMawW mPJUc0/FPongWs5WwOLuL1HQa1qAVQqRg4W0g2V9PsWDmpCY7IZyBoXk/tCzTbilO/QR Siwx8llNTZci7dJIeINYB/A+HyWFfDzevMS4FK54bLRI8UByLVQfZllaiyYsZRGWbrKR ZnIwW9ECE0P6RWqM35ftOVg917gJP8EiXsFxh46y1w+dyw+OlB2OplkNbmzb8VRmTVTM axcjwwT49hxltF96teUivbKxfH6naA1GUKu5hv4IYinWg6lJ75wadEJENTeU7ll0tUF1 h1Hw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@chromium.org header.s=google header.b=VHDocVcg; 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=pass (p=NONE sp=NONE dis=NONE) header.from=chromium.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id o16si8127966edt.286.2020.08.15.17.43.10; Sat, 15 Aug 2020 17:43:34 -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=@chromium.org header.s=google header.b=VHDocVcg; 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=pass (p=NONE sp=NONE dis=NONE) header.from=chromium.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1729060AbgHOVwU (ORCPT + 99 others); Sat, 15 Aug 2020 17:52:20 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:45602 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1729030AbgHOVwN (ORCPT ); Sat, 15 Aug 2020 17:52:13 -0400 Received: from mail-pg1-x544.google.com (mail-pg1-x544.google.com [IPv6:2607:f8b0:4864:20::544]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 7CE0DC00868E for ; Sat, 15 Aug 2020 10:11:15 -0700 (PDT) Received: by mail-pg1-x544.google.com with SMTP id x6so5989763pgx.12 for ; Sat, 15 Aug 2020 10:11:15 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=chromium.org; s=google; h=date:from:to:cc:subject:message-id:references:mime-version :content-disposition:in-reply-to; bh=BAVB1g/G59WljuvEwZfLgQcZGsyMrz+xF+J2CpCEONs=; b=VHDocVcgp3i5hnK3JOC5n1xwowOu3PG/vmHdB2FTQmrkQIk9Vq4xClNNXpQX9xq0XU SZ5C9UytWUiDuV74J9uvKS+lrRzMumsUcYw8LPFYKXG6BE40hAPeBdzFoXLVqk3X9L9+ dR0mb1S0fCgzBmx3RNiHRjErZue/3+FGTXB50= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:date:from:to:cc:subject:message-id:references :mime-version:content-disposition:in-reply-to; bh=BAVB1g/G59WljuvEwZfLgQcZGsyMrz+xF+J2CpCEONs=; b=BsTU9VSOGdJrMmSKmgL5/sY5xkNsnqh7uQ4GFRw72xk44kR0xC0YdnYvealE+gulJs rlr9YTlQ4oqphhsPDBlrMb4hkItTM0P/CJLtOqq5XoA22ohgd7qZNU8B9E037m6uiHVg rX5L6hIwfB3vKTVbeqNepCNpjULKHae8a8gWJGL8nKEH/DFnn3RRhPuvsGb4hpFhm13P 8sZBjrxvYS3wLTnlVf/dKL20lx1KGA/f7KbRSgXEL0TRUpiZbIfkgflDtX6cD29qj9pc vVv0gyLrHWv4g9OsbDrJQ19lIKBktFAs7fmjaTf7D+WSj1y+/yg/MjsOXqbSu++jRXcs /PpQ== X-Gm-Message-State: AOAM533JsKxuOwolmNe/OWaAwvmW2xHSeWHR+LYmRvlg+/J61Bx9XuBc tJ03hs7bDhURLXqLqwNwoWEqlg== X-Received: by 2002:a62:8387:: with SMTP id h129mr5505019pfe.142.1597511474893; Sat, 15 Aug 2020 10:11:14 -0700 (PDT) Received: from www.outflux.net (smtp.outflux.net. [198.145.64.163]) by smtp.gmail.com with ESMTPSA id w3sm12829718pff.56.2020.08.15.10.11.13 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sat, 15 Aug 2020 10:11:14 -0700 (PDT) Date: Sat, 15 Aug 2020 10:11:13 -0700 From: Kees Cook To: Rasmus Villemoes Cc: "Gustavo A. R. Silva" , Jason Gunthorpe , Leon Romanovsky , Matthew Wilcox , linux-kernel@vger.kernel.org, kernel-hardening@lists.openwall.com Subject: Re: [PATCH] overflow: Add __must_check attribute to check_*() helpers Message-ID: <202008151009.5709750A@keescook> References: <202008121450.405E4A3@keescook> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Thu, Aug 13, 2020 at 08:39:44AM +0200, Rasmus Villemoes wrote: > On 12/08/2020 23.51, Kees Cook wrote: > > Since the destination variable of the check_*_overflow() helpers will > > contain a wrapped value on failure, it would be best to make sure callers > > really did check the return result of the helper. Adjust the macros to use > > a bool-wrapping static inline that is marked with __must_check. This means > > the macros can continue to have their type-agnostic behavior while gaining > > the function attribute (that cannot be applied directly to macros). > > > > Suggested-by: Rasmus Villemoes > > Signed-off-by: Kees Cook > > --- > > include/linux/overflow.h | 51 +++++++++++++++++++++++----------------- > > 1 file changed, 30 insertions(+), 21 deletions(-) > > > > diff --git a/include/linux/overflow.h b/include/linux/overflow.h > > index 93fcef105061..ef7d538c2d08 100644 > > --- a/include/linux/overflow.h > > +++ b/include/linux/overflow.h > > @@ -43,6 +43,16 @@ > > #define is_non_negative(a) ((a) > 0 || (a) == 0) > > #define is_negative(a) (!(is_non_negative(a))) > > > > +/* > > + * Allows to effectively us apply __must_check to a macro so we can have > > word ordering? This and the __must_check-bool() renaming now done and sent in v2. Thanks! > Sorry, I meant to send this before your cooking was done but forgot > about it again. Not a big deal, but it occurred to me it might be better > to rename the existing check_*_overflow to __check_*_overflow (in both > branches of the COMPILER_HAS_GENERIC_BUILTIN_OVERFLOW), and then > > #define check_*_overflow(a, b, d) > __must_check_bool(__check_*_overflow(a, b, d)) At the end of the day, I'd rather not have a way to ignore the overflow in this way -- I'd rather have a set of wrap_mul_overflow() helpers instead. Then we've got proper annotation of the expectation (and a place for function attributes to be added to tell sanitizers to ignore overflow). -- Kees Cook