Return-Path: Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1752233AbdHPOYW (ORCPT ); Wed, 16 Aug 2017 10:24:22 -0400 Received: from mail-db5eur01on0075.outbound.protection.outlook.com ([104.47.2.75]:3840 "EHLO EUR01-DB5-obe.outbound.protection.outlook.com" rhost-flags-OK-OK-OK-FAIL) by vger.kernel.org with ESMTP id S1751578AbdHPOYU (ORCPT ); Wed, 16 Aug 2017 10:24:20 -0400 From: Oleksandr Shamray To: Arnd Bergmann CC: gregkh , Linux Kernel Mailing List , Linux ARM , "devicetree@vger.kernel.org" , OpenBMC Maillist , Joel Stanley , =?utf-8?B?SmnFmcOtIFDDrXJrbw==?= , Tobias Klauser , "linux-serial@vger.kernel.org" , "mec@shout.net" , "vadimp@maellanox.com" , system-sw-low-level , Rob Herring , "openocd-devel-owner@lists.sourceforge.net" , Jiri Pirko Subject: RE: [patch v3 1/3] drivers: jtag: Add JTAG core driver Thread-Topic: [patch v3 1/3] drivers: jtag: Add JTAG core driver Thread-Index: AQHTFa1XL6LNiNTEHUiQ8rcLbWol1aKFRGsAgAHC42A= Date: Wed, 16 Aug 2017 14:24:16 +0000 Message-ID: References: <1502791207-26951-1-git-send-email-oleksandrs@mellanox.com> <1502791207-26951-2-git-send-email-oleksandrs@mellanox.com> In-Reply-To: Accept-Language: en-US, uk-UA Content-Language: en-US X-MS-Has-Attach: X-MS-TNEF-Correlator: authentication-results: spf=none (sender IP is ) smtp.mailfrom=oleksandrs@mellanox.com; x-originating-ip: [80.90.224.13] x-ms-publictraffictype: Email x-microsoft-exchange-diagnostics: 1;VI1PR05MB1757;6:b5hCOklnRmiA4nfueAtPdz/VJFdJW0PCPIxPy4aYIMMh8t9q+QYFRjHn5FbxdeE+V4XPse+vZJMObNS69cs5aPJAtGq57EHhqsEYhNl+8B4qRUbMJXpzYnayh4cnDywm8ECchEVu+KO78Eh8S94K0MUwMyhcMSQ4Tq8KbTyc2b/X5Bkq7C6SZts2gFb0jN0ZaZNzmWkw3KZp1b0tIUsN4FOWbAVKtNEvq8i20XD6wxjCRhQq0KJGcxdhVo3mOYeK05GVivFUWh3P2qRodf7/MyrQbhb823jKDX+iUtcp7pvKUC4OZsRBCfBFx20+atRoJAVSViYSWe5uVDbsvmL2XQ==;5:wZ8Zzn01hXFm+s+L33ho8kD1gHsGcMXaMSylF8ceIy9L91GKz31DqN38U5YdkZkYRkWf9BCGMY1NtxM0jrCpkqsa4TQrvty8crdQ5E8Z9+YnrPlNEh/LFhPoaL4+qYGYtoq0A2YlDqnElH7RUAr+yQ==;24:nDXKpgi/yA2SwVQkExT4vVNIDE2xrrY2YYH2tPR2LqQszCqpPpWtISqOC89riqWoDPtAFnDvtNkHM/NrCDAtvfDcROHQ6eiNRn+nJbd+SwE=;7:CKIBIdlmrQZX+il3ui7oW1TRWEeR5nwxRnrE4mmrSeGbDOSrjLofHMh9kLR+L/tjstQXZD4p4sIQGgcqNuySPlA8jR2rJ7O1zru6PfxcuQ20NoaFHkAS8Uf7SNC/XlWcScAz3pLnx6d3h5ucuvFuChIPPP8J43QuiZrqoTyIH7kwrWFn7e5sKEyGl2p1s8jFXpuW3D5uOtafk8P2HBFYEcXoAwvqnZD9jJFaSgUfDW8= x-ms-exchange-antispam-srfa-diagnostics: SSOS; x-ms-office365-filtering-correlation-id: 79326eb7-83b2-4a91-8221-08d4e4b279be x-ms-office365-filtering-ht: Tenant x-microsoft-antispam: UriScan:;BCL:0;PCL:0;RULEID:(300000500095)(300135000095)(300000501095)(300135300095)(22001)(300000502095)(300135100095)(2017030254152)(48565401081)(300000503095)(300135400095)(2017052603031)(201703131423075)(201703031133081)(201702281549075)(300000504095)(300135200095)(300000505095)(300135600095)(300000506095)(300135500095);SRVR:VI1PR05MB1757; x-ms-traffictypediagnostic: VI1PR05MB1757: x-exchange-antispam-report-test: UriScan:(143289334528602)(9452136761055)(65623756079841)(258649278758335)(42262312472803); x-microsoft-antispam-prvs: x-exchange-antispam-report-cfa-test: BCL:0;PCL:0;RULEID:(100000700101)(100105000095)(100000701101)(100105300095)(100000702101)(100105100095)(6040450)(601004)(2401047)(8121501046)(5005006)(93006095)(93001095)(10201501046)(100000703101)(100105400095)(3002001)(6055026)(6041248)(20161123558100)(20161123560025)(201703131423075)(201702281528075)(201703061421075)(201703061406153)(20161123564025)(20161123555025)(20161123562025)(6072148)(201708071742011)(100000704101)(100105200095)(100000705101)(100105500095);SRVR:VI1PR05MB1757;BCL:0;PCL:0;RULEID:(100000800101)(100110000095)(100000801101)(100110300095)(100000802101)(100110100095)(100000803101)(100110400095)(100000804101)(100110200095)(100000805101)(100110500095);SRVR:VI1PR05MB1757; x-forefront-prvs: 0401647B7F x-forefront-antispam-report: SFV:NSPM;SFS:(10009020)(6009001)(39860400002)(189002)(13464003)(377454003)(199003)(24454002)(81166006)(2906002)(81156014)(74316002)(8676002)(101416001)(5250100002)(189998001)(50986999)(3846002)(102836003)(3280700002)(8936002)(6116002)(68736007)(33656002)(3660700001)(7416002)(54356999)(76176999)(107886003)(110136004)(53936002)(6246003)(6436002)(7696004)(5660300001)(6506006)(99286003)(55016002)(9686003)(54906002)(105586002)(106356001)(305945005)(229853002)(2950100002)(14454004)(2900100001)(6916009)(7736002)(25786009)(97736004)(4326008)(53546010)(478600001)(66066001)(86362001);DIR:OUT;SFP:1101;SCL:1;SRVR:VI1PR05MB1757;H:AM4PR0501MB2194.eurprd05.prod.outlook.com;FPR:;SPF:None;PTR:InfoNoRecords;MX:1;A:1;LANG:en; spamdiagnosticoutput: 1:99 spamdiagnosticmetadata: NSPM Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 X-OriginatorOrg: Mellanox.com X-MS-Exchange-CrossTenant-originalarrivaltime: 16 Aug 2017 14:24:16.2828 (UTC) X-MS-Exchange-CrossTenant-fromentityheader: Hosted X-MS-Exchange-CrossTenant-id: a652971c-7d2e-4d9b-a6a4-d149256f461b X-MS-Exchange-Transport-CrossTenantHeadersStamped: VI1PR05MB1757 Sender: linux-kernel-owner@vger.kernel.org List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Content-Transfer-Encoding: 8bit X-MIME-Autoconverted: from base64 to 8bit by nfs id v7GEOSiT017495 Content-Length: 3815 Lines: 102 > -----Original Message----- > From: arndbergmann@gmail.com [mailto:arndbergmann@gmail.com] On > Behalf Of Arnd Bergmann > Sent: Tuesday, August 15, 2017 2:16 PM > To: Oleksandr Shamray > Cc: gregkh ; Linux Kernel Mailing List kernel@vger.kernel.org>; Linux ARM ; > devicetree@vger.kernel.org; OpenBMC Maillist ; > Joel Stanley ; Jiří Pírko ; Tobias Klauser > ; linux-serial@vger.kernel.org; mec@shout.net; > vadimp@maellanox.com; system-sw-low-level level@mellanox.com>; Rob Herring ; openocd-devel- > owner@lists.sourceforge.net; Jiri Pirko > Subject: Re: [patch v3 1/3] drivers: jtag: Add JTAG core driver > > On Tue, Aug 15, 2017 at 12:00 PM, Oleksandr Shamray > wrote: > > > + case JTAG_IOCXFER: > > + if (copy_from_user(&xfer, varg, sizeof(struct jtag_xfer))) > > + return -EFAULT; > > + > > + if (xfer.length >= JTAG_MAX_XFER_DATA_LEN) > > + return -EFAULT; > > + > > + user_tdio_data = xfer.tdio; > > + xfer.tdio = jtag_copy_from_user((void __user *)user_tdio_data, > > + xfer.length); > > + if (!xfer.tdio) > > + return -ENOMEM; > > This is not safe for 32-bit processes on 64-bit kernels, since the structure layout > differs for the pointer member. It's better to always use either rework the > structure to avoid the pointer, or to use a > __u64 member to store it, and then use u64_to_user_ptr() to convert it in the > kernel. Thanks, I think using __u64 instead of pointer will be a good solution. > > > + case JTAG_GIOCSTATUS: > > + if (jtag->ops->status_get) > > + err = jtag->ops->status_get(jtag, > > + (enum jtag_endstate > > + *)&value); > > This pointer cast is also not safe, as an enum might have a different size than > the 'value' variable that is not an enum. I think you need to change the > argument type for the callback, or maybe use another intermediate. > > > +static int jtag_open(struct inode *inode, struct file *file) { > > + struct jtag *jtag = container_of(inode->i_cdev, struct jtag, > > +cdev); > > + > > + spin_lock(&jtag->lock); > > + > > + if (jtag->is_open) { > > + dev_info(NULL, "jtag already opened\n"); > > + spin_unlock(&jtag->lock); > > + return -EBUSY; > > + } > > + > > + jtag->is_open = true; > > + file->private_data = jtag; > > + spin_unlock(&jtag->lock); > > + return 0; > > +} > > Does the 'is_open' flag protect you from something that doesn't also happen > after a 'dup()' call on the file descriptor? is_open flag protects from the opening file more than one time. > > > + * @mode: access mode > > + * @type: transfer type > > + * @direction: xfer direction > > + * @length: xfer bits len > > + * @tdio : xfer data array > > + * @endir: xfer end state > > + * > > + * Structure represents interface to Aspeed JTAG device for jtag sdr > > +xfer > > + * execution. > > + */ > > +struct jtag_xfer { > > + __u8 mode; > > + __u8 type; > > + __u8 direction; > > + __u32 length; > > + __u8 *tdio; > > + __u8 endstate; > > +}; > > As mentioned above, the pointer in here makes it incompatible. Also, you > should reorder the members to avoid the implied padding. > Moving the 'endstate' before 'length' is sufficient. > Thank. I will do it. > Arnd