Received: by 2002:a05:6a10:2785:0:0:0:0 with SMTP id ia5csp214347pxb; Fri, 15 Jan 2021 01:04:15 -0800 (PST) X-Google-Smtp-Source: ABdhPJwV+EfeEQWPsgI22sRGR3tt1o8xOwQaQ0RbUQqnnvLIq4EzC2Q6pabUV5iSLIr3fmwXNAfn X-Received: by 2002:a50:e78b:: with SMTP id b11mr8688496edn.165.1610701454952; Fri, 15 Jan 2021 01:04:14 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1610701454; cv=none; d=google.com; s=arc-20160816; b=csojN5dYq19SqdLUvwvautkzYO/VC5d8JfErAneaQRoVSKKHtEE+8G4uzh3zJfDRsL l9Suj03DluZQj5cwrq2LGwyRsuYxhChJFjzbRAXNzrmP5+aZuvjum55DBr+P9/BCNkAF 5qAQlDkpVTkzoqO86ftP1V3IS+IOgABSjMMXhLYHqa6v54bxAawtpDUWZP8lRqdCgEAP neBA/Sv5tzHqm8L319fKcV4CbtrIhmRhFtyiPeTs9ZB5GoXGhVO4IOsfh4i7OlSeJMJ7 PH2vrl7mA1TvziAdn+Ab+BNmTcQJxPgoGJx7/fO/4rMfXVX87suCYx5NuzzSyYXQ/69P UcSA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:cc:to:subject:message-id:date:from:in-reply-to :references:mime-version:dkim-signature; bh=DaUuUl93daAF4tLjIvSm/KzBt/MtNEdOYHea+vMpyh0=; b=fGKkM0P9wSm4dgLZm2dFJeMTAqMl4oZ2TIey1+R95PPFwWR8l0335CvokEmrmXlOQA X4HM0RAUDTc3ybYNipRbaSrigfW2g6OxYVB+Hfu8xvuzqHlREmDkcNdVw8r/6xAQW441 Yrw+8QYVLZX9lIFs4WC1p+nQB2DgxUFH5UqC5IbGLsyfFhAXF36r+BNrPp3R453yygk0 c7EaXvOI71h6E0s52EYsu/wcS0DDwseNweLLQeNmY3Mm++bYQTPE6s9pLC2oZ6PsqRTf j81VF8rCvLxftwq7GgoUqsBRofGOP4QWbrlCTzrC26aNoAtSb1F3GI2OvYTHAl1IzUns TlDg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=k20201202 header.b=slpAOPtS; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id qt23si123977ejb.373.2021.01.15.01.03.51; Fri, 15 Jan 2021 01:04:14 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) client-ip=23.128.96.18; Authentication-Results: mx.google.com; dkim=pass header.i=@kernel.org header.s=k20201202 header.b=slpAOPtS; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1728941AbhAOJBs (ORCPT + 99 others); Fri, 15 Jan 2021 04:01:48 -0500 Received: from mail.kernel.org ([198.145.29.99]:33922 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726652AbhAOJBq (ORCPT ); Fri, 15 Jan 2021 04:01:46 -0500 Received: by mail.kernel.org (Postfix) with ESMTPSA id 3CB7E235DD; Fri, 15 Jan 2021 09:01:05 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1610701265; bh=/A9+Zdj6TeXK+0F6O2x/uxJykl7caLwG9Gsbb99EJRA=; h=References:In-Reply-To:From:Date:Subject:To:Cc:From; b=slpAOPtS7YCDBAgE41dzMlkAmNSstSYU6QgVZardVdQRETcPFnBhz638B9MfCX9JI MdQA8a9ZaP0356QuNQNixM9RlXTSng99DVtQx+anK4/dziSRPwcw8N45+yhLuETEM9 886mtj2yOSvuCZ9xdjVHxcnQL5P9rDdeFWP03g3+i3PqQX3bDDgY2/86xrjgWioN6n Iclf3LZ1NDz6EZ+1/OORQvNiPySLtX+xZFhAN4y3Z/KRIyNLJYCmpYExV2avR6gWHH jU8FsUvGN1l0NzE6s3W1dtuSTJHb0/EvTJylkIFXsvvl42gP1yJyLgCzR/dqBxgBcV ASNt2zWE3woQQ== Received: by mail-wr1-f44.google.com with SMTP id 6so1143432wri.3; Fri, 15 Jan 2021 01:01:05 -0800 (PST) X-Gm-Message-State: AOAM531HTNGUdL4+vR/BWQoyILMjAi8NzZ6vBC/e+L+BNspeZMSV360k qLrATk46YYYL+jUu4zetFO7JsZvA5Qy4HbzsV7c= X-Received: by 2002:adf:fe05:: with SMTP id n5mr12248933wrr.9.1610701263721; Fri, 15 Jan 2021 01:01:03 -0800 (PST) MIME-Version: 1.0 References: <20210106064807.253112-1-Sonicadvance1@gmail.com> In-Reply-To: From: Arnd Bergmann Date: Fri, 15 Jan 2021 10:00:47 +0100 X-Gmail-Original-Message-ID: Message-ID: Subject: Re: [PATCH] Adds a new ioctl32 syscall for backwards compatibility layers To: Ryan Houdek Cc: Catalin Marinas , Will Deacon , Alexander Viro , Arnd Bergmann , Christian Brauner , Andrew Morton , Minchan Kim , Aleksa Sarai , Sargun Dhillon , Miklos Szeredi , Vincenzo Frascino , "Amanieu d'Antras" , Willem de Bruijn , YueHaibing , Xiaoming Ni , Heiko Carstens , "Eric W. Biederman" , Joe Perches , Jan Kara , David Rientjes , Arnaldo Carvalho de Melo , "David S. Miller" , Linux ARM , "linux-kernel@vger.kernel.org" , Linux FS-devel Mailing List , Linux API , linux-arch Content-Type: text/plain; charset="UTF-8" Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Fri, Jan 15, 2021 at 3:06 AM Ryan Houdek wrote: > On Wed, Jan 6, 2021 at 12:49 AM Arnd Bergmann wrote: >> On Wed, Jan 6, 2021 at 7:48 AM wrote: >> > From: Ryan Houdek >> ... >> >> For x86, this has another complication, as some ioctls also need to >> check whether they are in an ia32 task (with packed u64 and 32-bit >> __kernel_old_time_t) or an x32 task (with aligned u64 and 64-bit >> __kernel_old_time_t). If the new syscall gets wired up on x86 as well, >> you'd need to decide which of the two behaviors you want. > > > I can have a follow-up patch that makes this do ni-syscall on x86_64 since > we can go through the int 0x80 handler, or x32 handler path and choose > whichever one there. I'd say for consistency >> > 3a) Userspace consumes all VA space above 32bit. Forcing allocations to >> > occur in lower 32bits >> > - This is the current implementation >> > 3b) Ensure any allocation in the ioctl handles ioctl entrypoint rather >> > than just allow generic memory allocations in full VA space >> > - This is hard to guarantee >> >> What kind of allocation do you mean here? Can you give an example of >> an ioctl that does this? >> > My concern here would be something like DRM allocating memory and > returning a pointer to userspace that ends up in 64bit space. > I can see something like `drm_get_unmapped_area` calls in to > `current->mm->get_unmapped_area` which I believe only ends up falling > down TASK_SIZE checks. I see. > Which could potentially return pointers in the 64bit address space range > in this case. Theoretically can be resolved either by thieving the full 64bit > VA range, or doing something like the Tango layer patches that on > syscall entry changes the syscall to a "compat" syscall. > compat syscall flag like Tango might be nicer here? Not sure how that flag is best encoded, but yes, it would have to be somewhere that arch_get_unmapped_area() and arch_get_mmap_end() can find. Clearly we want a solution that works for both tango and for your work, as well as being portable to any architecture. >> > } >> > + >> > +COMPAT_SYSCALL_DEFINE3(ioctl, unsigned int, fd, unsigned int, cmd, >> > + compat_ulong_t, arg) >> > +{ >> > + return do_ioctl32(fd, cmd, arg); >> > +} >> > + >> > +SYSCALL_DEFINE3(ioctl32, unsigned int, fd, unsigned int, cmd, >> > + compat_ulong_t, arg) >> > +{ >> > + return do_ioctl32(fd, cmd, arg); >> > +} >> >> These two look identical to me, I don't think you need to add a wrapper >> here at all, but can just use the normal compat_sys_ioctl entry point >> unless you want to add a 'flags' argument to control the struct padding. > > > I tried having the dispatch table call directly in to the COMPAT one and > the way things were lining up weren't allowing me to do this. > Since this is a bit unique in how it operates, I'm not quite sure if there is > another example I could pull from for this. For the asm-generic/unistd.h, you should be able to write htis as #if __BITS_PER_LONG == 64 __SC_COMP(__NR_ioctl32, compat_sys_ioctl, sys_ni_syscall) #endif Which means that the native syscall in a 64-bit process always points to compat_sys_ioctl, while a 32-bit process always gets -ENOSYS. Similarly, the syscall_64.tbl file on x86 and the other 64-bit architectures would use 442 64 ioctl32 compat_sys_ioctl FWIW, I suppose you can rename compat_sys_ioctl to sys_ioctl32 treewide, if that name makes more sense. Arnd