Received: by 2002:a25:683:0:0:0:0:0 with SMTP id 125csp572881ybg; Fri, 12 Jun 2020 08:57:39 -0700 (PDT) X-Google-Smtp-Source: ABdhPJxELnYv6kksXLkzYGcRefupi9R5jrZewdumR2/irrplub8TxzNr4HwkDXVJoBDoIT5E/t+1 X-Received: by 2002:a50:ee04:: with SMTP id g4mr12136712eds.119.1591977459536; Fri, 12 Jun 2020 08:57:39 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1591977459; cv=none; d=google.com; s=arc-20160816; b=jDoHo2dKQuo4N0MQzDpfDGBdZ1dlxPyMr2xRlgDitCb1T04LukDV/1bpnIOWVXyn2q BQu9/0Z6xizJQev39v7My930NozgaHTB4kwXgyr9HfX6RpDeO58ksk2E8s5Kb4pAltWn 73c8dYoHFISZm5b65FXcA1i1J+mixFdeBHaMcpO5ZKLWLYHE5fQC/5PtXae3iKlayaw7 exc0kTVffYTLVCaIljUUuA8wxUshT79IDJt76i53oSKG9mpKbAkUEhBQwM2CLOjDmCRf u6NnoybZ83uwiBJCy1fKEmd3Zqb4SLYKHw6lsSeDZtN8OdhX9Pz2owkn36R/FdjXHITH TOxQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:content-transfer-encoding:mime-version :content-language:accept-language:in-reply-to:references:message-id :date:thread-index:thread-topic:subject:cc:to:from; bh=7azpWh5jOk65nPlIEI2uX5/F1DzWur17oTX1KZKl7Dw=; b=ki8pgDuyWhLcYqRGWTN3WLf2v1sN1AzVHdR/TKui0WSPteoM9aojME3oQVJ7Sgls6N 9nM1UrqxE8mjD9LfDl9VE5mOdT+U7psF4WljS/I33tpduglWhbgBgqlmqCsL9+EDkYhk LQCKx+XrNWFsneAv+T53B1URaZz5FZkUBPDya25gPhebfoUeC+2IV132iAK1BcHrIvfQ ZsUc23LqeMxhnp9EU0NCER6U7TwPvElfjk98cYe/ktXKb2UdxNnLx3iLNSmRb0aguB8j jo0Am7wy8n5IfhzuXpsYwcG85XrZeQxih94mB/TYKqT03uOl4p6qd7tA8L21PPWLuaqt CyzQ== ARC-Authentication-Results: i=1; mx.google.com; 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=fail (p=NONE sp=NONE dis=NONE) header.from=aculab.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id o25si4098198eja.361.2020.06.12.08.57.15; Fri, 12 Jun 2020 08:57:39 -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; 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=fail (p=NONE sp=NONE dis=NONE) header.from=aculab.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1726108AbgFLPzU convert rfc822-to-8bit (ORCPT + 99 others); Fri, 12 Jun 2020 11:55:20 -0400 Received: from eu-smtp-delivery-151.mimecast.com ([207.82.80.151]:40534 "EHLO eu-smtp-delivery-151.mimecast.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726085AbgFLPzT (ORCPT ); Fri, 12 Jun 2020 11:55:19 -0400 Received: from AcuMS.aculab.com (156.67.243.126 [156.67.243.126]) (Using TLS) by relay.mimecast.com with ESMTP id uk-mta-256-WF26PnyoMeW0bYbJgCCLOA-1; Fri, 12 Jun 2020 16:55:15 +0100 X-MC-Unique: WF26PnyoMeW0bYbJgCCLOA-1 Received: from AcuMS.Aculab.com (fd9f:af1c:a25b:0:43c:695e:880f:8750) by AcuMS.aculab.com (fd9f:af1c:a25b:0:43c:695e:880f:8750) with Microsoft SMTP Server (TLS) id 15.0.1347.2; Fri, 12 Jun 2020 16:55:15 +0100 Received: from AcuMS.Aculab.com ([fe80::43c:695e:880f:8750]) by AcuMS.aculab.com ([fe80::43c:695e:880f:8750%12]) with mapi id 15.00.1347.000; Fri, 12 Jun 2020 16:55:15 +0100 From: David Laight To: 'Kees Cook' , Sargun Dhillon CC: Christian Brauner , "containers@lists.linux-foundation.org" , Giuseppe Scrivano , Robert Sesek , Chris Palmer , Jann Horn , Greg Kroah-Hartman , "linux-kernel@vger.kernel.org" , Matt Denton , "linux-fsdevel@vger.kernel.org" , Tejun Heo , Al Viro , "cgroups@vger.kernel.org" , "stable@vger.kernel.org" , "David S . Miller" Subject: RE: [PATCH v3 1/4] fs, net: Standardize on file_receive helper to move fds across processes Thread-Topic: [PATCH v3 1/4] fs, net: Standardize on file_receive helper to move fds across processes Thread-Index: AQHWP+BcCi14oegu0U6J73sUpcDiU6jTfHDAgACI+YCAAKH2YIAAcPLvgAAKH6A= Date: Fri, 12 Jun 2020 15:55:14 +0000 Message-ID: References: <037A305F-B3F8-4CFA-B9F8-CD4C9EF9090B@ubuntu.com> <202006092227.D2D0E1F8F@keescook> <20200610081237.GA23425@ircssh-2.c.rugged-nimbus-611.internal> <202006101953.899EFB53@keescook> <20200611100114.awdjswsd7fdm2uzr@wittgenstein> <20200611110630.GB30103@ircssh-2.c.rugged-nimbus-611.internal> <067f494d55c14753a31657f958cb0a6e@AcuMS.aculab.com> <202006111634.8237E6A5C6@keescook> <94407449bedd4ba58d85446401ff0a42@AcuMS.aculab.com> <20200612104629.GA15814@ircssh-2.c.rugged-nimbus-611.internal> <202006120806.E770867EF@keescook> In-Reply-To: <202006120806.E770867EF@keescook> Accept-Language: en-GB, en-US Content-Language: en-US X-MS-Has-Attach: X-MS-TNEF-Correlator: x-ms-exchange-transport-fromentityheader: Hosted x-originating-ip: [10.202.205.107] MIME-Version: 1.0 X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: aculab.com Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8BIT Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org From: Kees Cook > Sent: 12 June 2020 16:13 ... > > /* Fixed size ioctls. Can be converted later on? */ > > switch (cmd) { > > case SECCOMP_IOCTL_NOTIF_RECV: > > return seccomp_notify_recv(filter, buf); > > case SECCOMP_IOCTL_NOTIF_SEND: > > return seccomp_notify_send(filter, buf); > > case SECCOMP_IOCTL_NOTIF_ID_VALID: > > return seccomp_notify_id_valid(filter, buf); > > } > > > > /* Probably should make some nicer macros here */ > > switch (SIZE_MASK(DIR_MASK(cmd))) { > > case SIZE_MASK(DIR_MASK(SECCOMP_IOCTL_NOTIF_ADDFD)): > > Ah yeah, I like this because of what you mention below: it's forward > compat too. (I'd just use the ioctl masks directly...) > > switch (cmd & ~(_IOC_SIZEMASK | _IOC_DIRMASK)) Since you need the same mask on the case labels I think I'd define a helper just across the switch statement: #define M(cmd) ((cmd & ~(_IOC_SIZEMASK | _IOC_DIRMASK)) switch (M(cmd)) { case M(SECCOMP_IOCTL_NOTIF_RECV): ... } #undef M It is probably wrong to mask off DIRMASK. But you might need to add extra case labels for the broken one(s). Prior to worries about indirect jumps you could get a dense set of case label and faster code. David - Registered Address Lakeside, Bramley Road, Mount Farm, Milton Keynes, MK1 1PT, UK Registration No: 1397386 (Wales)