Received: by 2002:a25:1506:0:0:0:0:0 with SMTP id 6csp3970099ybv; Tue, 25 Feb 2020 10:37:23 -0800 (PST) X-Google-Smtp-Source: APXvYqxN2TccGRWkbsEJX8BxNbtCQ6jZwuH+H1WtrWwPdE3MOlZNvmeK603B/nmUkln7nTqhh0nj X-Received: by 2002:a9d:7c81:: with SMTP id q1mr26874831otn.112.1582655843098; Tue, 25 Feb 2020 10:37:23 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1582655843; cv=none; d=google.com; s=arc-20160816; b=iVZwpzbaUaO3nlaDNPTyhw5x3JlGnjpHmrUw4TRI41teUrsBLmag+i1QbCxo0noiXi +gjP5nXnitReYEhVLT7Sc+00l3eiiwB/3TGC0d+5B94yZpH/AggVnwyREgK6/ElalXk8 9q842phZYojyPUFZQ5usHU/kUUVHIyFVIrt/qXTQAzOetxzdHj5nIL6ubSsgQVaJkw+b hbWUPf4xhiH8x1sFaps46e1hTchbMjVAY64oz59G65RCsD9d8zEXF8axn9Bu2uBrvpeB 0OCoIXKzQRZP0U8baNZOzIWNC7rmtY/zmDb2UBxmhlLbO41pvhcOl5QxTCrcCocpNFKi KRtw== 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=/Oq7ZlHByEKisw958sDxdjAX7fiFkXlFc5ymByAOxAI=; b=qAKEgSCWI3tlNFZlhLGAG7k3YNx69WFnVFs5Fg9tMGyayQG3+ezLjaEXCbqngppj5b ImXjUsqwmEyyIRchhogNrekNJZGpevtSVnf7PJXHkJsVTm95/BCHT8xfHFkbDj2h5kds mW2qghDxRIP11clBma+nu5JiHgwgxzhNB9ax1M3BCnr1hLCqnrKX1Xojzuo6/0YwXuyu MIU89AsN6DaVfLD9VmunZutEBm675Vcu961xpOYu+A++qQEXyGPtm4derLaA/F+Plkdd cIght8FI1uoWA4hTwB5wQYg8vHYd0ns6VEKE1Tw1HHe5TP40xSqbxo4yw1P7y7JBYkfH 0tVA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@chromium.org header.s=google header.b=DS824e58; 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=chromium.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id l8si7226634oii.249.2020.02.25.10.37.10; Tue, 25 Feb 2020 10:37:23 -0800 (PST) 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=@chromium.org header.s=google header.b=DS824e58; 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=chromium.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1731591AbgBYSf6 (ORCPT + 99 others); Tue, 25 Feb 2020 13:35:58 -0500 Received: from mail-pl1-f196.google.com ([209.85.214.196]:40984 "EHLO mail-pl1-f196.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1727983AbgBYSf6 (ORCPT ); Tue, 25 Feb 2020 13:35:58 -0500 Received: by mail-pl1-f196.google.com with SMTP id t14so136758plr.8 for ; Tue, 25 Feb 2020 10:35:58 -0800 (PST) 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=/Oq7ZlHByEKisw958sDxdjAX7fiFkXlFc5ymByAOxAI=; b=DS824e58go8okeMKOqEHEbHc21x7FkHA0PkE7JjUV/ffMD1jaGlRVRKQiy5G78ZSYi w1g8VqpgDd0aOt7TLWrv9NKqWgKZYpnTPxeD6k9lHXhVVPmM22eWvb8eWDmVot6ePvL1 8WChB0KvbivUsKRrpzgsb+e+Tym3KoTwLEdn4= 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=/Oq7ZlHByEKisw958sDxdjAX7fiFkXlFc5ymByAOxAI=; b=OUxh0P1LKWXu33iYr9pX2pU+SVoeLn8OCtYMP+Quv135e2Qc3PlUMGl+iY9pejqv3O v4LHFIOLg6Rl/J54DgxhBy78G2Sq/V6BAbrgXkCKpZ1BcgxN+qYz08tDgv7n7JgOvnXX +TtrCEpxwHWUhkFBtjQXFMnuZF4zByP8cJ4jXpjhqJIxtXTgA9e/t54ebhXMQDH6olcL GpO1YxDbeDLBRvGZhG1A6pp4c2qaLbvAHeOTv6tcZGHnH9yDJRA1Rxo5pFshi0GRY/Uo CSPEzp8MO9m2rpzmsl1Ck+KuuVjvE7ui3uy8a8Szygnm0ElgCgqrf4ZMLuBsR1+rHZ5L LhGA== X-Gm-Message-State: APjAAAWTqhmJ6SO0v8EWyoyQ//KlHiZNQTxn7DxlCUx0f5qZ6/29XZGj 4iX74SKJ7+0nmA9lcLb7fYL63w== X-Received: by 2002:a17:90a:7187:: with SMTP id i7mr379790pjk.6.1582655757813; Tue, 25 Feb 2020 10:35:57 -0800 (PST) Received: from www.outflux.net (smtp.outflux.net. [198.145.64.163]) by smtp.gmail.com with ESMTPSA id d3sm4311417pjx.10.2020.02.25.10.35.56 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 25 Feb 2020 10:35:57 -0800 (PST) Date: Tue, 25 Feb 2020 10:35:56 -0800 From: Kees Cook To: Daniel Micay Cc: Daniel Axtens , Kernel Hardening , Linux-MM , kernel list , Andrew Morton Subject: Re: [PATCH 5/5] [RFC] mm: annotate memory allocation functions with their sizes Message-ID: <202002251035.AD29F84@keescook> References: <20200120074344.504-1-dja@axtens.net> <20200120074344.504-6-dja@axtens.net> 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 Fri, Feb 07, 2020 at 03:38:22PM -0500, Daniel Micay wrote: > There are some uses of ksize in the kernel making use of the real > usable size of memory allocations rather than only the requested > amount. It's incorrect when mixed with alloc_size markers, since if a > number like 14 is passed that's used as the upper bound, rather than a > rounded size like 16 returned by ksize. It's unlikely to trigger any > issues with only CONFIG_FORTIFY_SOURCE, but it becomes more likely > with -fsanitize=object-size or other library-based usage of > __builtin_object_size. I think the solution here is to use a macro that does the per-bucket rounding and applies them to the attributes. Keep the bucket size lists in sync will likely need some BUILD_BUG_ON()s or similar. -- Kees Cook