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=-4.1 required=3.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,MAILING_LIST_MULTI,SPF_HELO_NONE, SPF_PASS,URIBL_BLOCKED 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 F318BC2D0A3 for ; Sat, 24 Oct 2020 19:21:32 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id A90E920709 for ; Sat, 24 Oct 2020 19:21:32 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1603567292; bh=JVOtaKdH1EtSuGmR6kfsv5i3Q8TYXIkcMRHcLeY/C9Q=; h=References:In-Reply-To:From:Date:Subject:To:Cc:List-ID:From; b=yjegar7GfZ07OWsEJjIEjeXYHKxXtND0Opva255Hudua/DJfx8Nzw3xB/3+V0gEvO QHTFAlLWdkEZVneaMDtJDl4OO+IvgQT3pHrwIH5LyXMek1+0YVAJ+Z4Neol+Lq5NF3 uHpFZjBjQ9Gwzo/i9K4apfdjEhKB5PioPoAYvW6M= Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1763829AbgJXTV3 (ORCPT ); Sat, 24 Oct 2020 15:21:29 -0400 Received: from mail.kernel.org ([198.145.29.99]:45258 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1763681AbgJXTV2 (ORCPT ); Sat, 24 Oct 2020 15:21:28 -0400 Received: from mail-qt1-f182.google.com (mail-qt1-f182.google.com [209.85.160.182]) (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 E817720709 for ; Sat, 24 Oct 2020 19:21:27 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1603567288; bh=JVOtaKdH1EtSuGmR6kfsv5i3Q8TYXIkcMRHcLeY/C9Q=; h=References:In-Reply-To:From:Date:Subject:To:Cc:From; b=plKXKA4qYOw3F7cYinTY5CFGZTiQwWdDcLvgpdGKudMRtUcqhuRuQq2MMZ6A8mKdF /Yiuo3Y/9X+DW4AR3/FIsq+e+D6LWMdA1h6GY63GqrZtvESFNsxEiGiV4Bo8FaeG55 fYLZBFtS88hWI/Ee8ihNtCo/Ukh728oSIlqCrAoo= Received: by mail-qt1-f182.google.com with SMTP id e6so3950179qtw.10 for ; Sat, 24 Oct 2020 12:21:27 -0700 (PDT) X-Gm-Message-State: AOAM53214ho38z/thPseQwzQsSlJ16Sqn+hzovoyoY/vNcxbcxHHUpD3 AqPjuYG+5L9Qd3ROqUgwSYxz7AWZSk0lIyektG4= X-Google-Smtp-Source: ABdhPJyhyn2fnoh3jaY/Yy4Mn1Vh46i0l5GbzMkoQSTPMlbc9rc08yulVqjBQDaaAIOTXLpsoVUQXi+x2GqW93oz3Sw= X-Received: by 2002:ac8:64a:: with SMTP id e10mr8303474qth.142.1603567287128; Sat, 24 Oct 2020 12:21:27 -0700 (PDT) MIME-Version: 1.0 References: <20201008182713.2764-1-harshalchau04@gmail.com> <20201009045734.GA112189@kroah.com> <0eb6f48d05624c8abaf00ae1bd4d88a9@AcuMS.aculab.com> In-Reply-To: From: Arnd Bergmann Date: Sat, 24 Oct 2020 21:21:11 +0200 X-Gmail-Original-Message-ID: Message-ID: Subject: Re: [PATCH] char: ppdev: check if ioctl argument is present and valid To: harshal chaudhari Cc: David Laight , Greg KH , Sudip Mukherjee , linux-kernel Content-Type: text/plain; charset="UTF-8" Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Sat, Oct 24, 2020 at 5:54 PM harshal chaudhari wrote: > On Tue, Oct 13, 2020 at 4:42 PM David Laight wrote: > So I am a little bit confused about this check whether it's required or not > Please could you point me in the right direction? > > In any case, thanks for your help ... > > Here is a driver source located in: linux/drivers/misc/xilinx_sdfec.c > > static long xsdfec_dev_ioctl(struct file *fptr, unsigned int cmd, > unsigned long data) > { > struct xsdfec_dev *xsdfec; > void __user *arg = NULL; > int rval = -EINVAL; > > if (_IOC_TYPE(cmd) != XSDFEC_MAGIC) > return -ENOTTY; > > /* check if ioctl argument is present and valid */ > if (_IOC_DIR(cmd) != _IOC_NONE) > { > arg = (void __user *)data; > if (!arg) > return rval; > } > All of this can be removed, and replaced with unconditional void __user *arg = (void __user *)data; int rval; with an "rval = -ENOTTY" added in the 'default' case. This will make it behave more like other drivers, returning -ENOTTY for any unknown ioctl command, and returning -EFAULT for all invalid pointers, including NULL. xsdfec_dev_compat_ioctl() can removed as well, with the file operations changed to an unconditional (removing the #ifdef) .compat_ioctl = compat_ptr_ioctl(), This will not affect behavior, it's just another simplification. Arnd