Received: by 2002:a25:ab43:0:0:0:0:0 with SMTP id u61csp8147804ybi; Thu, 6 Jun 2019 07:29:15 -0700 (PDT) X-Google-Smtp-Source: APXvYqz7vqKwsWcciwUxydIbVn1+WxAsvsUI23q9jFiibb2uHNmfHKOK+drGyLZUAU7gDts129sp X-Received: by 2002:a17:90a:2488:: with SMTP id i8mr137248pje.123.1559831355254; Thu, 06 Jun 2019 07:29:15 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1559831355; cv=none; d=google.com; s=arc-20160816; b=oa26QS5KRoR6x9SI/Hsoec3tZc83rXS897AteI+rjMB+Gjkl8Z7O3PlI13oyGcHXm1 23KXSlN+1YVN8D0zUhMTUSvWKEyyg/jxcRwilB8Tq2QC5ksoT5/yjQlRa/qfPPlReZsN tTwr7j7ribaysXvMKG1gEE5tc84tl36zWdo5/w2cn/ULQsJk5eh5JsaDrKUMpM/sZxb7 CzSKo3gTHEAJREFYIxZ05zO+e8v5fyIG9ESibn/GPJW8nSPRMKKUdZv2xcXUEUOTe3zR xB3omVRqIgpMo94/KO4StHZS9u3arOP0ZGwIUMIruyJcR9zQijwaxPOHg7ZrkRYKAB6m htuA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:user-agent:in-reply-to :content-disposition:mime-version:references:message-id:subject:cc :to:from:date:dkim-signature; bh=O/jaU6k3+AGh4iDS048RC5QsB5CsTzgoSJ2lbgW3nNo=; b=gVMeE6jyK/E7FXcqT5LNGbzXOPPGf52jYTWXpyJd6J70idSP5X1fjXh2levF7MvBpt +ywxpzL7rMcDuImyClGcIswu7Lkp4EAl28kTPRQsTKfBQssboha4kq1oKnTaiEp1dJsu dwDyQKPtLP7A7SkJD6FQYpVQVOHyD+0ymS95JImT6P+J38/KZp1JOKydVc25CY67QTuy FjE0ogMpD7hAY9qhprY7i6dki79tAk3vzcn3CvWac18mm1GpxKayEW0WE4krrrjvzRUp P0FesgpoScj8jhKlcLPsE13U/LaXoUTeVySTA47cOT/Q3MeN4ms0DqQZThb623C6wOaf 45rw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=default header.b=qD5swS4+; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id h4si1971284pjs.103.2019.06.06.07.28.57; Thu, 06 Jun 2019 07:29:15 -0700 (PDT) Received-SPF: pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; dkim=pass header.i=@kernel.org header.s=default header.b=qD5swS4+; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1728998AbfFFO1b (ORCPT + 99 others); Thu, 6 Jun 2019 10:27:31 -0400 Received: from mail.kernel.org ([198.145.29.99]:37608 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1727133AbfFFO1a (ORCPT ); Thu, 6 Jun 2019 10:27:30 -0400 Received: from localhost (83-86-89-107.cable.dynamic.v4.ziggo.nl [83.86.89.107]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPSA id DE51320665; Thu, 6 Jun 2019 14:27:28 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1559831249; bh=YTbef3FvFKe2GsGHOo89NJrG+tTsjZZWyqwHqfe7Q+s=; h=Date:From:To:Cc:Subject:References:In-Reply-To:From; b=qD5swS4+kfog1cpjdyhiJh8iUgUAniNfx7ltHlLMFC9Loq0rkE+VsVyPvEtyKmcht sILxQWrBfKL3qK+00zU0O6dPzgGGeHi7DV6zL0a7R9+6Hgt4ggGTaYZjgKuzoAfS95 LDdZu/j4npE3d71Y4LzNgpa+5428A7bvU/BwGS7Q= Date: Thu, 6 Jun 2019 16:27:27 +0200 From: Greg Kroah-Hartman To: "Eric W. Biederman" Cc: Alan Stern , linux-usb@vger.kernel.org, Oliver Neukum , linux-kernel@vger.kernel.org Subject: Re: [PATCH] signal/usb: Replace kill_pid_info_as_cred with kill_pid_usb_asyncio Message-ID: <20190606142727.GA10785@kroah.com> References: <877eakou9o.fsf@xmission.com> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <877eakou9o.fsf@xmission.com> User-Agent: Mutt/1.12.0 (2019-05-25) Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Tue, May 21, 2019 at 07:40:35AM -0500, Eric W. Biederman wrote: > > The usb support for asyncio encoded one of it's values in the wrong > field. It should have used si_value but instead used si_addr which is > not present in the _rt union member of struct siginfo. > > The practical result of this is that on a 64bit big endian kernel > when delivering a signal to a 32bit process the si_addr field > is set to NULL, instead of the expected pointer value. > > This issue can not be fixed in copy_siginfo_to_user32 as the usb > usage of the the _sigfault (aka si_addr) member of the siginfo > union when SI_ASYNCIO is set is incompatible with the POSIX and > glibc usage of the _rt member of the siginfo union. > > Therefore replace kill_pid_info_as_cred with kill_pid_usb_asyncio a > dedicated function for this one specific case. There are no other > users of kill_pid_info_as_cred so this specialization should have no > impact on the amount of code in the kernel. Have kill_pid_usb_asyncio > take instead of a siginfo_t which is difficult and error prone, 3 > arguments, a signal number, an errno value, and an address enconded as > a sigval_t. The encoding of the address as a sigval_t allows the > code that reads the userspace request for a signal to handle this > compat issue along with all of the other compat issues. > > Add BUILD_BUG_ONs in kernel/signal.c to ensure that we can now place > the pointer value at the in si_pid (instead of si_addr). That is the > code now verifies that si_pid and si_addr always occur at the same > location. Further the code veries that for native structures a value > placed in si_pid and spilling into si_uid will appear in userspace in > si_addr (on a byte by byte copy of siginfo or a field by field copy of > siginfo). The code also verifies that for a 64bit kernel and a 32bit > userspace the 32bit pointer will fit in si_pid. > > I have used the usbsig.c program below written by Alan Stern and > slightly tweaked by me to run on a big endian machine to verify the > issue exists (on sparc64) and to confirm the patch below fixes the issue. > > /* usbsig.c -- test USB async signal delivery */ > > static struct usbdevfs_urb urb; > static struct usbdevfs_disconnectsignal ds; > static volatile sig_atomic_t done = 0; > > void urb_handler(int sig, siginfo_t *info , void *ucontext) > { > printf("Got signal %d, signo %d errno %d code %d addr: %p urb: %p\n", > sig, info->si_signo, info->si_errno, info->si_code, > info->si_addr, &urb); > > printf("%s\n", (info->si_addr == &urb) ? "Good" : "Bad"); > } > > void ds_handler(int sig, siginfo_t *info , void *ucontext) > { > printf("Got signal %d, signo %d errno %d code %d addr: %p ds: %p\n", > sig, info->si_signo, info->si_errno, info->si_code, > info->si_addr, &ds); > > printf("%s\n", (info->si_addr == &ds) ? "Good" : "Bad"); > done = 1; > } > > int main(int argc, char **argv) > { > char *devfilename; > int fd; > int rc; > struct sigaction act; > struct usb_ctrlrequest *req; > void *ptr; > char buf[80]; > > if (argc != 2) { > fprintf(stderr, "Usage: usbsig device-file-name\n"); > return 1; > } > > devfilename = argv[1]; > fd = open(devfilename, O_RDWR); > if (fd == -1) { > perror("Error opening device file"); > return 1; > } > > act.sa_sigaction = urb_handler; > sigemptyset(&act.sa_mask); > act.sa_flags = SA_SIGINFO; > > rc = sigaction(SIGUSR1, &act, NULL); > if (rc == -1) { > perror("Error in sigaction"); > return 1; > } > > act.sa_sigaction = ds_handler; > sigemptyset(&act.sa_mask); > act.sa_flags = SA_SIGINFO; > > rc = sigaction(SIGUSR2, &act, NULL); > if (rc == -1) { > perror("Error in sigaction"); > return 1; > } > > memset(&urb, 0, sizeof(urb)); > urb.type = USBDEVFS_URB_TYPE_CONTROL; > urb.endpoint = USB_DIR_IN | 0; > urb.buffer = buf; > urb.buffer_length = sizeof(buf); > urb.signr = SIGUSR1; > > req = (struct usb_ctrlrequest *) buf; > req->bRequestType = USB_DIR_IN | USB_TYPE_STANDARD | USB_RECIP_DEVICE; > req->bRequest = USB_REQ_GET_DESCRIPTOR; > req->wValue = htole16(USB_DT_DEVICE << 8); > req->wIndex = htole16(0); > req->wLength = htole16(sizeof(buf) - sizeof(*req)); > > rc = ioctl(fd, USBDEVFS_SUBMITURB, &urb); > if (rc == -1) { > perror("Error in SUBMITURB ioctl"); > return 1; > } > > rc = ioctl(fd, USBDEVFS_REAPURB, &ptr); > if (rc == -1) { > perror("Error in REAPURB ioctl"); > return 1; > } > > memset(&ds, 0, sizeof(ds)); > ds.signr = SIGUSR2; > ds.context = &ds; > rc = ioctl(fd, USBDEVFS_DISCSIGNAL, &ds); > if (rc == -1) { > perror("Error in DISCSIGNAL ioctl"); > return 1; > } > > printf("Waiting for usb disconnect\n"); > while (!done) { > sleep(1); > } > > close(fd); > return 0; > } > > Cc: Greg Kroah-Hartman > Cc: linux-usb@vger.kernel.org > Cc: Alan Stern > Cc: Oliver Neukum > Fixes: v2.3.39 > Cc: stable@vger.kernel.org > Signed-off-by: "Eric W. Biederman" > --- Ugh, what a mess, thanks for doing this work: Reviewed-by: Greg Kroah-Hartman