Received: by 2002:ab2:3141:0:b0:1ed:23cc:44d1 with SMTP id i1csp763336lqg; Sat, 2 Mar 2024 00:28:40 -0800 (PST) X-Forwarded-Encrypted: i=3; AJvYcCXq/mXUQe5lVAfq+WdYBc6yAZolmOAPlxj+Fn0TC6dYh0vo4uz5yQGSvsF8WiWMEc/sDc4d9O15V4+GeBzZPSlnvYDGZSOcjyOdzBiksg== X-Google-Smtp-Source: AGHT+IGVkjSI3vyu1Pwadz93h2Rt0kQtJ9w6WPf+mX9x1pvP8OK6kP4xlAr913HS5WxZF96wdE/B X-Received: by 2002:a17:907:20b9:b0:a43:6cd2:7a27 with SMTP id pw25-20020a17090720b900b00a436cd27a27mr2358743ejb.19.1709368120136; Sat, 02 Mar 2024 00:28:40 -0800 (PST) ARC-Seal: i=2; a=rsa-sha256; t=1709368120; cv=pass; d=google.com; s=arc-20160816; b=cq8JS22i7+qKcajtQzX3aVdMYM5VYizqQRyEDP+OYndhlQH2rK4cyVbEMrXSHji7a0 HbTjPyrrfm9TfOs8pqqAQ6p2ijtIWPMJbWkp5z35vJUKADKsma84OMTJTxO0wd4rRzQe NtTx4sV5aZ34BB85VmvZdNvOgTocYTiOe85cV4wOHpe04QUDZYPl9t5GRitlllt1BgGq 0rl+RSyprHSSWtKJZajRb1DgGUCXif5EjbC+qo73QIKRUOe+ZqIRHJUlR+QI4owueZcB nQ9wl4EDedhsetuH6IKni8d2UeXYMtt566UooGR85OdxGI26BytTzxl4bVNI3M1h66EJ BhAQ== ARC-Message-Signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=user-agent:in-reply-to:content-disposition:mime-version :list-unsubscribe:list-subscribe:list-id:precedence:references :message-id:subject:cc:to:from:date; bh=bZUeWiqrJfys5P2IF6B8OZHVB1uNrlwbXIKUVbBZBWM=; fh=oniqMhjl1GDv7NqQHggtWh9MCrZeqkNmFpmUuQGK6yE=; b=VYIZ0xS45XA0RGZeZDU0FLv9oFVsnRXCCUf5Gk84NTIzuOqluboXUdef6j8pZuGyY8 2xVfy8GmyhLKdl6Ms+ue3QHX1XXKISlcKIVQz4QTi4VP2Kn6kbjOXN8fBLAk6BkZfZK6 KTCQyEcaiBtzBozsjCDAefXujSMqJehFnEpTpJN33c+nyA0Z3X1m0RmNccNB+mYrhXZ4 j3LJibbA0r9XbOpR04V8huRL9Mhy5f4zW5Vp1aVRMH8YNXZSqZkkw+6HJWEq5bY9/ClB TZt5vi4IeGExRWHv+ewSfX5PL5+W6K/aoCoWJEhQDrgYbW1UuWENHc6mHgWHBrx2RnAy rUXQ==; dara=google.com ARC-Authentication-Results: i=2; mx.google.com; arc=pass (i=1); spf=pass (google.com: domain of linux-crypto+bounces-2463-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:4601:e00::3 as permitted sender) smtp.mailfrom="linux-crypto+bounces-2463-linux.lists.archive=gmail.com@vger.kernel.org" Return-Path: Received: from am.mirrors.kernel.org (am.mirrors.kernel.org. [2604:1380:4601:e00::3]) by mx.google.com with ESMTPS id v11-20020a170906564b00b00a430a51484esi2221814ejr.600.2024.03.02.00.28.40 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sat, 02 Mar 2024 00:28:40 -0800 (PST) Received-SPF: pass (google.com: domain of linux-crypto+bounces-2463-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:4601:e00::3 as permitted sender) client-ip=2604:1380:4601:e00::3; Authentication-Results: mx.google.com; arc=pass (i=1); spf=pass (google.com: domain of linux-crypto+bounces-2463-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:4601:e00::3 as permitted sender) smtp.mailfrom="linux-crypto+bounces-2463-linux.lists.archive=gmail.com@vger.kernel.org" Received: from smtp.subspace.kernel.org (wormhole.subspace.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by am.mirrors.kernel.org (Postfix) with ESMTPS id D78211F236E8 for ; Sat, 2 Mar 2024 08:28:39 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 815F817596; Sat, 2 Mar 2024 08:28:04 +0000 (UTC) X-Original-To: linux-crypto@vger.kernel.org Received: from bmailout1.hostsharing.net (bmailout1.hostsharing.net [83.223.95.100]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id ED05D17553; Sat, 2 Mar 2024 08:27:59 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=83.223.95.100 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1709368084; cv=none; b=Y/soV01wPRy4nhR4Ob4Tn1XrDVYmwTkSM2zbkM96H2larD8R3EPOwNurtuTYaFmcEMCqbXvC4fKaih+cUgzvo3y8IJqDFotD+3NV6CclQtr/e+Ob6XMyWTAw26CfowxH3Mr1t7QN6bgfG8E/dee1ofElZnMNJtyUSPIUjiEc6b4= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1709368084; c=relaxed/simple; bh=CVULUo//9x0nN93MMBp0nP2y9b2g3CbSPU8l7LLAMoA=; h=Date:From:To:Cc:Subject:Message-ID:References:MIME-Version: Content-Type:Content-Disposition:In-Reply-To; b=p2T//yBuBIssliNec+GBOD0uIbf+mnU0+gNmsgQ2sxwZANSmo/SEdZNyW4LekL5tBm9cLS0QrPb9soMUHqy7GsGVKPiC+1x6SIVvFGgst4+5+D7PqV1TTKlweB1+O1xfpLrlaKimsWIjQkpUtL2KQYKWtjLs4KlnXQ02Ev1B4Ks= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dmarc=none (p=none dis=none) header.from=wunner.de; spf=none smtp.mailfrom=h08.hostsharing.net; arc=none smtp.client-ip=83.223.95.100 Authentication-Results: smtp.subspace.kernel.org; dmarc=none (p=none dis=none) header.from=wunner.de Authentication-Results: smtp.subspace.kernel.org; spf=none smtp.mailfrom=h08.hostsharing.net Received: from h08.hostsharing.net (h08.hostsharing.net [83.223.95.28]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits) server-digest SHA256 client-signature RSA-PSS (4096 bits) client-digest SHA256) (Client CN "*.hostsharing.net", Issuer "RapidSSL TLS RSA CA G1" (verified OK)) by bmailout1.hostsharing.net (Postfix) with ESMTPS id E2F8B3000086A; Sat, 2 Mar 2024 09:27:51 +0100 (CET) Received: by h08.hostsharing.net (Postfix, from userid 100393) id D220F168E2; Sat, 2 Mar 2024 09:27:51 +0100 (CET) Date: Sat, 2 Mar 2024 09:27:51 +0100 From: Lukas Wunner To: Herbert Xu Cc: David Howells , "David S. Miller" , Jonathan Cameron , keyrings@vger.kernel.org, linux-crypto@vger.kernel.org, Andy Shevchenko , Peter Zijlstra , Dan Williams , Ard Biesheuvel , Jarkko Sakkinen , Nick Desaulniers , Nathan Chancellor Subject: Re: [PATCH v3] X.509: Introduce scope-based x509_certificate allocation Message-ID: <20240302082751.GA25828@wunner.de> References: <63cc7ab17a5064756e26e50bc605e3ff8914f05a.1708439875.git.lukas@wunner.de> Precedence: bulk X-Mailing-List: linux-crypto@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: User-Agent: Mutt/1.10.1 (2018-07-13) On Fri, Mar 01, 2024 at 06:10:33PM +0800, Herbert Xu wrote: > On Tue, Feb 20, 2024 at 04:10:39PM +0100, Lukas Wunner wrote: > > > > In x509_cert_parse(), add a hint for the compiler that kzalloc() never > > returns an ERR_PTR(). Otherwise the compiler adds a gratuitous IS_ERR() > > check on return. Introduce a handy assume() macro for this which can be > > re-used elsewhere in the kernel to provide hints for the compiler. > > Would it be possible to move the use of assume into the kzalloc > declaration instead? Perhaps by turning it into a static inline > wrapper that does the "assume"? > > Otherwise as time goes on we'll have a proliferation of these > "assume"s all over the place. I've tried moving the assume(!IS_ERR()) to kmalloc() (which already is a static inline), but that increased total vmlinux size by 448 bytes. I was expecting pushback due to the size increase, hence kept the assume() local to x509_cert_parse(). There's a coccinelle rule which warns if an IS_ERR() check is performed on a kmalloc'ed pointer (scripts/coccinelle/null/eno.cocci), hence there don't seem to be any offenders left in the tree which use this antipattern and adding assume(!IS_ERR()) to kmalloc() doesn't have any positive effect beyond avoiding the single unnecessary check in x509_cert_parse(). If you don't like the assume(!IS_ERR(cert)) in x509_cert_parse(), I can respin the patch to drop it. The unnecessary check which it avoids only occurs in the error path. If the certificate can be parsed without error, there's no unnecessary check. It still triggered my OCD when scrutinizing the disassembled code and sufficiently annoyed me that I wanted to get rid of it, but in reality it's not such a big deal. Thanks, Lukas