From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-0.8 required=3.0 tests=HEADER_FROM_DIFFERENT_DOMAINS, MAILING_LIST_MULTI,SPF_PASS,URIBL_BLOCKED autolearn=ham autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 8CF09C43382 for ; Wed, 26 Sep 2018 20:18:20 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id 37A052150C for ; Wed, 26 Sep 2018 20:18:20 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org 37A052150C Authentication-Results: mail.kernel.org; dmarc=none (p=none dis=none) header.from=sipsolutions.net Authentication-Results: mail.kernel.org; spf=none smtp.mailfrom=linux-wireless-owner@vger.kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1726727AbeI0Ccn (ORCPT ); Wed, 26 Sep 2018 22:32:43 -0400 Received: from s3.sipsolutions.net ([144.76.43.62]:46102 "EHLO sipsolutions.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726421AbeI0Ccn (ORCPT ); Wed, 26 Sep 2018 22:32:43 -0400 Received: by sipsolutions.net with esmtpsa (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.91) (envelope-from ) id 1g5GFy-00045x-Du; Wed, 26 Sep 2018 22:17:58 +0200 Message-ID: <1537993066.28767.29.camel@sipsolutions.net> Subject: Re: [PATCH] netlink: add policy attribute range validation From: Johannes Berg To: linux-wireless@vger.kernel.org, netdev@vger.kernel.org Date: Wed, 26 Sep 2018 22:17:46 +0200 In-Reply-To: <20180926200630.23399-1-johannes@sipsolutions.net> (sfid-20180926_220654_781731_7A389A4D) References: <20180926200630.23399-1-johannes@sipsolutions.net> (sfid-20180926_220654_781731_7A389A4D) Content-Type: text/plain; charset="UTF-8" X-Mailer: Evolution 3.26.6 (3.26.6-1.fc27) Mime-Version: 1.0 Content-Transfer-Encoding: 7bit Sender: linux-wireless-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-wireless@vger.kernel.org On Wed, 2018-09-26 at 22:06 +0200, Johannes Berg wrote: > From: Johannes Berg > > Without further bloating the policy structs, we can overload > the `validation_data' pointer with a struct of s16 min, max > and use those to validate ranges in NLA_{U,S}{8,16,32,64} > attributes. > > It may sound strange to validate NLA_U32 with a s16 max, but > in many cases NLA_U32 is used for enums etc. since there's no > size benefit in using a smaller attribute width anyway, due > to netlink attribute alignment; in cases like that it's still > useful, particularly when the attribute really transports an > enum value. That said, I did find a few places where we could benefit from a larger type here - e.g. having a NLA_U16 that must be non-zero cannot be represented in the policy as is, since you can't set max to 65535. However, I don't think we want to push the policy struct to 12 bytes on 32-bit platforms? It's currently 16 bytes on 64-bit due to the pointer (and alignment), but only 8 bytes on 32-bit. Keeping the few places that needed this validation is unlikely to be a larger win than the policy size increase due to the larger type. johannes