Received: by 2002:a05:6a10:af89:0:0:0:0 with SMTP id iu9csp2748576pxb; Mon, 31 Jan 2022 03:32:18 -0800 (PST) X-Google-Smtp-Source: ABdhPJzvkzZqBb2AxHzAsIFSZLtKf04430t8jFhrYn+Wj3hzOM3yQhTK66r+ZNbm1T5gUqj0zphT X-Received: by 2002:a17:902:7ecf:: with SMTP id p15mr20782144plb.112.1643628737914; Mon, 31 Jan 2022 03:32:17 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1643628737; cv=none; d=google.com; s=arc-20160816; b=Saw1bnGHKGHveZW4P4K27iScgm5l4Abz0txYzJeZ1io8cjiOy7tyqiV8VfQmgogchm fhSkx/j18CWBSDi1VXTI60QO4yvlKKkg1uJ2hgH68Ofo7vKzrv26RWdooffIoI999/re lqIxVCKAaGGRODTHk/x4BGZhZ6U0l/OPQhFNCf34flNKf93/fozb/jO67TQQzP8/ssqi s12Vq5wx9k9gb6Ou0a7Q+lmwWe+Qi4zZvenzp9pK2W6owt6mzcuRvyJfrSyOrIj8oskv 8DkXdBkmiInhLVhuFzhOEwJ9HYWUqEh9+qzOcEFRddPxIvNd2qWlJRXCKUqOD0DZoW4v 637Q== 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=4KPQs4BICnK1jcv7Ue8a1i7g7BfJfHr1ekNmdCInY0w=; b=MT/DYfr7ryJ0nvqBXfXYdiR6xzzGYQLRhDgaYUwZCS3M7fJiHTg7pgeOqub6gBinfR I4Ziu079/RCarqGih2T6I0YSYpSZDfqix/lBn6zlJGuV3tJx4INaywv61ZpWAhByENdw dB5cxxgi+f8o6mNvEaRg1YSgN42N4RQeeK8pfWI3CHYBx/w6gaCEbHU1rg3eBLtu9C5P gWKojBxPnz3/zLsGjHV0ALHJ29Y2f660yRQhssz7VmSxnwJ89QKRTRnp1nKSFYGFN60s xB1Drx6sy/M2Sm+M6UPjMU3QSS70IIFxW6HApQ3bGUF6qCmUHAucWz1q+83A+bBNd54s bgQw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@gmail.com header.s=20210112 header.b=l4flimN6; 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=QUARANTINE dis=NONE) header.from=gmail.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id 195si12775163pga.696.2022.01.31.03.32.07; Mon, 31 Jan 2022 03:32:17 -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=@gmail.com header.s=20210112 header.b=l4flimN6; 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=QUARANTINE dis=NONE) header.from=gmail.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1344304AbiA1UCC (ORCPT + 99 others); Fri, 28 Jan 2022 15:02:02 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:35280 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S245650AbiA1UCA (ORCPT ); Fri, 28 Jan 2022 15:02:00 -0500 Received: from mail-oi1-x22c.google.com (mail-oi1-x22c.google.com [IPv6:2607:f8b0:4864:20::22c]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 909DBC061714 for ; Fri, 28 Jan 2022 12:02:00 -0800 (PST) Received: by mail-oi1-x22c.google.com with SMTP id w133so14375876oie.7 for ; Fri, 28 Jan 2022 12:02:00 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20210112; h=mime-version:references:in-reply-to:from:date:message-id:subject:to :cc; bh=4KPQs4BICnK1jcv7Ue8a1i7g7BfJfHr1ekNmdCInY0w=; b=l4flimN6Rgf2/XPpkMw15pfJ9RHpjcAibkUIjUJN7f5ACxUodXF5fhtEiLq25oN2nQ Ig0/aMHr46/+8YDNpR6y5kh/KWNZZGwl1/RlBB4a7jd41u9I8t4acBrM1vP/w+FGwjuO Z1JOz+F9UXZk2roXWX6TIZbw4aK+a1s25EbraaIMhdci7VexsfqRMupQ7nIlFtASA/sh /RemWindYWXe6KXXrV+wzRWDOv4L7GiyOql4NLTmLnT2GTsuJyBlFPQbINI742iYYadJ vwJ+Iq2U9y6g/xgFXqsycHnHfckiim44vVngighjOBQ14AImYd2odulSZR/M5aQ7ExGg Gl+w== 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=4KPQs4BICnK1jcv7Ue8a1i7g7BfJfHr1ekNmdCInY0w=; b=bOKlWv5ysewKrRgAvoJ1+xfV8j2b8YZ/2fIX64d4xoA8l3LyRQX6ifQNWEzdmb071l zyPj921zAa2AXTDqcduwVriLTAQhtehM6kDQg9RYPPCCdR39evbNTItRwPaOetz3h8uj KyDOIV57axoTmc50c9lMiABnCHUk9l1ZcAf8SZNX6yC1El9/Ng80NrU+dWTmYieLe0Em 6GJMRG4qXwM56ILzxzLesJiVwU4C/i1AMxIlPR9/86su3G2ipHI7CRqPaL3IDTXlNNbd /FMcK86cQiE6c8eljxmfNDhQO6YugpN9toLNYcIMLhB76TYFw3WN843wUbRF2WzwPa+u azog== X-Gm-Message-State: AOAM530h9XItuP3HYNHm0YcMAZgeJcaUCxJhU9K/3gqnqGE+hNdmbCgV PySKP7wpC2AVNp3PUdxgAD9ap7b+t8TuabKwy8c= X-Received: by 2002:a05:6808:2189:: with SMTP id be9mr11252433oib.93.1643400119936; Fri, 28 Jan 2022 12:01:59 -0800 (PST) MIME-Version: 1.0 References: <20220124165856.57022-1-zhou1615@umn.edu> <536c833413ccbe0b8ad653a50c5ea867bf975290.camel@redhat.com> In-Reply-To: From: Alex Deucher Date: Fri, 28 Jan 2022 15:01:48 -0500 Message-ID: Subject: Re: [PATCH] drm/nouveau/acr: Fix undefined behavior in nvkm_acr_hsfw_load_bl() To: Karol Herbst 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 2:58 PM Karol Herbst wrote: > > 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. I think if the umn mess taught us anything, it's the need for more careful scrutiny. But I certainly don't have the time to retype every valid patch if it comes from a umn source. There are also ethical implications to that as well. You didn't actually write the patch. Alex > > > > > > > > > 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 > > > > > >