From mboxrd@z Thu Jan 1 00:00:00 1970 From: Johannes Berg Subject: Re: [PATCH] netlink: add policy attribute range validation Date: Wed, 26 Sep 2018 22:24:42 +0200 Message-ID: <1537993482.28767.34.camel@sipsolutions.net> References: <20180926200630.23399-1-johannes@sipsolutions.net> (sfid-20180926_220654_781731_7A389A4D) Mime-Version: 1.0 Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: 7bit To: linux-wireless@vger.kernel.org, netdev@vger.kernel.org Return-path: Received: from s3.sipsolutions.net ([144.76.43.62]:46180 "EHLO sipsolutions.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726453AbeI0Cjg (ORCPT ); Wed, 26 Sep 2018 22:39:36 -0400 In-Reply-To: <20180926200630.23399-1-johannes@sipsolutions.net> (sfid-20180926_220654_781731_7A389A4D) Sender: netdev-owner@vger.kernel.org List-ID: Another thing to note: Given the union of validation_data pointer and min/max, we'll always get into this: > + /* validate range */ > + if (pt->min || pt->max) { if validation_data is set, but of course end up taking the default case, where nothing further happens: > + default: > + /* no further validation */ > + validate = false; > + break; > + } > + > + if (validate && (value < pt->min || value > pt->max)) { > + NL_SET_ERR_MSG_ATTR(extack, nla, > + "integer out of range"); > + return -ERANGE; > + } > + } > + > return 0; I'm not *entirely* happy with this, but I haven't been able to come up with a way that doesn't do this, doesn't duplicate the nla types list (NLA_{U,S}{8,16,32,64}) in the code, and also loads the attribute value only if validation is needed. johannes