From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-6.0 required=3.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,HEADER_FROM_DIFFERENT_DOMAINS, MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS autolearn=no autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id E2D23C433C1 for ; Wed, 24 Mar 2021 02:02:16 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id BB6A9619E9 for ; Wed, 24 Mar 2021 02:02:16 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S234684AbhCXCBn (ORCPT ); Tue, 23 Mar 2021 22:01:43 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:57440 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231544AbhCXCBS (ORCPT ); Tue, 23 Mar 2021 22:01:18 -0400 Received: from mail-pf1-x433.google.com (mail-pf1-x433.google.com [IPv6:2607:f8b0:4864:20::433]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 4E083C061763 for ; Tue, 23 Mar 2021 19:01:18 -0700 (PDT) Received: by mail-pf1-x433.google.com with SMTP id x26so16201586pfn.0 for ; Tue, 23 Mar 2021 19:01:18 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=chromium.org; s=google; h=date:from:to:cc:subject:message-id:references:mime-version :content-disposition:in-reply-to; bh=Gko5DwdDrrjyuudztCK85u5fA9SOsiUHVh5WfDpFt8E=; b=QlJxkIRDjzXTY962t2mtJA7UVqpJYbvcjCSKEMSo/Q5mM60eQoKJHEXyROJMl7N+ES kEXL+d876OKQFmHIFECPqG2PQLhuC5OYGzBJvk5FNiIa6/eJBbCg1szxejz4xHCjoKaJ BI1VsVWLDZ/5tGIYFIMpjkewa0LZPtGwL3ZTA= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:date:from:to:cc:subject:message-id:references :mime-version:content-disposition:in-reply-to; bh=Gko5DwdDrrjyuudztCK85u5fA9SOsiUHVh5WfDpFt8E=; b=ZclJXwiObdZk+FRraaVBY99DvT+Xw/6X+RowtnjMRfiqoV1eOVCw++qxcSGKGdlIVs D4oBrJ84xtYkfTVJ9u/rdZF8bF9UbF/hZS86zyS/RZEf+E+cx4fQlKN/JRHDrwrk9cAm LAPb8bJcNuPfWMR5re/pxdI33sZEcmkSLAT/8CcOtZKa3mDDOx3gg3v8xZKmohVSAeaE GzBRW/8FcfCynN+AjsiBxCDKwtcDV+vwmvqHIAx52Lqzo1i2iJwRdXydsPHWhVwNM8Uj hW5k4oD6ENcZWsDGnIv+WVGXNT8xE8zGa1uI0oMZHi5o4t0195f+01zLiQP5jkL30sq7 cMVA== X-Gm-Message-State: AOAM532xlpPR06YqXGnVf6QVJ+bpRyh9fM9mf9QhYSIH3ZzGr/i1Gs8E 0pD/muSEPj0IdBi/7uWAqBzJgA== X-Google-Smtp-Source: ABdhPJxjsLNxIWN+kP3AAa5XMz8NmKTnf5Z8dD1Tcao1d3voJoNIhlTReYr8pe8xY1AcqQYOBEuOZA== X-Received: by 2002:a63:f546:: with SMTP id e6mr954277pgk.299.1616551277775; Tue, 23 Mar 2021 19:01:17 -0700 (PDT) Received: from google.com ([2409:10:2e40:5100:bcf2:e05a:a993:9494]) by smtp.gmail.com with ESMTPSA id d2sm389013pjx.42.2021.03.23.19.01.15 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 23 Mar 2021 19:01:17 -0700 (PDT) Date: Wed, 24 Mar 2021 11:01:12 +0900 From: Sergey Senozhatsky To: Ricardo Ribalda Cc: Sergey Senozhatsky , Laurent Pinchart , Tomasz Figa , Mauro Carvalho Chehab , Hans Verkuil , Linux Media Mailing List , Linux Kernel Mailing List Subject: Re: [PATCHv3 5/6] media: uvcvideo: add UVC 1.5 ROI control Message-ID: References: <20210319055342.127308-1-senozhatsky@chromium.org> <20210319055342.127308-6-senozhatsky@chromium.org> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On (21/03/23 17:16), Ricardo Ribalda wrote: [..] > > +static bool validate_roi_bounds(struct uvc_streaming *stream, > > + struct v4l2_selection *sel) > > +{ > > + if (sel->r.left > USHRT_MAX || > > + sel->r.top > USHRT_MAX || > > + (sel->r.width + sel->r.left) > USHRT_MAX || > > + (sel->r.height + sel->r.top) > USHRT_MAX || > > + !sel->r.width || !sel->r.height) > > + return false; > > + > > + if (sel->flags > V4L2_SEL_FLAG_ROI_AUTO_HIGHER_QUALITY) > > + return false; > > Is it not allowed V4L2_SEL_FLAG_ROI_AUTO_IRIS | > V4L2_SEL_FLAG_ROI_AUTO_HIGHER_QUALITY ? Good question. I don't know. Depends on what HIGHER_QUALITY can stand for (UVC doesn't specify). But overall it seems like features there are mutually exclusive. E.g. AUTO_FACE_DETECT and AUTO_DETECT_AND_TRACK. I think it'll be better to replace this with if (sel->flags > USHRT_MAX) return false; so that we don't let overflow happen and accidentally enable/disable some of the features. > > + > > + return true; > > +} > > + > > +static int uvc_ioctl_s_roi(struct file *file, void *fh, > > + struct v4l2_selection *sel) > > +{ > > + struct uvc_fh *handle = fh; > > + struct uvc_streaming *stream = handle->stream; > > + struct uvc_roi_rect *roi; > > + int ret; > > + > > + if (!validate_roi_bounds(stream, sel)) > > + return -E2BIG; > > Not sure if this is the correct approach or if we should convert the > value to the closest valid... Well, at this point we know that ROI rectangle dimensions are out of sane value range. I'd rather tell user-space about integer overflow. Looking for the closest ROI rectangle that suffice can be rather tricky. It may sounds like we can just use BOUNDARIES_MAX, but this is what Firmware D returns for GET_MAX ioctl(V4L2_SEL_TGT_ROI_BOUNDS_MAX) 0, 0, 65535, 65535 -ss