Received: by 2002:a25:ad19:0:0:0:0:0 with SMTP id y25csp8158297ybi; Tue, 23 Jul 2019 03:50:36 -0700 (PDT) X-Google-Smtp-Source: APXvYqxn3G3CTWc2qxsg7g1XVXi3x3E9Dup/dd5kMy4bg37q9WhhLw3rwSzkLvg7IwNPbkFR7TmT X-Received: by 2002:a17:90a:270f:: with SMTP id o15mr81773087pje.56.1563879035924; Tue, 23 Jul 2019 03:50:35 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1563879035; cv=none; d=google.com; s=arc-20160816; b=A3oNUQFt0gGfLl6Nz7RLsBmdd3/70gjBHzLpr2T0dWr6wELCTdXdy0WNk7+V/g3QpS SFc/VFxGMXfGg+hLkTiXLJVnTG2pBX1zR4rklyxapr6xg7ApP0/nVHxvqsetrDwaB5/5 SbTUfWZvJt6l6FZGVemQQ+ZP1EIrlmOlVqU0UG7FyHCXtrDfzdk24gcvtXu8tUrd/Ynq JD7oBVlltIzyO1dd5+Btc1Wm+1c5si9y7I4oKneuHK0q6U8FdBoBkko7zmzt9yO/YWcb vKleAwmfODEx3BlB+5H58MVBREDT86zuV4jaNJb5CUcR8/SsGZT+UrpVkUfhDerlFc3c 2nRA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:cc:to:subject:message-id:date:from :in-reply-to:references:mime-version:dkim-signature; bh=B3csljNxSAMC8dXGBnIJKIxxKZ6wVtvrhNqS/CnG6ac=; b=VdCyg+Va2VQ5lbXwEqFdraVA/8FMn2xz27xVXK6bw8cuckF3ZNpIa3lOaPBzW6kuGD tW/ohm2uKvtcDteMNe1QU4r7S2qPfBZa6FvHXqEer5z0Boew2ifCbypzfs8g2pk8HDeM Mj40LDfhPZkJA9Joen/tiUN88QzSqu+pg1ofzZpqREINPsbmO6KNd2x8BnpVAj/hAuiX E2mmjfJfxdpR/ymSbup9cFl2wgXo82kjaEwCh0foPVTC9zj8sSyA4fLEnYHzSQPNW6Q2 QSxiPAccBqsoNu/Vlhd+g8OZzDFV9NdqFwQMSjj3PDqHaQYdx2enDi9Jg7VjhPsCS6UA hgpA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=default header.b=EkqROvek; 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; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id f5si11165709pln.228.2019.07.23.03.50.20; Tue, 23 Jul 2019 03:50:35 -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=EkqROvek; 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; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1731727AbfGVXru (ORCPT + 99 others); Mon, 22 Jul 2019 19:47:50 -0400 Received: from mail.kernel.org ([198.145.29.99]:40236 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1728655AbfGVXru (ORCPT ); Mon, 22 Jul 2019 19:47:50 -0400 Received: from mail-wr1-f51.google.com (mail-wr1-f51.google.com [209.85.221.51]) (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 946F421E70 for ; Mon, 22 Jul 2019 23:47:49 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1563839269; bh=ZJaWlqPi2cdZE2l3aFe+zt2XP8rCoSUqW+jNvs+HvNM=; h=References:In-Reply-To:From:Date:Subject:To:Cc:From; b=EkqROvek39weM/EmV7A0thZwlX/NAlBfawlc0NcqiZY01njUcGWhiGpUMo9HvH9sR m1Ne/VIJ8ORlqcwW+/RnvQ36aDp9zUbe5ZqOUOok9fgOWLBjA8krGJ5kGrN1+eHoKX qZHPRnp/qin31xajsOh4DCjVxwZkDB0kqGfZTyaw= Received: by mail-wr1-f51.google.com with SMTP id 31so41175413wrm.1 for ; Mon, 22 Jul 2019 16:47:49 -0700 (PDT) X-Gm-Message-State: APjAAAXWu/ovbXMjoMGYbQ9atnPjrVdhSAVZxOgPckhQSgFj46bZ8EUB OMTLdGYbgmtp0X46QqeX2sbzDyzX52JmjO8bEsybPQ== X-Received: by 2002:a5d:4309:: with SMTP id h9mr74387750wrq.221.1563839268042; Mon, 22 Jul 2019 16:47:48 -0700 (PDT) MIME-Version: 1.0 References: <20190719170343.GA13680@linux.intel.com> <19EF7AC8-609A-4E86-B45E-98DFE965DAAB@amacapital.net> <201907221012.41504DCD@keescook> <201907221135.2C2D262D8@keescook> <201907221620.F31B9A082@keescook> In-Reply-To: <201907221620.F31B9A082@keescook> From: Andy Lutomirski Date: Mon, 22 Jul 2019 16:47:36 -0700 X-Gmail-Original-Message-ID: Message-ID: Subject: Re: [5.2 REGRESSION] Generic vDSO breaks seccomp-enabled userspace on i386 To: Kees Cook Cc: Andy Lutomirski , Thomas Gleixner , Sean Christopherson , Vincenzo Frascino , X86 ML , LKML Content-Type: text/plain; charset="UTF-8" Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Mon, Jul 22, 2019 at 4:28 PM Kees Cook wrote: > > On Mon, Jul 22, 2019 at 12:17:16PM -0700, Andy Lutomirski wrote: > > On Mon, Jul 22, 2019 at 11:39 AM Kees Cook wrote: > > > > > > On Mon, Jul 22, 2019 at 08:31:32PM +0200, Thomas Gleixner wrote: > > > > On Mon, 22 Jul 2019, Kees Cook wrote: > > > > > Just so I'm understanding: the vDSO change introduced code to make an > > > > > actual syscall on i386, which for most seccomp filters would be rejected? > > > > > > > > No. The old x86 specific VDSO implementation had a fallback syscall as > > > > well, i.e. clock_gettime(). On 32bit clock_gettime() uses the y2038 > > > > endangered timespec. > > > > > > > > So when the VDSO was made generic we changed the internal data structures > > > > to be 2038 safe right away. As a consequence the fallback syscall is not > > > > clock_gettime(), it's clock_gettime64(). which seems to surprise seccomp. > > > > > > Okay, it's didn't add a syscall, it just changed it. Results are the > > > same: conservative filters suddenly start breaking due to the different > > > call. (And now I see why Andy's alias suggestion would help...) > > > > > > I'm not sure which direction to do with this. It seems like an alias > > > list is a large hammer for this case, and a "seccomp-bypass when calling > > > from vDSO" solution seems too fragile? > > > > > > > I don't like the seccomp bypass at all. If someone uses seccomp to > > disallow all clock_gettime() variants, there shouldn't be a back door > > to learn the time. > > > > Here's the restart_syscall() logic that makes me want aliases: we have > > different syscall numbers for restart_syscall() on 32-bit and 64-bit. > > The logic to decide which one to use is dubious at best. I'd like to > > introduce a restart_syscall2() that is identical to restart_syscall() > > except that it has the same number on both variants. > > I've built a straw-man for this idea... but I have to say I don't > like it. This can lead to really unexpected behaviors if someone > were to have differing filters for the two syscalls. For example, > let's say someone was doing a paranoid audit of 2038-unsafe clock usage > and marked clock_gettime() with RET_KILL and marked clock_gettime64() > with RET_LOG. This aliasing would make clock_gettime64() trigger with > RET_KILL... This particular issue is solvable: > + /* Handle syscall aliases when result is not SECCOMP_RET_ALLOW. */ > + if (unlikely(action != SECCOMP_RET_ALLOW)) { > + int alias; > + > + alias = seccomp_syscall_alias(sd->arch, sd->nr); > + if (unlikely(alias != -1)) { > + /* Use sd_local for an aliased syscall. */ > + if (sd != &sd_local) { > + sd_local = *sd; > + sd = &sd_local; > + } > + sd_local.nr = alias; > + > + /* Run again, with the alias, accepting the results. */ > + filter_ret = seccomp_run_filters(sd, &match); > + data = filter_ret & SECCOMP_RET_DATA; > + action = filter_ret & SECCOMP_RET_ACTION_FULL; How about: new_data = ...; new_action = ...; if (new_action == SECCOMP_RET_ALLOW) { data = new_data; action = new_action; } It might also be nice to allow a filter to say "hey, I want to set this result and I do *not* want compatibility aliases applied", but I'm not quite sure how to express that. I don't love this whole concept, but I also don't have a better idea. --Andy