Received: by 2002:a25:2c96:0:0:0:0:0 with SMTP id s144csp672060ybs; Sun, 24 May 2020 17:49:25 -0700 (PDT) X-Google-Smtp-Source: ABdhPJzF3A8xocujACyJ0XmNk777d/UsPUK4QFozY/fpdqeGzOLh7jCBJ+erETnEupwahmUcTMPP X-Received: by 2002:a17:906:1ccd:: with SMTP id i13mr17758077ejh.148.1590367765640; Sun, 24 May 2020 17:49:25 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1590367765; cv=none; d=google.com; s=arc-20160816; b=tfsOETGnZicOPvbeb4N/SUUOD/ah0peCj4rIunWoabLQN5bwlKPq5ZmdmEuVU0wKjM YlGUgYeEJaIIq9AW1HUwfSLUQFaokphGNBGnLeJ+cPOJApxZnSOCrJ5TPseWOc8jejTc VYUMjwOqoRD3PG/akk3/tZmth4SJXi72cvQkMZ/o4byiNR+iFs99+XJfpNkU9OytJZc8 qissM9immpw6bK6SF48utBlXeSaVTW9qwMEt+9U41IQ9e/KQaymiD/KlUeBTS0vm31nf QUJBfsaev35JQ+xd29FJOxSrj9ELJU1kZwvB1muc4Id/JxzLrwEIJorBrTKU1ImMpGEF C+FQ== 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=EwykEdM3SyRomohU3e5rjyCqJmUudG4184nZb0VuwGU=; b=SzcSzsp+yUMAbqOQdXW9l6Gxwg7nevMLbkUvrqfMp1gfhvOZ/Z2QZn0ZREgPzjpBA9 W5ODV0ExJ9x4VpV9di3CNXssmzewPpDHRjkFZ9jOvsb0+HGBLFPF2gTB0JkNdjVqRx43 kO6JUaUAdkAbG8N5dbg7BGu0Sgprzr3yD90Hs8hz4gJdU4LtgHomZECCZ7c2nU6sbnD5 ByQEzbo+tcvyHQ9ujqOjgbPQBO1F7ayqjWB3rJsvdU8V8qtkZcqNVRXw06AEdMUeFR6o jyEWzehDGcRvsz3ePGpLGVFF8+PWrHUGFNkLLHGNatYauboTpfXtSOQiysX8orD0Rz28 Tbzw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@sargun.me header.s=google header.b=aJ49HXpD; 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 Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id fy7si4385549ejb.499.2020.05.24.17.49.00; Sun, 24 May 2020 17:49:25 -0700 (PDT) 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=@sargun.me header.s=google header.b=aJ49HXpD; 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 Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S2388657AbgEYA2g (ORCPT + 99 others); Sun, 24 May 2020 20:28:36 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:56134 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S2388431AbgEYA2f (ORCPT ); Sun, 24 May 2020 20:28:35 -0400 Received: from mail-ej1-x642.google.com (mail-ej1-x642.google.com [IPv6:2a00:1450:4864:20::642]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 83D69C061A0E for ; Sun, 24 May 2020 17:28:35 -0700 (PDT) Received: by mail-ej1-x642.google.com with SMTP id n24so18868922ejd.0 for ; Sun, 24 May 2020 17:28:35 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=sargun.me; s=google; h=mime-version:references:in-reply-to:from:date:message-id:subject:to :cc; bh=EwykEdM3SyRomohU3e5rjyCqJmUudG4184nZb0VuwGU=; b=aJ49HXpD8xoJymFOGHw1Nc6cTn41t6yYceBnCnsfkEqmu3aJ27VyozXfpO/GoSZC/R UJ3yEwYnBWMl9OKyjjI9EdX90Lxbf6cWAp4os/Ue1Q8oVNySS2a/98rceH1q0GTQbg9B nP4GgcY/CUptu5HoHw/M/CetsHczAvdav/BPU= 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=EwykEdM3SyRomohU3e5rjyCqJmUudG4184nZb0VuwGU=; b=snD7T7VzKYDuq7O056b9icJkzxrBgbBsH/SQuiBkziY4WaIJzr1tNHNeNSBmvTDLYA elLr6JECf1aQVoSv/IGITcDCa6Dno+J+BGypzS1DcwvNJ4BH17i9iHix0ujGEYReJBKw FMA2CxeK5rf4l7urUkQqUcq2tplmLFxA41/Nl7pbJ+G0Fw5DyThsqKLP2XmD88kkPrKl 1XAnOVPK1cX7X2xzkRGf3W3FGDQIh7bMI7taQiaucBifKINqD5h4tz45adzUcVzWC+RC sB0ijyK7RQPd/zaWowbKRiPNkllEIQz9DjT/B2AQ0yl+NakofFKvj8IUWyTYfslVcVyY VGaQ== X-Gm-Message-State: AOAM533m+/WpQh0DnMSAxlkI/zexK7i0hErF2AcYM/9ttVAF7KSXetQM L8dPvTMdFnJKHUlO4PliCjdi+S0nPYJu1gQB2HiF7Q== X-Received: by 2002:a17:906:2cc2:: with SMTP id r2mr16329022ejr.269.1590366514113; Sun, 24 May 2020 17:28:34 -0700 (PDT) MIME-Version: 1.0 References: <20200524233942.8702-1-sargun@sargun.me> <20200524233942.8702-3-sargun@sargun.me> <20200525000537.GB23230@ZenIV.linux.org.uk> In-Reply-To: <20200525000537.GB23230@ZenIV.linux.org.uk> From: Sargun Dhillon Date: Sun, 24 May 2020 17:27:58 -0700 Message-ID: Subject: Re: [PATCH 2/5] seccomp: Introduce addfd ioctl to seccomp user notifier To: Al Viro Cc: LKML , Linux Containers , Linux API , Christian Brauner , Tycho Andersen , Kees Cook , Aleksa Sarai , Jeffrey Vander Stoep , Jann Horn , Robert Sesek , Chris Palmer , Matt Denton , Kees Cook 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 Sun, May 24, 2020 at 5:05 PM Al Viro wrote: > > On Sun, May 24, 2020 at 04:39:39PM -0700, Sargun Dhillon wrote: > > Bad refcounting rules. *IF* we go with anything of that sort (and I'm not > convinced that the entire series makes sense), it's better to have more > uniform rules re reference consumption/disposal. > > Make the destructor of addfd *ALWAYS* drop its reference. And have this > function go Are you suggesting the in both the error, and non-error cases the ioctl invoker side is responsible for fput'ing the final reference in both the success and non-success cases? Would we take an extra reference prior to fd_install? > > if (addfd->fd >= 0) { > ret = replace_fd(addfd->fd, addfd->file, addfd->flags); > } else { > ret = get_unused_fd_flags(addfd->flags); > if (ret >= 0) > fd_install(ret, get_file(addfd->file)); > } > Wouldn't this result in consumption of reference in one case (fd_install), and the fd still having a reference in the replace_fd case?