Received: by 2002:a25:ad19:0:0:0:0:0 with SMTP id y25csp3135015ybi; Thu, 18 Jul 2019 21:43:01 -0700 (PDT) X-Google-Smtp-Source: APXvYqxrRu3daDB+n+EUN/3Wj7x+7QtL4mTrcVrMaJb3cbSA+VAyzDYnEIR5DPkE9IIjnFe/U4fh X-Received: by 2002:a17:902:24c:: with SMTP id 70mr54109588plc.2.1563511381257; Thu, 18 Jul 2019 21:43:01 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1563511381; cv=none; d=google.com; s=arc-20160816; b=f2Riiawwc712xfrqXXL1NWBwDm+ZJhgMAvbbAS4u1XHVWbOjn8x+KjUk40LF7L/DAN CVuO5RBE1uB9rtV2oRyRxJzotWElZhIv8ADVtOikbLFWfX10DlyA3kmO4Fg60ZZOP9Ww cdFQVy9GjdgsYLtkemoYf0J9kkqq44QiwXZK8I24nc/EQfCCORwfI3FCsYM3NDsr4g1m SbWq+/fkwF1A364KDOUUdaooDx879c2SD6K0c92PybeISQM+7ISJNtf+97w/+6ul7WEl 6t0N/kZQ30zxjS1aEcKVGqRnE3Z/rC9v8BXIehSnxeARXBbG8rO17Q0ZMNxtUZE1AakH Da5A== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:content-transfer-encoding:mime-version :references:in-reply-to:message-id:date:subject:cc:to:from :dkim-signature; bh=kby8MKJzNQDFQihu6RiDgbMD1DlbcOn87uAChnmrCSM=; b=IgB0I1nmSedJxIxnn0yAcniPpNFZJvCRqqk3X7wknTRT+ZnhnKdUbIMos0B8kz6W49 pqiZzFfuPO/RPvC8t7+/9xgskivkH5/EJGYz9eM2HypagB/TkXzHDYGAJcHPX18iBtj+ NWzj4mycGTyiUh2MLjqVdSnzX6B5zczaXs5zreolvoG8TIWmqrutKMjG3h1pRWb4vmsb L92S6CwwK8uCg7T7cLj1SrdcRQXn9pVQFzdFp3T7wZdP/OjICpQ/ij2F/c3vjv1ZxhoM QOAe6f+UpTD65n4H2/LNzQ4jRX8RMjwQBVhCEP/N+XrXn3PZ5JuiiEUJLyFyi1g2Pjm8 JXAQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=default header.b=oKvUpsRs; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id v22si1454894pfe.275.2019.07.18.21.42.45; Thu, 18 Jul 2019 21:43:01 -0700 (PDT) Received-SPF: pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; dkim=pass header.i=@kernel.org header.s=default header.b=oKvUpsRs; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1728237AbfGSEka (ORCPT + 99 others); Fri, 19 Jul 2019 00:40:30 -0400 Received: from mail.kernel.org ([198.145.29.99]:57178 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1727663AbfGSD56 (ORCPT ); Thu, 18 Jul 2019 23:57:58 -0400 Received: from sasha-vm.mshome.net (c-73-47-72-35.hsd1.nh.comcast.net [73.47.72.35]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPSA id 2639621852; Fri, 19 Jul 2019 03:57:57 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1563508677; bh=khMITClIFeXYHdEQNwwvpfphNqgiJNWFhLiR+IZGREI=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=oKvUpsRssfQ8VQP8vcRtJgmvJwWU9eRr5uf5RAdT4YS14I68v8AktSGv2K19c3n7f sk74o638qGsytmbiAt91Wv1p7lm9a0cpNx8D+tPfv7WL2jt5X+/c1ZjrYy1CGTIuSn eDhldfvJhdun9YScljXmaGrEZ8n7wnTG8/LpfGjw= From: Sasha Levin To: linux-kernel@vger.kernel.org, stable@vger.kernel.org Cc: Gen Zhang , Jani Nikula , Sasha Levin , dri-devel@lists.freedesktop.org Subject: [PATCH AUTOSEL 5.2 029/171] drm/edid: Fix a missing-check bug in drm_load_edid_firmware() Date: Thu, 18 Jul 2019 23:54:20 -0400 Message-Id: <20190719035643.14300-29-sashal@kernel.org> X-Mailer: git-send-email 2.20.1 In-Reply-To: <20190719035643.14300-1-sashal@kernel.org> References: <20190719035643.14300-1-sashal@kernel.org> MIME-Version: 1.0 X-stable: review X-Patchwork-Hint: Ignore Content-Transfer-Encoding: 8bit Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org From: Gen Zhang [ Upstream commit 9f1f1a2dab38d4ce87a13565cf4dc1b73bef3a5f ] In drm_load_edid_firmware(), fwstr is allocated by kstrdup(). And fwstr is dereferenced in the following codes. However, memory allocation functions such as kstrdup() may fail and returns NULL. Dereferencing this null pointer may cause the kernel go wrong. Thus we should check this kstrdup() operation. Further, if kstrdup() returns NULL, we should return ERR_PTR(-ENOMEM) to the caller site. Signed-off-by: Gen Zhang Reviewed-by: Jani Nikula Signed-off-by: Jani Nikula Link: https://patchwork.freedesktop.org/patch/msgid/20190524023222.GA5302@zhanggen-UX430UQ Signed-off-by: Sasha Levin --- drivers/gpu/drm/drm_edid_load.c | 2 ++ 1 file changed, 2 insertions(+) diff --git a/drivers/gpu/drm/drm_edid_load.c b/drivers/gpu/drm/drm_edid_load.c index 1e5593575d23..6192b7b20d84 100644 --- a/drivers/gpu/drm/drm_edid_load.c +++ b/drivers/gpu/drm/drm_edid_load.c @@ -278,6 +278,8 @@ struct edid *drm_load_edid_firmware(struct drm_connector *connector) * the last one found one as a fallback. */ fwstr = kstrdup(edid_firmware, GFP_KERNEL); + if (!fwstr) + return ERR_PTR(-ENOMEM); edidstr = fwstr; while ((edidname = strsep(&edidstr, ","))) { -- 2.20.1