Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from gabe.freedesktop.org (gabe.freedesktop.org [131.252.210.177]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.lore.kernel.org (Postfix) with ESMTPS id 763E7C433F5 for ; Thu, 5 May 2022 08:27:50 +0000 (UTC) Received: from gabe.freedesktop.org (localhost [127.0.0.1]) by gabe.freedesktop.org (Postfix) with ESMTP id A7FC910ED7A; Thu, 5 May 2022 08:27:49 +0000 (UTC) Received: from NAM11-CO1-obe.outbound.protection.outlook.com (mail-co1nam11on2072.outbound.protection.outlook.com [40.107.220.72]) by gabe.freedesktop.org (Postfix) with ESMTPS id D1FE410F15E for ; Thu, 5 May 2022 08:27:47 +0000 (UTC) ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=UMoIgM79GOTRafyJxpNhQWvtjSdQKQpKVPo5GQC49oX8pl98AslC1vP5OnhCwAq0kVvkX0K1HOAooyGR9obQ8hrMy3KItoXZmJ5vo2idfLdN5qX1IHlsJ5nxG//kH1LG74PynPdD5dNvUBJ/RRZGdCroAwuLSTY3uAXAQPzlejXYp6vR6JQ7lLlHa52/4Ju04kuG6Rfmmj5ZtB7C4wZ6t3lQWYc+wXvbQoE7wN+xAeUHJRWvRPZ0E3FowyzfFay09yShESFQ/3ldHtsIoc9eN9M77NF4YMaTYGuzLe1YkYg1VkRLgNXk1mL9K0zZbuygETjgX3f33Ccwn2BtKfMv2g== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=microsoft.com; s=arcselector9901; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-AntiSpam-MessageData-ChunkCount:X-MS-Exchange-AntiSpam-MessageData-0:X-MS-Exchange-AntiSpam-MessageData-1; bh=G02D3DeHiMd/N5MmuYJU+44VpRbdbzgvqodmTzx8mq4=; b=AydNjavk7aYCZlbSgS1IX1YK2A9iYGgtgqLJLGj5WM8bZSE+3MsvhRfAPVfjB1p7AC9l2yOsxiDFkVtOje7/8DNB8mrBkWsM3ttedIhA58u4Zn5WYP5mjorWvtCGDHtijRyIfhlpGY+U5ktTt8GEdzLOx5FOiYvs8PGFkBXmeCG/q3SENvzko4JfX8BMT0Fk5AgdE6sqwgo2KZOa3xXXoLUrqj/L/ULCRjt/ox1YqAu+gZIKiiMrmzFnmdOaF++S1V6Z28R+bTXX6ozHYObkpLHs78yAgYt07M4V4NVsOolgiZpaJ6rW9nkXmWJQcuoe/NZOY1eIdrX1kvNcRgwRBg== ARC-Authentication-Results: i=1; mx.microsoft.com 1; spf=pass smtp.mailfrom=amd.com; dmarc=pass action=none header.from=amd.com; dkim=pass header.d=amd.com; arc=none DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=amd.com; s=selector1; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck; bh=G02D3DeHiMd/N5MmuYJU+44VpRbdbzgvqodmTzx8mq4=; b=JZBMgRcrZQBZhR0lwDoBrTkOyNkWG7yem2WIdoNZ1gYP/i9SFsn4KNwAK8rTuKFY+eNv8LiE23e/ozjyjk/4pTP+Ufsz5dmeCAAYJmCROMSGz9OWxvMS9Ic79YcEf4rZtfB8JpBkNhByQFZdVgfglEHv+8ggwkM1GISOiD3SCuU= Authentication-Results: dkim=none (message not signed) header.d=none;dmarc=none action=none header.from=amd.com; Received: from BN8PR12MB3587.namprd12.prod.outlook.com (2603:10b6:408:43::13) by DS7PR12MB6120.namprd12.prod.outlook.com (2603:10b6:8:98::5) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.5206.24; Thu, 5 May 2022 08:27:44 +0000 Received: from BN8PR12MB3587.namprd12.prod.outlook.com ([fe80::fdba:2c6c:b9ab:38f]) by BN8PR12MB3587.namprd12.prod.outlook.com ([fe80::fdba:2c6c:b9ab:38f%4]) with mapi id 15.20.5206.025; Thu, 5 May 2022 08:27:44 +0000 Content-Type: multipart/alternative; boundary="------------o8QpyQH7KQX30W9oPadFYydu" Message-ID: <03423100-0266-1396-49ad-2b61d7331f6e@amd.com> Date: Thu, 5 May 2022 10:27:39 +0200 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:91.0) Gecko/20100101 Thunderbird/91.7.0 Subject: Re: [PATCH 1/2] dma-buf: Add an API for exporting sync files (v13) Content-Language: en-US To: Jason Ekstrand References: <20220504203404.1495485-1-jason@jlekstrand.net> <20220504203404.1495485-2-jason@jlekstrand.net> <7d478470-00fa-07a6-1479-dee80ced5b76@amd.com> From: =?UTF-8?Q?Christian_K=c3=b6nig?= In-Reply-To: X-ClientProxiedBy: AM5PR04CA0025.eurprd04.prod.outlook.com (2603:10a6:206:1::38) To BN8PR12MB3587.namprd12.prod.outlook.com (2603:10b6:408:43::13) MIME-Version: 1.0 X-MS-PublicTrafficType: Email X-MS-Office365-Filtering-Correlation-Id: cd9fc796-17c8-414d-c0bd-08da2e7120f6 X-MS-TrafficTypeDiagnostic: DS7PR12MB6120:EE_ X-Microsoft-Antispam-PRVS: X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: 4xJmhGV3xHnnwVzEI9E8+BaE5ozpNoCNxasRfR319ushrJm8JD+0lwv8QJnO9+pnKNSAjRddssalIaxgGvWadsKMFdKrTZCM1hv+MfvYbKQQHV+AL5sGOkevZVBm6Xey6rmjyhcRuRuiQWwVjmF9p4Bw/rl+sn/Glqy3Ga9c35jdg4GYbRoZgf8Fv2MtAoqUizM0XI64OiugHDWbKDV5vlQN+/vh6nf5EAhE7Uxv2Q2N1XVZ3hsiOLcfSWHUBiRylPP7kz1eZ/CrchBbqWhcK2txLnk1P8Yq/Zt0CwHmS9g+ikXHYAqnfzmOBvXLQMDdG973iLtYk0W5PFNxRKTp3te7V3CmA/Pht6S1nizA4T/1ErHMJaZJA4b/hK1JK4ZxSekye40T9tEPMqDzswW1hV7P9ECXHecc9RpNnvWUYV2NShzQGYacePPcw5QrB8tt75kGzfqWytBC1ieJRzxVsxuA9e5yIvS1JTTM8cAuCjaTHLssFgCrWX4md6WYCfWUZATlnZ45tT/zWjRf8LXVFQqlXIliytZiybQlNpkWL4reNxJyb3Jqa5MrFpRxvEakrWXNMkcpkIjiHGxlzKbTbY2/VlxagybHnF3JzIpmk90Nwbk/hkKU52zY2zYIZUtljsdioW7xY/Cbruz2z2j5Vj0HTp6hUoOkxJj05Ya+Z5R0aJHdlvgSlDKQyXhjyPxuTxomIsAS8Ovz9NP1nRdhRab7FDrZz1j88SVfHH538H/0/YsCmdj7OfPgB/BvASxG X-Forefront-Antispam-Report: CIP:255.255.255.255; CTRY:; LANG:en; SCL:1; SRV:; IPV:NLI; SFV:NSPM; H:BN8PR12MB3587.namprd12.prod.outlook.com; PTR:; CAT:NONE; SFS:(13230001)(4636009)(366004)(8676002)(66946007)(66556008)(66476007)(66574015)(83380400001)(31686004)(4326008)(6916009)(54906003)(2616005)(186003)(316002)(26005)(86362001)(2906002)(31696002)(6512007)(6506007)(53546011)(33964004)(6666004)(36756003)(5660300002)(38100700002)(8936002)(6486002)(508600001)(45980500001)(43740500002); DIR:OUT; SFP:1101; X-MS-Exchange-AntiSpam-MessageData-ChunkCount: 1 X-MS-Exchange-AntiSpam-MessageData-0: =?utf-8?B?ZVoxWTI4Z2dwS0JIbzJVOVN6SFJIb0xYWTVuL0htMzRIcnVKM2dMeVA2Z3Mr?= =?utf-8?B?QWRpaERvSi9hNGN4K0hhMk9xMW0wYnY2TVQvTStYSi9PbE92eHpsalhxcnpW?= =?utf-8?B?UUk1bUpuUzhBYVUvVEg5dTdjRWdRdDZpM2VDMGJSSS9RSFdQaTIyYnhhN0Z4?= =?utf-8?B?NHZCejBVc29oK0lVM29qenArREpxREg4L3FNVW9mb0tp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Eh2WmVUYlQza2ZNdnlBZHNGMksxVkJ6ZG9wbE1YaFR0UGdKblFwL3A5OEl2?= =?utf-8?B?L0VjdFJWbzFIU1UvOXhteFJjRlpZZE1Na1p2N0dLM0RFdG1YQzdnZFFkejlR?= =?utf-8?B?REx3VUdhQWt1aEhQdytFQkdEWDBPWlhGQnF2cmM2Wi9kN29PODhpbVVhV2pC?= =?utf-8?B?dDhzYnh6VmVoSTE2QTZXWEtYV2JGTUQyUk9GN1dDVHVOQ3hlZGJkMjg5Y2R0?= =?utf-8?B?TWxmT3pyT1A3eFFURHpTaW0wRG1jbWhYYjZ2bjRGaFpVa2svY1hmcm9nby9l?= =?utf-8?B?aGowSndDTzEyVFR5ekcwcXYxK04rbERNa0hTd0ZVRFYrSUNZY1gxUT09?= X-OriginatorOrg: amd.com X-MS-Exchange-CrossTenant-Network-Message-Id: cd9fc796-17c8-414d-c0bd-08da2e7120f6 X-MS-Exchange-CrossTenant-AuthSource: BN8PR12MB3587.namprd12.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 05 May 2022 08:27:44.7601 (UTC) X-MS-Exchange-CrossTenant-FromEntityHeader: Hosted X-MS-Exchange-CrossTenant-Id: 3dd8961f-e488-4e60-8e11-a82d994e183d X-MS-Exchange-CrossTenant-MailboxType: HOSTED X-MS-Exchange-CrossTenant-UserPrincipalName: zCnmZzUvyhNACDolNeB5kpWctmOTREZook9ceKnmJJw4FUhEreqglfD9YD2E8o7s X-MS-Exchange-Transport-CrossTenantHeadersStamped: DS7PR12MB6120 X-BeenThere: dri-devel@lists.freedesktop.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: Direct Rendering Infrastructure - Development List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Sumit Semwal , Maling list - DRI developers , Daniel Vetter Errors-To: dri-devel-bounces@lists.freedesktop.org Sender: "dri-devel" --------------o8QpyQH7KQX30W9oPadFYydu Content-Type: text/plain; charset=UTF-8; format=flowed Content-Transfer-Encoding: 8bit Am 05.05.22 um 10:10 schrieb Jason Ekstrand: > On Thu, May 5, 2022 at 1:25 AM Christian König > wrote: > > [SNIP] > > +     fd_install(fd, sync_file->file); > > + > > +     arg.fd = fd; > > +     if (copy_to_user(user_data, &arg, sizeof(arg))) > > +             return -EFAULT; > > I know we had that discussion before, but I'm not 100% any more > what the > outcome was. > > The problem here is that when the copy_to_user fails we have a file > descriptor which is valid, but userspace doesn't know anything > about it. > > I only see a few possibilities here: > 1. Keep it like this and just assume that a process which you > can't copy > the fd to is also dying (a bit to much assumption for my taste). > > 2. Close the file descriptor when this happens (not ideal either). > > 3. Instead of returning the fd in the parameter structure return > it as > IOCTL result. > > Number 3 is what drm_prime_handle_to_fd_ioctl() is doing as well and > IIRC we said that this is probably the best option. > > > I don't have a strong preference here, so I'll go with whatever in the > end but let me at least explain my reasoning.  First, this was based > on the FD import/export in syncobj which stuffs the FD in the args > struct.  If `copy_to_user` is a problem here, it's a problem there as > well.  Second, the only way `copy_to_user` can fail is if the client > gives us a read-only page or somehow manages to race removing the page > from their address space (via unmap(), for instance) with this ioctl.  > Both of those seem like pretty serious client errors to me.  That, or > the client is in the process of dying, in which case we really don't care. Yeah, I know about that copy_to_user() issue in the syncobj and also some driver specific handling. That's why we discussed this before and IIRC somebody indeed ran into an issue with -EFAULT and that was the reason all this bubbled up. I don't have a strong preference either, but I think we should try to learn from previous mistakes and design new interfaces based on such experience. Christian. > > --Jason > --------------o8QpyQH7KQX30W9oPadFYydu Content-Type: text/html; charset=UTF-8 Content-Transfer-Encoding: 8bit Am 05.05.22 um 10:10 schrieb Jason Ekstrand:
On Thu, May 5, 2022 at 1:25 AM Christian König <christian.koenig@amd.com> wrote:
[SNIP]
> +     fd_install(fd, sync_file->file);
> +
> +     arg.fd = fd;
> +     if (copy_to_user(user_data, &arg, sizeof(arg)))
> +             return -EFAULT;

I know we had that discussion before, but I'm not 100% any more what the
outcome was.

The problem here is that when the copy_to_user fails we have a file
descriptor which is valid, but userspace doesn't know anything about it.

I only see a few possibilities here:
1. Keep it like this and just assume that a process which you can't copy
the fd to is also dying (a bit to much assumption for my taste).

2. Close the file descriptor when this happens (not ideal either).

3. Instead of returning the fd in the parameter structure return it as
IOCTL result.

Number 3 is what drm_prime_handle_to_fd_ioctl() is doing as well and
IIRC we said that this is probably the best option.

I don't have a strong preference here, so I'll go with whatever in the end but let me at least explain my reasoning.  First, this was based on the FD import/export in syncobj which stuffs the FD in the args struct.  If `copy_to_user` is a problem here, it's a problem there as well.  Second, the only way `copy_to_user` can fail is if the client gives us a read-only page or somehow manages to race removing the page from their address space (via unmap(), for instance) with this ioctl.  Both of those seem like pretty serious client errors to me.  That, or the client is in the process of dying, in which case we really don't care.

Yeah, I know about that copy_to_user() issue in the syncobj and also some driver specific handling.

That's why we discussed this before and IIRC somebody indeed ran into an issue with -EFAULT and that was the reason all this bubbled up.

I don't have a strong preference either, but I think we should try to learn from previous mistakes and design new interfaces based on such experience.

Christian.


--Jason


--------------o8QpyQH7KQX30W9oPadFYydu--