From patchwork Fri Feb 2 10:38:27 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Hans Verkuil X-Patchwork-Id: 13542717 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 8AD6A1426A for ; Fri, 2 Feb 2024 10:38:30 +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=1706870310; cv=none; b=d6oAPSWHtz+HtfVD9lgROrepKuU6evzfS/udr+M12+B4j+qDlVESSqkKEJKIFlT3gjiNiB0MjnVjjsl8B/W7eiPCltoysrolJEe0S/MgAWIAEeW2MW3P2Jv7OVqmT06qSpuZxXsRUm2WOpuOeqq8ruDKyYZYafPw/AindGKOD1k= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1706870310; c=relaxed/simple; bh=cr9C/7sGlW+k54565U8oITZEQkl54F44JFEPfQt1Whc=; h=Message-ID:Date:MIME-Version:To:Cc:From:Subject:Content-Type; b=UIx9vDI0G3rp/Sbe9aaisUPzYftr02TyvSHkyS2Amh9pYEWzik1+q5iOn4Cri2c5C/i73p0UeY3YYqU0IXt68PTgOZjOR2s/hrrNX4RVrjRxe51LEPLo40002L/xYj8aRbaAh+mS3VoipbipNB9E2kG+uK35CXgbM0HzIyLrt5s= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; arc=none smtp.client-ip=10.30.226.201 Received: by smtp.kernel.org (Postfix) with ESMTPSA id 8DC86C433C7; Fri, 2 Feb 2024 10:38:29 +0000 (UTC) Message-ID: <6af38faa-a10c-40e2-873b-c4288a68c5aa@xs4all.nl> Date: Fri, 2 Feb 2024 11:38:27 +0100 Precedence: bulk X-Mailing-List: linux-media@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 User-Agent: Mozilla Thunderbird Content-Language: en-US, nl To: Linux Media Mailing List Cc: Dorcas Litunya From: Hans Verkuil Subject: [PATCH] media: v4l2-ctrls-core.c: check min/max for menu controls Menu controls require that the min-max range is inside 0-63. Negative values obviously make no sense for menu controls, and the maximum value is currently limited by the number of bits of the menu_skip_mask value. If we ever need to add support for larger menus, then more work is needed. For now just check that everything is within range. Signed-off-by: Hans Verkuil Reviewed-by: Nicolas Dufresne diff --git a/drivers/media/v4l2-core/v4l2-ctrls-core.c b/drivers/media/v4l2-core/v4l2-ctrls-core.c index a662fb60f73f..89d1e3e78563 100644 --- a/drivers/media/v4l2-core/v4l2-ctrls-core.c +++ b/drivers/media/v4l2-core/v4l2-ctrls-core.c @@ -1504,7 +1504,8 @@ int check_range(enum v4l2_ctrl_type type, return 0; case V4L2_CTRL_TYPE_MENU: case V4L2_CTRL_TYPE_INTEGER_MENU: - if (min > max || def < min || def > max) + if (min > max || def < min || def > max || + min < 0 || max >= BITS_PER_LONG_LONG) return -ERANGE; /* Note: step == menu_skip_mask for menu controls. So here we check if the default value is masked out. */