Received: by 2002:a05:6358:d09b:b0:dc:cd0c:909e with SMTP id jc27csp10088255rwb; Fri, 25 Nov 2022 00:30:11 -0800 (PST) X-Google-Smtp-Source: AA0mqf7za+8pMMJo095qEMnCL2DFngi1lm9Axe5yXxWJQ4ZZ/lxjpsy2gzVYaFIQBc+WFjxQJbME X-Received: by 2002:aa7:c85a:0:b0:45f:b9d8:9514 with SMTP id g26-20020aa7c85a000000b0045fb9d89514mr34306349edt.204.1669365011418; Fri, 25 Nov 2022 00:30:11 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1669365011; cv=none; d=google.com; s=arc-20160816; b=U8wu5Qzo1mL1nuzs57h4zAucTIaUqDDqVlUAjwgDpgIquD+qdyoS3yraeG5r1FtIVf 0i+bmRfVwR7y/tfEtcX4msk3hgnErUNn7fBL+8y5rE6X6grKPAwotYLzb5krpvE1UQtq gieF9CgnoAB37LSl6VEdS9k6pKMW3wHtCMdupvI6Ei6PBF7ffhiDaHh8KGQkc3oYye1C nu+bQ2gZOFfNPll/lYRcKjLoSJoBhYoeM+lykJzbOzb80wex2gTssq5Gie5yGElrjzQy 1G7RZ9r6JKF9s6jYVE1QJAsvxhAuRAaT1N2dug8apNU5/puSgUXxe6bhZ405frNdUm21 Dduw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:mime-version:message-id:date:references :organization:in-reply-to:subject:cc:to:from:dkim-signature; bh=hiLPIfEQ1BmVU7gt4aNCcbOFSqGb+wqJ/sOzR3DM66Y=; b=C55YnMKvivOpVIRBoOrauJZfa5arVPELiVcqbuRUcfSZnp91tsPKKHLdoBanx7mdab KJlBOuRDiLTdI+DBY/Kih+g/FPTiDhaNjw34iKsXRVZZpqrb+2gDO4hur5INogCostCT irpE++g+hDhzT2WwMcx8fr89WGtMfg8l9sDAOwzALoAVhDtukT7J2L6oXxe1t1d75pOh k+lfZwvqOqEqDeBayTn33WJ8lCzpnFo27PoeR/I/Go13P2go4oFGmqnjNdqw6AkBpoOC tzKusAtrE0hY6TNy0Bx22oi39SRELDuvPWWX+8BMR3HW+YrVexcM2lb8V8hdb6kbpnlR LIgA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@intel.com header.s=Intel header.b=bfhEQYGE; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=intel.com Return-Path: Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id g14-20020a056402090e00b00447d6f244c6si2422884edz.248.2022.11.25.00.29.49; Fri, 25 Nov 2022 00:30:11 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) client-ip=2620:137:e000::1:20; Authentication-Results: mx.google.com; dkim=pass header.i=@intel.com header.s=Intel header.b=bfhEQYGE; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=intel.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S229739AbiKYISZ (ORCPT + 86 others); Fri, 25 Nov 2022 03:18:25 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:38956 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229597AbiKYISY (ORCPT ); Fri, 25 Nov 2022 03:18:24 -0500 Received: from mga12.intel.com (mga12.intel.com [192.55.52.136]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 2DDF813E3B for ; Fri, 25 Nov 2022 00:18:24 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1669364304; x=1700900304; h=from:to:cc:subject:in-reply-to:references:date: message-id:mime-version; bh=hUfcDdsfSX5YjlGOWR2p6U6J07KOVONjwuqBLYRBav4=; b=bfhEQYGEqzxw3N37XtNJUINOLEs/LRMSwPpxnnjXAIRm7Tiebi7SCUTu YLLopRU2U06aky2ndpg4OX62dMIbCKqX+wWDLEIUh/SNsNqcxDZs8K1z1 buF10t1mSEP2vgIR3GXXUala5eFjx5gSZi4JYP13CypbGPn++mSy416ck 9GEQt0EhqndquHtULJczoffzCOT9ZnQcQ/SkdP4oUBLlnYeY4SKfpmHcz BAhlbqCW696y+RuMVay/GQCllxmjSEqTU/UG3igH0o7/DvZjJnJg2L+XK Giin33oJ5cBxcneyvCAyKPOa/g0wEvvJ/gSmx2xq6Kh7TPwLqHZNAvHRV g==; X-IronPort-AV: E=McAfee;i="6500,9779,10541"; a="294139533" X-IronPort-AV: E=Sophos;i="5.96,192,1665471600"; d="scan'208";a="294139533" Received: from fmsmga007.fm.intel.com ([10.253.24.52]) by fmsmga106.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 25 Nov 2022 00:18:23 -0800 X-IronPort-AV: E=McAfee;i="6500,9779,10541"; a="644729418" X-IronPort-AV: E=Sophos;i="5.96,192,1665471600"; d="scan'208";a="644729418" Received: from dcliffo1-mobl.ger.corp.intel.com (HELO localhost) ([10.252.17.151]) by fmsmga007-auth.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 25 Nov 2022 00:18:20 -0800 From: Jani Nikula To: Xia Fukun , airlied@gmail.com, daniel@ffwll.ch, ville.syrjala@linux.intel.com, lucas.demarchi@intel.com, joonas.lahtinen@linux.intel.com Cc: rodrigo.vivi@intel.com, tvrtko.ursulin@linux.intel.com, intel-gfx@lists.freedesktop.org, dri-devel@lists.freedesktop.org, linux-kernel@vger.kernel.org, xiafukun@huawei.com Subject: Re: [PATCH] drm/i915/bios: fix a memory leak in generate_lfp_data_ptrs In-Reply-To: <20221125063428.69486-1-xiafukun@huawei.com> Organization: Intel Finland Oy - BIC 0357606-4 - Westendinkatu 7, 02160 Espoo References: <20221125063428.69486-1-xiafukun@huawei.com> Date: Fri, 25 Nov 2022 10:18:18 +0200 Message-ID: <875yf35tx1.fsf@intel.com> MIME-Version: 1.0 Content-Type: text/plain X-Spam-Status: No, score=-4.3 required=5.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_EF,RCVD_IN_DNSWL_MED,SPF_HELO_PASS, SPF_NONE autolearn=ham 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 On Fri, 25 Nov 2022, Xia Fukun wrote: > When (size != 0 || ptrs->lvds_ entries != 3), the program tries to > free() the ptrs. However, the ptrs is not created by calling kzmalloc(), > but is obtained by pointer offset operation. > This may lead to memory leaks or undefined behavior. Yeah probably worse things will happen than just leak. > > Fix this by replacing the arguments of kfree() with ptrs_block. > > Fixes: a87d0a847607 ("drm/i915/bios: Generate LFP data table pointers if the VBT lacks them") > Signed-off-by: Xia Fukun Reviewed-by: Jani Nikula > --- > drivers/gpu/drm/i915/display/intel_bios.c | 2 +- > 1 file changed, 1 insertion(+), 1 deletion(-) > > diff --git a/drivers/gpu/drm/i915/display/intel_bios.c b/drivers/gpu/drm/i915/display/intel_bios.c > index 28bdb936cd1f..edbdb949b6ce 100644 > --- a/drivers/gpu/drm/i915/display/intel_bios.c > +++ b/drivers/gpu/drm/i915/display/intel_bios.c > @@ -414,7 +414,7 @@ static void *generate_lfp_data_ptrs(struct drm_i915_private *i915, > ptrs->lvds_entries++; > > if (size != 0 || ptrs->lvds_entries != 3) { > - kfree(ptrs); > + kfree(ptrs_block); > return NULL; > } -- Jani Nikula, Intel Open Source Graphics Center