Received: by 2002:a05:6a10:2726:0:0:0:0 with SMTP id ib38csp943589pxb; Wed, 6 Apr 2022 05:00:25 -0700 (PDT) X-Google-Smtp-Source: ABdhPJysjmvNbdDpM5A3mKM7JzIuAKELWi4XtXYQWjBvKd3HEm97Z+VtlClW4P7LfjYg5c9ppHtx X-Received: by 2002:a17:90b:1b0f:b0:1c6:ed78:67ad with SMTP id nu15-20020a17090b1b0f00b001c6ed7867admr9509217pjb.41.1649246425446; Wed, 06 Apr 2022 05:00:25 -0700 (PDT) ARC-Seal: i=2; a=rsa-sha256; t=1649246425; cv=pass; d=google.com; s=arc-20160816; b=R1GVbP2Vt3kfny7F6uREeA0g6Yi7R73fb+SemzvCm7GOS2NgIZ2ErqHBC7x97dLeBl Yf/QuoNQGSvBuKzcIgCv4B5Lwdtey0pm2oYCxGfhJ72/nmkxXozmYXlhiUlK44U8C6wx bkV8nVlqFCY1aXCsEhU2lRirinIa3uxCMt9Tg+q3oUQDbl6KSs4BOgfjSjt0xYpiOLCE akaT5aq8pYl0i385AQimWC5Lj//zALQXF/x8YwX/Oln9nJIR4BviboQO8cmOLra0YrtA OM/hrmasZI5gtCDsIwG5MEuraLjUCH8Zx2IPSxSlpc9XAocq36k3Vs+ALqtKt2RDyr5B 29AA== ARC-Message-Signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:mime-version:content-transfer-encoding :in-reply-to:from:references:cc:to:content-language:subject :user-agent:date:message-id:dkim-signature; bh=bRhaSgwQxursOeBtc3su16M0VCK+blA/0dBA1VenjL8=; b=bX8I5u77uwT9siyF3EOOiLe5kXJrpJlSDh0aaRH5Hc8lzVAOzsV2hokvcD+2JFF0Sx 7JEdycj7NLAb0xJ48Rcv4AcaboVz9/IIJIyz1RxBOSwdqtojXBmZGBA/9nagnkZWs+E/ 6+YOjmQnFM0GOjKLmA1+vVfnZJksGW1bTwkS6BQr6vQ3BRKpI8bn6X7LrwxKmQ0bRZ7J 8sZHF2YtnUNf3YomLJ9ZTNG9xhexS74K5Z759sLXt/jB615kr43Wt5pwhzEf9DBNC+K7 Fx7uW4zHB5UIBYbGoPFF0cAnJToc4X8YMlRgpGVzbZuFQi8sJZfXYSkcIRJTUKBVOcLi zDCQ== ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@amd.com header.s=selector1 header.b=oPylPikB; arc=pass (i=1 spf=pass spfdomain=amd.com dkim=pass dkdomain=amd.com dmarc=pass fromdomain=amd.com); spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=QUARANTINE sp=QUARANTINE dis=NONE) header.from=amd.com Return-Path: Received: from lindbergh.monkeyblade.net (lindbergh.monkeyblade.net. [2620:137:e000::1:18]) by mx.google.com with ESMTPS id lr1-20020a17090b4b8100b001cab7e7bcccsi5426892pjb.44.2022.04.06.05.00.24 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 06 Apr 2022 05:00:25 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:18 as permitted sender) client-ip=2620:137:e000::1:18; Authentication-Results: mx.google.com; dkim=pass header.i=@amd.com header.s=selector1 header.b=oPylPikB; arc=pass (i=1 spf=pass spfdomain=amd.com dkim=pass dkdomain=amd.com dmarc=pass fromdomain=amd.com); spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=QUARANTINE sp=QUARANTINE dis=NONE) header.from=amd.com Received: from out1.vger.email (out1.vger.email [IPv6:2620:137:e000::1:20]) by lindbergh.monkeyblade.net (Postfix) with ESMTP id 910B1664552; Wed, 6 Apr 2022 03:23:49 -0700 (PDT) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1575706AbiDEXIv (ORCPT + 99 others); Tue, 5 Apr 2022 19:08:51 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:54448 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1457980AbiDERCr (ORCPT ); Tue, 5 Apr 2022 13:02:47 -0400 Received: from NAM12-BN8-obe.outbound.protection.outlook.com (mail-bn8nam12on2050.outbound.protection.outlook.com [40.107.237.50]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 9356B2E9C6 for ; Tue, 5 Apr 2022 10:00:48 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=KqQZ6NCU5VOhj72Qsfr+htZee5eDN3kSAY8PIJoflHkBhFssomsMxb3fXSQHCJTVB56bVEc0EwLg+AftRlF95Z5IhiBF0u5xuGqPBd7eTdc3iSAQf2yJho8F2/a5Tij5rOHDkRmsd3T5T3RgkhFTsoga31jLra//O94cwaG10yjN59lgJNiTXP8LcmzLeCe39qvBFeoduMLfGlEnBzbk50AjQqx8Q8qXPG6pNqiWtFgwVQKuviBI2CJoojAxk68zxQz1sARLzJzEdVfOJ83C71wHsEtA5x0Uuss2y8FjvdI4DqEP3b6n1NqntqpYCFaU2tyKYhp8iYqDhKGRu7Ktsg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=microsoft.com; s=arcselector9901; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-AntiSpam-MessageData-ChunkCount:X-MS-Exchange-AntiSpam-MessageData-0:X-MS-Exchange-AntiSpam-MessageData-1; bh=bRhaSgwQxursOeBtc3su16M0VCK+blA/0dBA1VenjL8=; b=V94L0D4RsMp4DGMAth0C/3OjCezFcBImYG6+dSM6PBCujw3/qQM2E8D/woeNeDB26/ViGCjJBL+VLv03oTE9OdeXlU5WCLVOK4Dt6ogI5Sh7NVz53HyK91/NOTzmiSzJz1NmNSxQvifo9/el6eQSSikV4EfCNSj8nOwarjkC6DiS0cts4OwYWQAz4Oi5MXab4yBC2WRZB3nx9HSwtdzolmsSVmsJBLsvRvs+ZoqHFzmTrJG5HUNgwtrFU6XTn7XL0yvsGZP31ssbzI0SDL63/emhtZBCAlOiiTSu+KC3VRro7/MvpyHll6+cpqRWiaQ8iUOCLKaDbsJeGz08fy5JqA== ARC-Authentication-Results: i=1; mx.microsoft.com 1; spf=pass smtp.mailfrom=amd.com; dmarc=pass action=none header.from=amd.com; dkim=pass header.d=amd.com; arc=none DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=amd.com; s=selector1; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck; bh=bRhaSgwQxursOeBtc3su16M0VCK+blA/0dBA1VenjL8=; b=oPylPikBGsqm+wt/eQTRAOu6YJ15mQIpOwnN+Dzegpdxliu5gIql5CZLmQ22j6V/yPRCKYZQa5gCxi10qXlQHujPtdWSfAI+2yFASOJu0JgOECn8M9IPqihZyCYCcG3IDbKNLkCP6medFmlp6DMMORbMGeBHdiub4yAhxwOnXW0= Authentication-Results: dkim=none (message not signed) header.d=none;dmarc=none action=none header.from=amd.com; Received: from BN9PR12MB5115.namprd12.prod.outlook.com (2603:10b6:408:118::14) by CO6PR12MB5474.namprd12.prod.outlook.com (2603:10b6:303:139::9) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.5123.31; Tue, 5 Apr 2022 17:00:45 +0000 Received: from BN9PR12MB5115.namprd12.prod.outlook.com ([fe80::4839:9431:1040:5cd5]) by BN9PR12MB5115.namprd12.prod.outlook.com ([fe80::4839:9431:1040:5cd5%3]) with mapi id 15.20.5123.031; Tue, 5 Apr 2022 17:00:44 +0000 Message-ID: Date: Tue, 5 Apr 2022 13:00:42 -0400 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:91.0) Gecko/20100101 Thunderbird/91.7.0 Subject: Re: [PATCH] drm/amdkfd: Fix potential NULL pointer dereference Content-Language: en-US To: Grigory Vasilyev , Rodrigo Siqueira , Melissa Wen Cc: "Pan, Xinhui" , linux-kernel@vger.kernel.org, amd-gfx@lists.freedesktop.org, David Airlie , dri-devel@lists.freedesktop.org, Alex Deucher , =?UTF-8?Q?Christian_K=c3=b6nig?= References: <20220404222132.12740-1-h0tc0d3@gmail.com> From: Felix Kuehling In-Reply-To: <20220404222132.12740-1-h0tc0d3@gmail.com> Content-Type: text/plain; charset=UTF-8; format=flowed Content-Transfer-Encoding: 8bit X-ClientProxiedBy: YT1PR01CA0115.CANPRD01.PROD.OUTLOOK.COM (2603:10b6:b01:2c::24) To BN9PR12MB5115.namprd12.prod.outlook.com (2603:10b6:408:118::14) MIME-Version: 1.0 X-MS-PublicTrafficType: Email X-MS-Office365-Filtering-Correlation-Id: e58d55df-24a7-477a-d4f9-08da1725d2dc X-MS-TrafficTypeDiagnostic: CO6PR12MB5474:EE_ X-Microsoft-Antispam-PRVS: X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: cvOjWkzxtFGgp1x+8pubBFHIzA7ofEHVS6FnkBS5br2GBpR1CdQi3oKLl+K8m631CvPMdBSfKbDPzM4NRgmFjSkGF1rLegK3V8fIwbphjhu5AH7lm8EGPaQZMaek6lwvzr0BmSpWS/m7eWbc/gWPguAWCdm7hgy4T0YwLo2DLoeA+KyEnns1GsFtm63wTxLQg1icg7wQj4+t/8I0iFH26vyaq+KLDEppBouEeSCYbmZJJNwah2MnaQnk3Jb8TfHis8zSxp0VHGUVHSa1Lql9Qe5MuZQEau9tdWiFI0qi05WT1NmAw2f2KrwC+mFzNlkQLFcsngsFKd8xEt/3ZbR+iSqLdRE3kjT1NGlbhB57d7lq9CQ9OGIzheQP/zy/ltV2f+wYuQqWAxVrqkdGocFyZ0LpubgG2DFSk5/RRvsgqLNtvkLtCYBu2NSEYhJ8CoSkvO5RPwMZn40TyUtrSAoeRz2CRrOTGYg7y9Q1o3ByMA8rAS99hg9KUqrEzsLwa7IJWXetB2fLdiYJcE2YBRoHxSgSQ5X9NJ0CbFuAhm8491aCiFQpy2QDSU4J8C+T2gc9FR1ibu/xxkNJB5kMeHafADtmSUX2b1b5W65biLem8fL4KcsrIYFvu63ZmaUe5VwOzGp33AUM0kfEJSef82JLZ/D4ooWZAKUl5Aherdiax1grCtGwGTgfhGR6VD1WxL2st5QKc0VZXoaxym9y04IaQPaSwOoCAxRXD5PH4zsofiY= X-Forefront-Antispam-Report: CIP:255.255.255.255;CTRY:;LANG:en;SCL:1;SRV:;IPV:NLI;SFV:NSPM;H:BN9PR12MB5115.namprd12.prod.outlook.com;PTR:;CAT:NONE;SFS:(13230001)(4636009)(366004)(8676002)(36756003)(26005)(2616005)(4326008)(66946007)(186003)(6512007)(38100700002)(66476007)(31686004)(66556008)(83380400001)(6506007)(8936002)(110136005)(31696002)(508600001)(5660300002)(44832011)(2906002)(54906003)(6486002)(316002)(86362001)(43740500002)(45980500001);DIR:OUT;SFP:1101; X-MS-Exchange-AntiSpam-MessageData-ChunkCount: 1 X-MS-Exchange-AntiSpam-MessageData-0: =?utf-8?B?RUIyRXB5dzNTK2loOHA5ZEJoVWNYQi8xQ0YrZ0Jwc0hDZG03U3llSERTVnp4?= =?utf-8?B?Y1ZzUmhHVENUcHJsdEovaWZIL3paTDhCdEZwa0dQTXl2YWVQd3c3UE5iQnNk?= =?utf-8?B?Zm42bUVvd3lieERxdW5yU00zVUNydXJDd0xSV0dKWVVrNTNtbk9PZFM5cXhX?= =?utf-8?B?anEyOFhxcS9NQzI3NFlNK2lQeGRFektQdFNPWGJqZW1yNUxqVDZTOHpodW4w?= =?utf-8?B?cHhDRi9HQjkyT1lHR0ZNSkZNSU5ZT3pTSUc4RkpWSGQzVlRoY0pCODkxaDV0?= =?utf-8?B?YWdVeGZ4ZG1DdnIrekdDbWlaWFE4OER3RDhlNmg2RlJHc2VXMVBpZzNUdTQw?= =?utf-8?B?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YWGxFNTR2ZmwvMFdiZzdJ?= =?utf-8?B?VU55dGFkWVRVeXVWQ3pEUUovTlduSTRrSDR4UDdDcy9XMjFzQ0huTy9GazEz?= =?utf-8?B?WGZGQnRIUFR4akRJQWJnWHl3amFQV2FJUyttV0phY0dONEhycUtvVVY5RFhU?= =?utf-8?B?UDlzanVycTJQME52OVV2SitPbU9MUmRqYlFlRFVNeFhyMDlGZ0JtZz09?= X-OriginatorOrg: amd.com X-MS-Exchange-CrossTenant-Network-Message-Id: e58d55df-24a7-477a-d4f9-08da1725d2dc X-MS-Exchange-CrossTenant-AuthSource: BN9PR12MB5115.namprd12.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 05 Apr 2022 17:00:44.7606 (UTC) X-MS-Exchange-CrossTenant-FromEntityHeader: Hosted X-MS-Exchange-CrossTenant-Id: 3dd8961f-e488-4e60-8e11-a82d994e183d X-MS-Exchange-CrossTenant-MailboxType: HOSTED X-MS-Exchange-CrossTenant-UserPrincipalName: 9cSFjzYDu1rICe6cV4W256XyAHzXOktmnWKAirf4l0dzwAiJWbGaYYlUv9qi/nmE/ATXqmjPL9hz+Ne+iu1ONg== X-MS-Exchange-Transport-CrossTenantHeadersStamped: CO6PR12MB5474 X-Spam-Status: No, score=-4.8 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,HEADER_FROM_DIFFERENT_DOMAINS, MAILING_LIST_MULTI,NICE_REPLY_A,RDNS_NONE,SPF_HELO_NONE, T_SCC_BODY_TEXT_LINE autolearn=unavailable autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Am 2022-04-04 um 18:21 schrieb Grigory Vasilyev: > In the amdgpu_amdkfd_get_xgmi_bandwidth_mbytes function, > the peer_adev pointer can be NULL and is passed to amdgpu_xgmi_get_num_links. > > In amdgpu_xgmi_get_num_links, peer_adev pointer is dereferenced > without any checks: peer_adev->gmc.xgmi.node_id . What's worse, peer_adev is uninitialized with an undefined value if src is NULL. So that code was definitely bogus. However, I think your patch will result in incorrect results. Currently amdgpu_amdkfd_get_xgmi_bandwidth is always called with is_min=true if src==NULL, and with is_min=false if src!=NULL. The intention is, that we assume a single XGMI link in the case that src==NULL. That means the is_min parameter is redundant. What we should do instead is, assume that num_links==1 if src==NULL, and drop the is_min parameter. That would keep things working the way they do now, and prevent potential problems in the future. Regards,   Felix > > Signed-off-by: Grigory Vasilyev > --- > drivers/gpu/drm/amd/amdgpu/amdgpu_amdkfd.c | 5 ++--- > 1 file changed, 2 insertions(+), 3 deletions(-) > > diff --git a/drivers/gpu/drm/amd/amdgpu/amdgpu_amdkfd.c b/drivers/gpu/drm/amd/amdgpu/amdgpu_amdkfd.c > index be1a55f8b8c5..1a1006b18016 100644 > --- a/drivers/gpu/drm/amd/amdgpu/amdgpu_amdkfd.c > +++ b/drivers/gpu/drm/amd/amdgpu/amdgpu_amdkfd.c > @@ -541,11 +541,10 @@ int amdgpu_amdkfd_get_xgmi_bandwidth_mbytes(struct amdgpu_device *dst, > struct amdgpu_device *adev = dst, *peer_adev; > int num_links; > > - if (adev->asic_type != CHIP_ALDEBARAN) > + if (!src || adev->asic_type != CHIP_ALDEBARAN) > return 0; > > - if (src) > - peer_adev = src; > + peer_adev = src; > > /* num links returns 0 for indirect peers since indirect route is unknown. */ > num_links = is_min ? 1 : amdgpu_xgmi_get_num_links(adev, peer_adev);