Received: by 2002:ac0:a5a6:0:0:0:0:0 with SMTP id m35-v6csp26830imm; Thu, 27 Sep 2018 15:18:18 -0700 (PDT) X-Google-Smtp-Source: ACcGV61n47JVfFhG7Y8qn4GRDxGXtT+Hzm0+wdLsT2GXOjFdjBu7R4BT4TRFUBt8sngycemZjtdI X-Received: by 2002:a62:da1c:: with SMTP id c28-v6mr13701073pfh.68.1538086698039; Thu, 27 Sep 2018 15:18:18 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1538086698; cv=none; d=google.com; s=arc-20160816; b=GKh9bUlOv3j67FOf7MKdKghZUoLzt5MFA4+UeaOgcq9mb0QoFnmkQMGtIrQFZ85gpK m5to7VeYJ8P0cj+gjenqOhxcHMt2cEtPHmrAN5YXMH9ZHvmq46i8GZ97njQmO/Cc+9Nh NvO7i9DC2MUdDpraFRc3SYekgW+ubUsiSQFq3u85gq3T8N+7U/HXl/tnecth4UO/dj/X DiVMJw2Rsntx1jfrtiozDIB3HPaqqmSB6j6bTP8Af/u2oqlXaE1BgqVcGhbegysrelIp j8pD7JIDoNbs2IcSTEue9FUT8eVMs3UbexgFUgnYEc3XeNOLF9hxaxbx4Od1slUzMBkw Nr9g== 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=OM7EeGrjcsh1y+yxDFXAt8/Qwyt+S6tQgPGaZOC3y/g=; b=XrCW00s5/J6KWluLtCtLrdyvABD+FZ+3+yDiUmSoJ8bxPNKOgp0/Un/ro0tRZBNkm0 y3dZ7hFwgsuxKcfwyUhY0upW88n3wu5cvkDnRTw7TwULq23xdLa1gDA2An0r3ngcjABl G7JnqT9U8oGM+tu4HRWd88LUYVvY77HQw23d1uwsQE1zUh36xNvIviNHI7Y2nbskgB/k pg2HIlq7Q6M7PICGiK0WHCxbtQVgE1o5wth2y4KV+BfMEimUBevvSAypSSoJuQLkaPCy BEL+0Jd+1VdtFcGgE6HrIDcxYE1hyStRRCrCN+uLv9a3r/U3MxaAoky56q662YFY5po8 7dTA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@google.com header.s=20161025 header.b=VH7mTAPM; 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=REJECT sp=REJECT dis=NONE) header.from=google.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id e22-v6si2783275pgi.111.2018.09.27.15.18.00; Thu, 27 Sep 2018 15:18:18 -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=@google.com header.s=20161025 header.b=VH7mTAPM; 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=REJECT sp=REJECT dis=NONE) header.from=google.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1728161AbeI1EiD (ORCPT + 99 others); Fri, 28 Sep 2018 00:38:03 -0400 Received: from mail-ot1-f67.google.com ([209.85.210.67]:35429 "EHLO mail-ot1-f67.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726185AbeI1EiD (ORCPT ); Fri, 28 Sep 2018 00:38:03 -0400 Received: by mail-ot1-f67.google.com with SMTP id j9-v6so4181474otl.2 for ; Thu, 27 Sep 2018 15:17:35 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20161025; h=mime-version:references:in-reply-to:from:date:message-id:subject:to :cc; bh=OM7EeGrjcsh1y+yxDFXAt8/Qwyt+S6tQgPGaZOC3y/g=; b=VH7mTAPMcMX9kWfnpEdHxncbrfO1HRPALlQmBZQ5C2HJaPbDD4YZ8tt//mYk2qPe/7 q/9wF3ZSM+3VN0jPSJYZgUH81/hctLFjLPTmREtGQ9ONzvvnia/X/73MT1aQ7muxrHL/ QSI+5NpArI2n8w44x83oM7ql77CFlN5JcpgF9Yhhqam+9fv5w8PdQ6XOLnk+BSHruick BRZ6KuXH3vyQHEjSPuc1hbj7rPICSifwy3LCRztrIklgBZAyymYoCcPPu58xtFaCKuUC ujZ3fuyYnZ13SHgp/9Xv8u2awVNW+5VfgYZPULJrVKaV8EgNd/XT9y/jbEykMT9N7C29 dAdg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:mime-version:references:in-reply-to:from:date :message-id:subject:to:cc; bh=OM7EeGrjcsh1y+yxDFXAt8/Qwyt+S6tQgPGaZOC3y/g=; b=Y8NGtqoE2FAZJnXS9Iz758+MqlidjUDPg7Qbe919gy0spuwMPYwG+yXP7KptIrd9jb xMYLIIBPBo1LTY2XK6cNGuGglM5dOmIK9Y3I1ciINj96EecjEK/ll2pc9/L1fmWWiUsf gF5xnyL+pVJa6SUSnH+X0FIt80umyemBngg87EuduW4IQ66mH67yltOFPLCTqkE9oj1/ xo3MfVc1hW8U7zQNDc2N/0ohr0DE012PuB57w+hvaptKeNfocWS6YEkDCwoh3U4gVdzh L/ypvRnLwhI85RDlXpuTm92YLzjLFI6ODS9PBneqgzZFgU4tSeHa7i9NmockJBKA6IrC KDtQ== X-Gm-Message-State: ABuFfojMG7QM96zDXOqZtfOiuUsTzll5FUm3Q1Cm85pAKzdbzQqLqtGw nMJdlA8HWK7fi/IysYAbrEOCSvDSpTxeX/x2oB+1cg== X-Received: by 2002:a9d:2843:: with SMTP id h3-v6mr8717416otd.230.1538086654319; Thu, 27 Sep 2018 15:17:34 -0700 (PDT) MIME-Version: 1.0 References: <20180927151119.9989-1-tycho@tycho.ws> <20180927151119.9989-6-tycho@tycho.ws> <20180927221408.GD15491@cisco.cisco.com> In-Reply-To: <20180927221408.GD15491@cisco.cisco.com> From: Jann Horn Date: Fri, 28 Sep 2018 00:17:07 +0200 Message-ID: Subject: Re: [PATCH v7 5/6] seccomp: add a way to pass FDs via a notification fd To: Tycho Andersen Cc: Kees Cook , kernel list , containers@lists.linux-foundation.org, Linux API , Andy Lutomirski , Oleg Nesterov , "Eric W. Biederman" , "Serge E. Hallyn" , Christian Brauner , Tyler Hicks , suda.akihiro@lab.ntt.co.jp, linux-fsdevel@vger.kernel.org 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 Fri, Sep 28, 2018 at 12:14 AM Tycho Andersen wrote: > On Thu, Sep 27, 2018 at 09:28:07PM +0200, Jann Horn wrote: > > On Thu, Sep 27, 2018 at 5:11 PM Tycho Andersen wrote: > > > This patch adds a way to insert FDs into the tracee's process (also > > > close/overwrite fds for the tracee). This functionality is necessary to > > > mock things like socketpair() or dup2() or similar, but since it depends on > > > external (vfs) patches, I've left it as a separate patch as before so the > > > core functionality can still be merged while we argue about this. Except > > > this time it doesn't add any ugliness to the API :) > > [...] > > > +static long seccomp_notify_put_fd(struct seccomp_filter *filter, > > > + unsigned long arg) > > > +{ > > > + struct seccomp_notif_put_fd req; > > > + void __user *buf = (void __user *)arg; > > > + struct seccomp_knotif *knotif = NULL; > > > + long ret; > > > + > > > + if (copy_from_user(&req, buf, sizeof(req))) > > > + return -EFAULT; > > > + > > > + if (req.fd < 0 && req.to_replace < 0) > > > + return -EINVAL; > > > + > > > + ret = mutex_lock_interruptible(&filter->notify_lock); > > > + if (ret < 0) > > > + return ret; > > > + > > > + ret = -ENOENT; > > > + list_for_each_entry(knotif, &filter->notif->notifications, list) { > > > + struct file *file = NULL; > > > + > > > + if (knotif->id != req.id) > > > + continue; > > > > Are you intentionally permitting non-SENT states here? It shouldn't > > make a big difference, but I think it'd be nice to at least block the > > use of notifications in SECCOMP_NOTIFY_REPLIED state. > > Agreed, I'll block everything besides REPLIED. Do you mean SENT? In REPLIED state, seccomp_notify_put_fd() is racy because the target task is in the process of waking up, right?