lists.openwall.net   lists  /  announce  owl-users  owl-dev  john-users  john-dev  passwdqc-users  yescrypt  popa3d-users  /  oss-security  kernel-hardening  musl  sabotage  tlsify  passwords  /  crypt-dev  xvendor  /  Bugtraq  Full-Disclosure  linux-kernel  linux-netdev  linux-ext4  linux-hardening  linux-cve-announce  PHC 
Open Source and information security mailing list archives
 
Hash Suite for Android: free password hash cracker in your pocket
[<prev] [next>] [<thread-prev] [thread-next>] [day] [month] [year] [list]
Message-ID: <d48e65cc-3c7b-4a93-80a2-fa0d676e88c4@arm.com>
Date: Fri, 18 Oct 2024 18:07:19 +0100
From: James Morse <james.morse@....com>
To: Tony Luck <tony.luck@...el.com>
Cc: x86@...nel.org, linux-kernel@...r.kernel.org,
 Fenghua Yu <fenghua.yu@...el.com>,
 Reinette Chatre <reinette.chatre@...el.com>,
 Thomas Gleixner <tglx@...utronix.de>, Ingo Molnar <mingo@...hat.com>,
 Borislav Petkov <bp@...en8.de>, H Peter Anvin <hpa@...or.com>,
 Babu Moger <Babu.Moger@....com>, shameerali.kolothum.thodi@...wei.com,
 D Scott Phillips OS <scott@...amperecomputing.com>,
 carl@...amperecomputing.com, lcherian@...vell.com,
 bobo.shaobowang@...wei.com, tan.shaopeng@...itsu.com,
 baolin.wang@...ux.alibaba.com, Jamie Iles <quic_jiles@...cinc.com>,
 Xin Hao <xhao@...ux.alibaba.com>, peternewman@...gle.com,
 dfustini@...libre.com, amitsinght@...vell.com,
 David Hildenbrand <david@...hat.com>, Rex Nie <rex.nie@...uarmicro.com>,
 Dave Martin <dave.martin@....com>, Shaopeng Tan <tan.shaopeng@...fujitsu.com>
Subject: Re: [PATCH v5 04/40] x86/resctrl: Use schema type to determine how to
 parse schema values

Hi Tony,

On 16/10/2024 00:15, Tony Luck wrote:
> On Fri, Oct 04, 2024 at 06:03:11PM +0000, James Morse wrote:
>> +static ctrlval_parser_t *get_parser(struct rdt_resource *r)
>> +{
>> +	switch (r->schema_fmt) {
>> +	case RESCTRL_SCHEMA_BITMAP:
>> +		return &parse_cbm;
>> +	case RESCTRL_SCHEMA_RANGE:
>> +		return &parse_bw;
>> +	}
>> +
>> +	return NULL;
>> +}
> 
> Is it really worth making this a helper function? It's only
> used once.

Moved. This was just to avoid bloating the caller with boiler-plate.


>> +
>>  /*
>>   * For each domain in this resource we expect to find a series of:
>>   *	id=mask
>> @@ -204,6 +225,7 @@ int parse_cbm(struct rdt_parse_data *data, struct resctrl_schema *s,
>>  static int parse_line(char *line, struct resctrl_schema *s,
>>  		      struct rdtgroup *rdtgrp)
>>  {
>> +	ctrlval_parser_t *parse_ctrlval = get_parser(s->res);
> 
> No check to see if get_parser() returned NULL.

No - but you must have passed it a non-existant enum value for that to happen, so we're
already in memory corruption territory. (I probably should have made get_parser()
WARN_ON_ONCE() when returning NULL)


>>  	enum resctrl_conf_type t = s->conf_type;
>>  	struct resctrl_staged_config *cfg;
>>  	struct rdt_resource *r = s->res;
>> @@ -235,7 +257,7 @@ static int parse_line(char *line, struct resctrl_schema *s,
>>  		if (d->hdr.id == dom_id) {
>>  			data.buf = dom;
>>  			data.rdtgrp = rdtgrp;
>> -			if (r->parse_ctrlval(&data, s, d))
>> +			if (parse_ctrlval(&data, s, d))
>>  				return -EINVAL;
> 
> Without the helper this could be:
> 
> 			switch (r->schema_fmt) {
> 			case RESCTRL_SCHEMA_BITMAP:
> 				if (parse_cbm(&data, s, d))
> 					return -EINVAL;
> 				break;
> 			case RESCTRL_SCHEMA_RANGE:
> 				if (parse_bw(&data, s, d))
> 					return -EINVAL;
> 				break;
> 			default:
> 				WARN_ON_ONCE(1);
> 				return -EINVAL;
> 			}

I'd prefer the switch statement to have no default so that it triggers a compiler warning
when future enum entries are added. This way the compiler can find cases where a new
schema format missed a bit - it doesn't need booting the result on hardware to trigger a
warning.

To avoid 'break' in a loop not breaking out of the loop, and to avoid bloating the loop
I've kept the function pointer so the non-existant enum case is handled with the rest of
the errors at the top of the function:
|        /* Walking r->domains, ensure it can't race with cpuhp */
|        lockdep_assert_cpus_held();
|
|        switch (r->schema_fmt) {
|        case RESCTRL_SCHEMA_BITMAP:
|                parse_ctrlval = &parse_cbm;
|                break;
|        case RESCTRL_SCHEMA_RANGE:
|                parse_ctrlval = &parse_bw;
|                break;
|        }
|
|        if (WARN_ON_ONCE(!parse_ctrlval))
|                return -EINVAL;
|
|        if (rdtgrp->mode == RDT_MODE_PSEUDO_LOCKSETUP &&


Thanks,

James

Powered by blists - more mailing lists

Powered by Openwall GNU/*/Linux Powered by OpenVZ