Received: by 2002:a05:6a10:af89:0:0:0:0 with SMTP id iu9csp2748416pxb; Mon, 31 Jan 2022 03:32:06 -0800 (PST) X-Google-Smtp-Source: ABdhPJwNFI4QoDza6GmMpv8+YJPOl+GXheaUjgDyiTTi9vRCNmeS7+ulMLD4cfmsxD8J/eExh55G X-Received: by 2002:aa7:8a05:: with SMTP id m5mr19649017pfa.40.1643628726284; Mon, 31 Jan 2022 03:32:06 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1643628726; cv=none; d=google.com; s=arc-20160816; b=ouPNN9ncZfwvA2jIZkJtvyeA2FHTqj1c0VPOTblt44IHQK9f8PbfveYNQyHIddLUjB DC++fUkjEpOiFP/4+lcHaekb9NvIFcGmVdoFbSZ0FtZyBCXaILX8lPycE/31EQgVQ4Mx j96MjhE5MQLJ1KaRtD9yQ7Cq9upXiN7EoE/nqocSRCIRGbRkjw+1qr6+BbDyLm8oF7f+ 6G1hFTgUhRpXp/8aG9VEKXeDHQk6owObczZ2bR5u9ojRiujAG7lWbxJoAMzehW7tCTRH c5P0f5jvTz9pQDsifN0DyTzSOTUfsOfycGxHQ9D/gd8rWXWqt0YtI6OQMzGfYu2OzD6T XuUw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:cc:to:subject:message-id:date:from:in-reply-to :references:mime-version:dkim-signature; bh=coCa9J+GhEzNyejkCKSC7tpX70/70zSfnqE1h06XrJU=; b=yeY1y/Om3M2lWSRARo/E3GS9jane8HNKjMO1JpTQa3nc/ps5/NXBFkMRZJUddgfjKF WLFmmegtmVS1VkRw8kwCblZCkoWlEeRLvKRVcth1LpaIEZxqhVauanqHt+ZgFAHIXMpH 1RK0nWKRypVSz+zhjr4AxgT28HOLKD0zs05vK+lxMdtq9TyrY8c2gqcHqZhhQaWj7y1W myGoOP2ZMHhzwTUQHcOgK6IrodWQ2zrWLo5RWU+AM1HqdrsRmAZT7I/DB6EB2RTamr7+ OVCuT5G0pQu3FZWbvwk91TivkR7M5ARwNyKh5khxnTXBzvSuAnsN174HMkQA9lzgtTsP WU5w== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@redhat.com header.s=mimecast20190719 header.b=OAzxeyOh; 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=redhat.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id j69si10214849pgd.506.2022.01.31.03.31.55; Mon, 31 Jan 2022 03:32:06 -0800 (PST) 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=@redhat.com header.s=mimecast20190719 header.b=OAzxeyOh; 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=redhat.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S232004AbiA1T6s (ORCPT + 99 others); Fri, 28 Jan 2022 14:58:48 -0500 Received: from us-smtp-delivery-124.mimecast.com ([170.10.129.124]:38700 "EHLO us-smtp-delivery-124.mimecast.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1351132AbiA1T6K (ORCPT ); Fri, 28 Jan 2022 14:58:10 -0500 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1643399890; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: in-reply-to:in-reply-to:references:references; bh=coCa9J+GhEzNyejkCKSC7tpX70/70zSfnqE1h06XrJU=; b=OAzxeyOh9lXRGj+waujr8bQ9bbDXRFaD7t5n8HSVS4IkklLz6s7L6k8Z9eKwLI7O6glBwN j5JTxvJDSpf0FeOV6RYhkW7sgZdkz0XdhbjGheop3r3pJJBwn38eKAsfRZlncGUIqG6e22 2M6+avLpDM3f8L0DNM3SuVANl1zJgQw= Received: from mail-wm1-f69.google.com (mail-wm1-f69.google.com [209.85.128.69]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id us-mta-613-V5uFpz1wM7-cgIgJmKDe8Q-1; Fri, 28 Jan 2022 14:58:08 -0500 X-MC-Unique: V5uFpz1wM7-cgIgJmKDe8Q-1 Received: by mail-wm1-f69.google.com with SMTP id s190-20020a1ca9c7000000b00347c6c39d9aso3406304wme.5 for ; Fri, 28 Jan 2022 11:58:08 -0800 (PST) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:mime-version:references:in-reply-to:from:date :message-id:subject:to:cc; bh=coCa9J+GhEzNyejkCKSC7tpX70/70zSfnqE1h06XrJU=; b=gJSUF540E00Lt4R/t+NRirpQ8/lXmSAXDSOHtM/ZJ3jN3v3Qs0wuf28CoM1EUEHPM6 xJ3aIX1a5U+uROLwJdWGPUj0SuBPmdQYXbtBY1BrHKXRdjBiginwlOYo5MzhnOiZ4fuA YQXShLNo8pmO0iiGPuI8Mat20AoGYLw6px2uPvhPGTzmrkDDZFOJjkLScABwwAB2vgyO Fwfmkl1c+HiYlWu3dIDbz+480zRopkW8JPArx5sqr9dP005NjH7BUybHWZAKrmq7VPxo 97dSs71qVLk8YHNPgrLRpVtrOtOZTJSB5WLyX8Qx0yRrup3PpvKPn71fEy2zHZyvp/Az e0dA== X-Gm-Message-State: AOAM533zF/mKlSOUbswbXO1BNvey+p0VdGzE2vwf+8R+ClDcr1iCyGcP f5mZPDuV52Y18rGcfbDYgnalrrBX9VNaZ7gXlz1VGIzOqbAPUx/uf1nu3RqHlYqgd9muFVS90ES GBPydoR2MBzoBW1H66XLz4BBxePRHijwaCd4JRc2Q X-Received: by 2002:a7b:c21a:: with SMTP id x26mr17301234wmi.74.1643399887596; Fri, 28 Jan 2022 11:58:07 -0800 (PST) X-Received: by 2002:a7b:c21a:: with SMTP id x26mr17301215wmi.74.1643399887368; Fri, 28 Jan 2022 11:58:07 -0800 (PST) MIME-Version: 1.0 References: <20220124165856.57022-1-zhou1615@umn.edu> <536c833413ccbe0b8ad653a50c5ea867bf975290.camel@redhat.com> In-Reply-To: From: Karol Herbst Date: Fri, 28 Jan 2022 20:57:56 +0100 Message-ID: Subject: Re: [PATCH] drm/nouveau/acr: Fix undefined behavior in nvkm_acr_hsfw_load_bl() To: Alex Deucher Cc: Lyude Paul , Greg KH , Zhou Qingyang , David Airlie , nouveau , Kangjie Lu , LKML , Maling list - DRI developers , Ben Skeggs Content-Type: text/plain; charset="UTF-8" Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Fri, Jan 28, 2022 at 8:54 PM Alex Deucher wrote: > > On Fri, Jan 28, 2022 at 2:20 PM Lyude Paul wrote: > > > > Sigh-thank you for catching this - I had totally forgot about the umn.edu ban. > > I pushed this already but I will go ahead and send a revert for this patch. > > Will cc you on it as well. > > This seems short-sighted. If the patch is valid I see no reason to > not accept it. I'm not trying to downplay the mess umn got into, but > as long as the patch is well scrutinized and fixes a valid issue, it > should be applied rather than leaving potential bugs in place. > > Alex > Even though knowing that malicious code can be introduced via perfectly fine looking patches, and sometimes one will never spot the problem, this patch isn't all that bad tbh. So should we reject patches out of "policies" or should we just be extra careful? But not addressing the concerns as Greg pointed out is also kind of a bad move, but also not knowing what the state of resolving this mess is anyway. > > > > > On Fri, 2022-01-28 at 11:18 +0100, Greg KH wrote: > > > On Tue, Jan 25, 2022 at 12:58:55AM +0800, Zhou Qingyang wrote: > > > > In nvkm_acr_hsfw_load_bl(), the return value of kmalloc() is directly > > > > passed to memcpy(), which could lead to undefined behavior on failure > > > > of kmalloc(). > > > > > > > > Fix this bug by using kmemdup() instead of kmalloc()+memcpy(). > > > > > > > > This bug was found by a static analyzer. > > > > > > > > Builds with 'make allyesconfig' show no new warnings, > > > > and our static analyzer no longer warns about this code. > > > > > > > > Fixes: 22dcda45a3d1 ("drm/nouveau/acr: implement new subdev to replace > > > > "secure boot"") > > > > Signed-off-by: Zhou Qingyang > > > > --- > > > > The analysis employs differential checking to identify inconsistent > > > > security operations (e.g., checks or kfrees) between two code paths > > > > and confirms that the inconsistent operations are not recovered in the > > > > current function or the callers, so they constitute bugs. > > > > > > > > Note that, as a bug found by static analysis, it can be a false > > > > positive or hard to trigger. Multiple researchers have cross-reviewed > > > > the bug. > > > > > > > > drivers/gpu/drm/nouveau/nvkm/subdev/acr/hsfw.c | 9 +++++---- > > > > 1 file changed, 5 insertions(+), 4 deletions(-) > > > > > > > > diff --git a/drivers/gpu/drm/nouveau/nvkm/subdev/acr/hsfw.c > > > > b/drivers/gpu/drm/nouveau/nvkm/subdev/acr/hsfw.c > > > > index 667fa016496e..a6ea89a5d51a 100644 > > > > --- a/drivers/gpu/drm/nouveau/nvkm/subdev/acr/hsfw.c > > > > +++ b/drivers/gpu/drm/nouveau/nvkm/subdev/acr/hsfw.c > > > > @@ -142,11 +142,12 @@ nvkm_acr_hsfw_load_bl(struct nvkm_acr *acr, const > > > > char *name, int ver, > > > > > > > > hsfw->imem_size = desc->code_size; > > > > hsfw->imem_tag = desc->start_tag; > > > > - hsfw->imem = kmalloc(desc->code_size, GFP_KERNEL); > > > > - memcpy(hsfw->imem, data + desc->code_off, desc->code_size); > > > > - > > > > + hsfw->imem = kmemdup(data + desc->code_off, desc->code_size, > > > > GFP_KERNEL); > > > > nvkm_firmware_put(fw); > > > > - return 0; > > > > + if (!hsfw->imem) > > > > + return -ENOMEM; > > > > + else > > > > + return 0; > > > > } > > > > > > > > int > > > > -- > > > > 2.25.1 > > > > > > > > > > As stated before, umn.edu is still not allowed to contribute to the > > > Linux kernel. Please work with your administration to resolve this > > > issue. > > > > > > > -- > > Cheers, > > Lyude Paul (she/her) > > Software Engineer at Red Hat > > >