Received: by 2002:a05:6a10:17d3:0:0:0:0 with SMTP id hz19csp1939430pxb; Mon, 12 Apr 2021 10:06:46 -0700 (PDT) X-Google-Smtp-Source: ABdhPJyFKoD304z0BQn67vQLNTkt8C2d5aVqai/B3mjXMKNnho0omStodMajRsjhOoTRNqYTJC6S X-Received: by 2002:a17:90a:bd8c:: with SMTP id z12mr130895pjr.83.1618247206109; Mon, 12 Apr 2021 10:06:46 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1618247206; cv=none; d=google.com; s=arc-20160816; b=i5uCELHU8sHCdnqlnbDQDye2XPMPU5j6fSOhuTLDdGIJ7I0WiG6dGo76xHFf4y7s3X BTvcRzv4OWnGjoDrE7/5KoDcobK3gwAvyRKRr6dFCDIoA2g28oV2uuGXAbmbmAiXNqBO nUbYtEc9pWg8snBcYNimbnHdmyNIk8SW2DDbg4N61q7hW1sg23favBfEuGhcWP+6X2X7 Sy4024YQXLQRq8Dch2mqKV4DYf2cAuIioR5LfBXf/Gd2MjQ3GTHyQf4pu6YsaKFWZL+d I3BLmfgaPLnPE2LFVi/wpbzRASxdCLx1WmQ3tpUst6O+7pZZIFBMGfFJOdU/q8eQrXRF KVDA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:content-language :in-reply-to:mime-version:user-agent:date:message-id:from:references :cc:to:subject; bh=42YWouFrSsBTzVmsjtz5PfPkQT2PvKWWQ58LxXBBZj8=; b=pRtYGD8irqYwS8emZJgQ5EkEwEt8mMSEkl07DNOiPe9bQkHJoqryqIf6jAI4Mf+R3P sg/pBx13V1djNqHfwIcrHoTOqWnfvC4As2YX+EIW85QkGup4JLH40engg63SkNNiIKcb qccO6ivYSwyXcO3oVMATwXMGpefJiR0JwGBp/C7/3Yt6ChyDagMVqZmjJxfwqoiQktdU hvmRRmjtUGAPSK43r3tvlGMrmMj0TUNRHaz4jPDZEcDyvolUfc54Iq/zoF55MDQ4pdM1 r8uLRks2Ri4b/px1PHwbowwb8xHf87EpXv0LA7y7k1YJynRSAinlirQ0/QMMfV8PgTp1 rmTw== ARC-Authentication-Results: i=1; mx.google.com; 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=fail (p=NONE sp=NONE dis=NONE) header.from=canonical.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id h12si16712598plr.246.2021.04.12.10.06.30; Mon, 12 Apr 2021 10:06:46 -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; 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=fail (p=NONE sp=NONE dis=NONE) header.from=canonical.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S244089AbhDLRF1 (ORCPT + 99 others); Mon, 12 Apr 2021 13:05:27 -0400 Received: from youngberry.canonical.com ([91.189.89.112]:50528 "EHLO youngberry.canonical.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S245261AbhDLRE6 (ORCPT ); Mon, 12 Apr 2021 13:04:58 -0400 Received: from 1.general.cking.uk.vpn ([10.172.193.212]) by youngberry.canonical.com with esmtpsa (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.86_2) (envelope-from ) id 1lVzzJ-00023K-IM; Mon, 12 Apr 2021 17:04:37 +0000 Subject: Re: [PATCH][next] KEYS: trusted: Fix missing null return from kzalloc call To: jejb@linux.ibm.com, Jarkko Sakkinen , Mimi Zohar , David Howells , James Morris , "Serge E . Hallyn" , Sumit Garg , linux-integrity@vger.kernel.org, keyrings@vger.kernel.org, linux-security-module@vger.kernel.org Cc: kernel-janitors@vger.kernel.org, linux-kernel@vger.kernel.org References: <20210412160101.1627882-1-colin.king@canonical.com> From: Colin Ian King Message-ID: <53fef8cf-0dd4-e4fe-260b-0f5ad25d9014@canonical.com> Date: Mon, 12 Apr 2021 18:04:37 +0100 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:78.0) Gecko/20100101 Thunderbird/78.8.1 MIME-Version: 1.0 In-Reply-To: Content-Type: text/plain; charset=utf-8 Content-Language: en-US Content-Transfer-Encoding: 7bit Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On 12/04/2021 17:48, James Bottomley wrote: > On Mon, 2021-04-12 at 17:01 +0100, Colin King wrote: >> From: Colin Ian King >> >> The kzalloc call can return null with the GFP_KERNEL flag so >> add a null check and exit via a new error exit label. Use the >> same exit error label for another error path too. >> >> Addresses-Coverity: ("Dereference null return value") >> Fixes: 830027e2cb55 ("KEYS: trusted: Add generic trusted keys >> framework") >> Signed-off-by: Colin Ian King >> --- >> security/keys/trusted-keys/trusted_core.c | 6 ++++-- >> 1 file changed, 4 insertions(+), 2 deletions(-) >> >> diff --git a/security/keys/trusted-keys/trusted_core.c >> b/security/keys/trusted-keys/trusted_core.c >> index ec3a066a4b42..90774793f0b1 100644 >> --- a/security/keys/trusted-keys/trusted_core.c >> +++ b/security/keys/trusted-keys/trusted_core.c >> @@ -116,11 +116,13 @@ static struct trusted_key_payload >> *trusted_payload_alloc(struct key *key) >> >> ret = key_payload_reserve(key, sizeof(*p)); >> if (ret < 0) >> - return p; >> + goto err; >> p = kzalloc(sizeof(*p), GFP_KERNEL); >> + if (!p) >> + goto err; >> >> p->migratable = migratable; >> - >> +err: >> return p; > > This is clearly a code migration bug in > > commit 251c85bd106099e6f388a89e88e12d14de2c9cda > Author: Sumit Garg > Date: Mon Mar 1 18:41:24 2021 +0530 > > KEYS: trusted: Add generic trusted keys framework > > Which has for addition to trusted_core.c: > > +static struct trusted_key_payload *trusted_payload_alloc(struct key > *key) > +{ > + struct trusted_key_payload *p = NULL; > + int ret; > + > + ret = key_payload_reserve(key, sizeof(*p)); > + if (ret < 0) > + return p; > + p = kzalloc(sizeof(*p), GFP_KERNEL); > + > + p->migratable = migratable; > + > + return p; > +} > > And for trusted_tpm1.c: > > -static struct trusted_key_payload *trusted_payload_alloc(struct key > *key) > -{ > - struct trusted_key_payload *p = NULL; > - int ret; > - > - ret = key_payload_reserve(key, sizeof *p); > - if (ret < 0) > - return p; > - p = kzalloc(sizeof *p, GFP_KERNEL); > - if (p) > - p->migratable = 1; /* migratable by default */ > - return p; > -} > > The trusted_tpm1.c code was correct and we got this bug introduced by > what should have been a simple cut and paste ... how did that happen? > And therefore, how safe is the rest of the extraction into > trusted_core.c? > fortunately it gets caught by static analysis, but it does make me also concerned about what else has changed and how this gets through review. > James > >