From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1752151AbdK0VUY (ORCPT ); Mon, 27 Nov 2017 16:20:24 -0500 Received: from merlin.infradead.org ([205.233.59.134]:38838 "EHLO merlin.infradead.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1751670AbdK0VUX (ORCPT ); Mon, 27 Nov 2017 16:20:23 -0500 Date: Mon, 27 Nov 2017 22:20:03 +0100 From: Peter Zijlstra To: Jiri Olsa Cc: Jiri Olsa , Ingo Molnar , Arnaldo Carvalho de Melo , lkml , Namhyung Kim , David Ahern , Andi Kleen , Milind Chabbi , Alexander Shishkin , Michael Ellerman , Hari Bathini , Jin Yao , Kan Liang , Sukadev Bhattiprolu , Oleg Nesterov , Will Deacon Subject: Re: [PATCH 4/6] hw_breakpoint: Factor out __modify_user_hw_breakpoint function Message-ID: <20171127212003.aauonfkbl45pd7dj@hirez.programming.kicks-ass.net> References: <20171127162133.21163-1-jolsa@kernel.org> <20171127162133.21163-5-jolsa@kernel.org> <20171127164639.3ymnc6io3eae7n4c@hirez.programming.kicks-ass.net> <20171127170911.GA22026@krava> <20171127171203.tmdvcsnsownieijv@hirez.programming.kicks-ass.net> <20171127172532.GA23094@krava> <20171127173417.eokpkznt65yreoav@hirez.programming.kicks-ass.net> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <20171127173417.eokpkznt65yreoav@hirez.programming.kicks-ass.net> User-Agent: NeoMutt/20170609 (1.8.3) Sender: linux-kernel-owner@vger.kernel.org List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Mon, Nov 27, 2017 at 06:34:17PM +0100, Peter Zijlstra wrote: > On Mon, Nov 27, 2017 at 06:25:32PM +0100, Jiri Olsa wrote: > > On Mon, Nov 27, 2017 at 06:12:03PM +0100, Peter Zijlstra wrote: > > > But what validates the input attr is the same as the event attr, aside > > > from those fields? > > > > we don't.. the attr serves as a holder to carry those fields > > into the function > > Then that's a straight up bug. > > > the current kernel interface does not check anything else > > Not enough, if the new attr would fail perf_event_open() it should also > fail this modify thing. On IRC you asked: peterz, I dont follow.. why should we check fields that we dont use? Suppose someone does: attr = malloc(sizeof(*attr)); // uninitialized memory attr->type = BP; attr->bp_addr = new_addr; attr->bp_type = bp_type; attr->bp_len = bp_len; ioctl(fd, PERF_IOC_MOD_ATTR, &attr); And feeds absolute shite for the rest of the fields. Then we later want to extend IOC_MOD_ATTR to allow changing attr::sample_type but we can't, because that would break the above application. Therefore we must be very strict to check only the fields we can change have changed.