Received: by 2002:ab2:6857:0:b0:1ef:ffd0:ce49 with SMTP id l23csp2381182lqp; Sun, 24 Mar 2024 16:54:22 -0700 (PDT) X-Forwarded-Encrypted: i=3; AJvYcCXYWZMPdAsL7W+KT9T/yArYsEuqyQpISCkeIEpBNTCuP+aUnJSJNnM6MHqIs5MiW2NMnCYb/rsMEgmspACAqgCrRBQ9CqGsHc862LZkJg== X-Google-Smtp-Source: AGHT+IFy3WKYEb86ekNRH9oSO5JVJejpKQk8OiE3pr7cxgsZKpjqEqGVIfkNTDLwv0P06s3Qg0Or X-Received: by 2002:a05:6214:f0a:b0:690:30fc:1a99 with SMTP id gw10-20020a0562140f0a00b0069030fc1a99mr7938429qvb.5.1711324462533; Sun, 24 Mar 2024 16:54:22 -0700 (PDT) ARC-Seal: i=2; a=rsa-sha256; t=1711324462; cv=pass; d=google.com; s=arc-20160816; b=Yvgc73HlwkWdAqAl18g9qoTAWJkm+0w9ebTEuFgwRMNNMa5mOFm2RsnRP12Yhkc9ht rNbSSXn54UBw2uKjiFtR3BbgOVpuynfNdBVvdg1vP3GzpLnA80puYHx06pbPWgMiC45i hg9JSn19jO1SKGvy2syHwUvNUg8Xu2Sacis0IX13ruWrhcEEgW/oXfqIPHxQZ+KUa+oB 0veVJmSajJZ/kYclmZ9hWrVXLRBiPUxNcJpoy0xxa8gXUd/cWHHDlGbEKNS+YRg1xY9W Y1Q1lD8yIuuF1AkRCH1HvmA4yk/RL5toViPWwfpPmcpiuNhu9guuLTwear0GufwkjmTG X34w== ARC-Message-Signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=content-transfer-encoding:mime-version:list-unsubscribe :list-subscribe:list-id:precedence:references:in-reply-to:message-id :date:subject:cc:to:from:dkim-signature; bh=k9aLMU5DjXw7Ej848kVBNFiDk2+ALwoXol70aHq40OI=; fh=AyitjD+m1tW2eReGs0K6Aj7FeshQ+PGZHW1+CadMVuw=; b=ymQh5C/xHbztSjMuqrru0CMyV6S87YpsAHK9lNjZ8pOnOFhYh19ZyGxeQmk9JLR1WX HLiPZ64tt30eQF7NqRyQqSbcpSxbHZC5YNHdntsJcAh6Y7IbMWae3c776ZMfOxq/yUv8 aDwJkxeWSoT8CrcgL9Zz/vktKKsYiRPewrqEbPVt0BinBCABUApZ+uNh1/sgbrBVuQqq bVWyerC9DDaDhh2UpllWNyQnVhbM3qZVpEUmSL0WjQSYjMSmpCBXWED/6Aval8vaYkeU 9YY24bBIRMKucpCoHTZjqzKPjyYH0wUoyQBcoz8A0AD95TMd1r98dPWPYTiW6C75gpNj GumQ==; dara=google.com ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@kernel.org header.s=k20201202 header.b=N49H5tpA; arc=pass (i=1 dkim=pass dkdomain=kernel.org); spf=pass (google.com: domain of linux-kernel+bounces-113251-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:45d1:ec00::1 as permitted sender) smtp.mailfrom="linux-kernel+bounces-113251-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Return-Path: Received: from ny.mirrors.kernel.org (ny.mirrors.kernel.org. [2604:1380:45d1:ec00::1]) by mx.google.com with ESMTPS id j3-20020a05621419c300b006968f144340si853280qvc.581.2024.03.24.16.54.22 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sun, 24 Mar 2024 16:54:22 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel+bounces-113251-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:45d1:ec00::1 as permitted sender) client-ip=2604:1380:45d1:ec00::1; Authentication-Results: mx.google.com; dkim=pass header.i=@kernel.org header.s=k20201202 header.b=N49H5tpA; arc=pass (i=1 dkim=pass dkdomain=kernel.org); spf=pass (google.com: domain of linux-kernel+bounces-113251-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:45d1:ec00::1 as permitted sender) smtp.mailfrom="linux-kernel+bounces-113251-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Received: from smtp.subspace.kernel.org (wormhole.subspace.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by ny.mirrors.kernel.org (Postfix) with ESMTPS id 4393C1C22D98 for ; Sun, 24 Mar 2024 23:54:22 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 35FD41870C9; Sun, 24 Mar 2024 22:40:52 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b="N49H5tpA" Received: from smtp.kernel.org (aws-us-west-2-korg-mail-1.web.codeaurora.org [10.30.226.201]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 5094B1870A8; Sun, 24 Mar 2024 22:40:51 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=10.30.226.201 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1711320051; cv=none; b=IpGe1RLGHtaodEa3oI1YZKNpqu94Ryq4TuaKxpTRkWmHkSpcwA5dMXxXh29LWR6yNwzjjE2AyVoVMAKdHGXB04OkuYCiyT/1zMzT4YCq18mY6qfG7b485UAMPzd1w5hF6boapec7nT+7DOK7PqSD3a2uVtQHNgtWylpM/IpspQQ= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1711320051; c=relaxed/simple; bh=r94iDyI3IDylZBFHddqhoES6VAbPF+0tOiw1jowT+zQ=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=Cohg0yCbvHgjEtAL2zDPzyUNhFWV+9bbGZ9hp0pwRMVw2M1h+1czH7EKNTVBrh/uoK9H4tXI6LSuaBbiMne8gNZSneMrmMBJiDqqrd3U7gkA49qIkR+MTyR0/1lAgoGDW4Z0hzJpqJtwrcpjyZTfwNtCfRjBThXnkGJ02qsBcVc= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=N49H5tpA; arc=none smtp.client-ip=10.30.226.201 Received: by smtp.kernel.org (Postfix) with ESMTPSA id 64CD8C43390; Sun, 24 Mar 2024 22:40:50 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1711320051; bh=r94iDyI3IDylZBFHddqhoES6VAbPF+0tOiw1jowT+zQ=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=N49H5tpAhuxXiOKPkfrSAZ+WZtEXTA64tDCH0gHjTYCaKjLDTDhoBMPvRIh2HpVLh VJkG+f5WgvZ3+Tj0qC7pG/8r9nyOLav5XI8lT24+t491IK2IVCqJMK8HSnatFC005W Fvw0i4F9WT7bOcFfdzz8SbTB6XcgVKX8b6nwmvdSflJVHJiOWIGolEQ0scJwy5s+hV b4byKr117l3mqcuKKwJdxl1Ctkv1Dk+oZPJYUFdL0lrKfA66dgfS9VTSPlDI4C9860 YX8+BqBSyw9uvtvaAIB1Wo0owAxkFmVwjGAcGpjfz5Ox1zx8YsNqTFFTR1jHDTD8QD 7e454nM2YRieQ== From: Sasha Levin To: linux-kernel@vger.kernel.org, stable@vger.kernel.org Cc: Harry Wentland , Arthur Grillo , Melissa Wen , Melissa Wen , Sasha Levin Subject: [PATCH 6.8 360/715] drm/vkms: Avoid reading beyond LUT array Date: Sun, 24 Mar 2024 18:28:59 -0400 Message-ID: <20240324223455.1342824-361-sashal@kernel.org> X-Mailer: git-send-email 2.43.0 In-Reply-To: <20240324223455.1342824-1-sashal@kernel.org> References: <20240324223455.1342824-1-sashal@kernel.org> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 X-stable: review X-Patchwork-Hint: Ignore Content-Transfer-Encoding: 8bit From: Harry Wentland [ Upstream commit 2fee84030d12d9fddfa874e4562d71761a129277 ] When the floor LUT index (drm_fixp2int(lut_index) is the last index of the array the ceil LUT index will point to an entry beyond the array. Make sure we guard against it and use the value of the floor LUT index. v3: - Drop bits from commit description that didn't contribute anything of value Fixes: db1f254f2cfa ("drm/vkms: Add support to 1D gamma LUT") Signed-off-by: Harry Wentland Cc: Arthur Grillo Reviewed-by: Arthur Grillo Reviewed-by: Melissa Wen Signed-off-by: Melissa Wen Link: https://patchwork.freedesktop.org/patch/msgid/20231108163647.106853-6-harry.wentland@amd.com Signed-off-by: Sasha Levin --- drivers/gpu/drm/vkms/vkms_composer.c | 14 ++++++++++---- 1 file changed, 10 insertions(+), 4 deletions(-) diff --git a/drivers/gpu/drm/vkms/vkms_composer.c b/drivers/gpu/drm/vkms/vkms_composer.c index 3c99fb8b54e2d..e7441b227b3ce 100644 --- a/drivers/gpu/drm/vkms/vkms_composer.c +++ b/drivers/gpu/drm/vkms/vkms_composer.c @@ -123,6 +123,8 @@ static u16 apply_lut_to_channel_value(const struct vkms_color_lut *lut, u16 chan enum lut_channel channel) { s64 lut_index = get_lut_index(lut, channel_value); + u16 *floor_lut_value, *ceil_lut_value; + u16 floor_channel_value, ceil_channel_value; /* * This checks if `struct drm_color_lut` has any gap added by the compiler @@ -130,11 +132,15 @@ static u16 apply_lut_to_channel_value(const struct vkms_color_lut *lut, u16 chan */ static_assert(sizeof(struct drm_color_lut) == sizeof(__u16) * 4); - u16 *floor_lut_value = (__u16 *)&lut->base[drm_fixp2int(lut_index)]; - u16 *ceil_lut_value = (__u16 *)&lut->base[drm_fixp2int_ceil(lut_index)]; + floor_lut_value = (__u16 *)&lut->base[drm_fixp2int(lut_index)]; + if (drm_fixp2int(lut_index) == (lut->lut_length - 1)) + /* We're at the end of the LUT array, use same value for ceil and floor */ + ceil_lut_value = floor_lut_value; + else + ceil_lut_value = (__u16 *)&lut->base[drm_fixp2int_ceil(lut_index)]; - u16 floor_channel_value = floor_lut_value[channel]; - u16 ceil_channel_value = ceil_lut_value[channel]; + floor_channel_value = floor_lut_value[channel]; + ceil_channel_value = ceil_lut_value[channel]; return lerp_u16(floor_channel_value, ceil_channel_value, lut_index & DRM_FIXED_DECIMAL_MASK); -- 2.43.0