Received: by 2002:a05:7412:8d10:b0:f3:1519:9f41 with SMTP id bj16csp4726996rdb; Tue, 12 Dec 2023 07:45:44 -0800 (PST) X-Google-Smtp-Source: AGHT+IEL3xIHwMIgiYqvstA9LWa/RVEIt+ZrUEj4rLrQZ4VtHBC0In974SjH19ICfVCb1+HLkETI X-Received: by 2002:a05:6a00:9398:b0:6cd:dece:b73d with SMTP id ka24-20020a056a00939800b006cddeceb73dmr3497369pfb.18.1702395944549; Tue, 12 Dec 2023 07:45:44 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1702395944; cv=none; d=google.com; s=arc-20160816; b=ZgItgWRENnBx6PbI2oV6uEyWclsFQg/WQQNZVZjk0jiSeQGBe6XEiQehQM8FITbdS9 5RqczomMRmaN53pYwPzyRkwwPYyZ0sb1Z6GPh+c8ECEmMlY/VyjOE7wN0IFWFFoQN7hY ve5dLwqG2Qgwjxvtcca/OyvEgiHVO3jipwkJ98Bnxzl3pHmtDQYgYuVjAXNPIkf6pNV7 Kl9/Yq3j4Oo4yHxA9cP/AFYfAafU1NY0IIQG2oLs4ERlClBD7TL2o69NB3B2oB+FYVqP afmYLOT557SUEn4opzCF9Dz+IwvFgWLajHrwnHTJMUDkZrlgZBlX8ri+xmIJJbleb3Dz ivfw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :references:in-reply-to:message-id:subject:cc:to:from:date; bh=XczcdEwOH6c3CrPQlzqwKVfeqNiSHlPfW9ItGgDCU6g=; fh=DXqSFHFMGWs8NWhSKawAW+CcN1HWregSaTKgaWTRpeY=; b=sDebLFoXFf4oS0YdUZvyYJgx2PrfXZ/8MoNHJ8915Jxpc57EKhRneLMfNnA4k6aENe Ed3Y8ONS9zMOigAMyRP1Nwg92/RwsOkHPiTTKuiJBMV53kpjUR+5Bewg5ecjGaJnjhpn MLN1V9r/A0wqq8gt3FI4syUCBeKAqDqvfVNY5OabQeBJ5PbwJl4Pjh7pyhbGms1y7DYg LpQZBczdD/Q2kCaLVdFn8LB67QznJr4AYN8UCTX8VFFbhat8G0S86b9XR6qKnVhpyQZw tgTGKhDmyBYC2e01ansoQjtFauPuSxbuylaT3Z5oWqEMALMobxr8yVYN8b5ucACoWI2j 1xdw== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.38 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Return-Path: Received: from fry.vger.email (fry.vger.email. [23.128.96.38]) by mx.google.com with ESMTPS id by26-20020a056a02059a00b005c6832282f7si8256737pgb.304.2023.12.12.07.45.44 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 12 Dec 2023 07:45:44 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.38 as permitted sender) client-ip=23.128.96.38; Authentication-Results: mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.38 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: from out1.vger.email (depot.vger.email [IPv6:2620:137:e000::3:0]) by fry.vger.email (Postfix) with ESMTP id 643158083DCD; Tue, 12 Dec 2023 07:45:18 -0800 (PST) X-Virus-Status: Clean X-Virus-Scanned: clamav-milter 0.103.11 at fry.vger.email Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1377121AbjLLPpC (ORCPT + 99 others); Tue, 12 Dec 2023 10:45:02 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:35088 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1377023AbjLLPpC (ORCPT ); Tue, 12 Dec 2023 10:45:02 -0500 Received: from smtp.kernel.org (relay.kernel.org [52.25.139.140]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id B7BB499 for ; Tue, 12 Dec 2023 07:45:08 -0800 (PST) Received: by smtp.kernel.org (Postfix) with ESMTPSA id B1E4EC433C8; Tue, 12 Dec 2023 15:45:07 +0000 (UTC) Date: Tue, 12 Dec 2023 10:45:49 -0500 From: Steven Rostedt To: Mathieu Desnoyers Cc: LKML , Linux Trace Kernel , Masami Hiramatsu , Mark Rutland Subject: Re: [PATCH v2] tracing: Allow for max buffer data size trace_marker writes Message-ID: <20231212104549.58863438@gandalf.local.home> In-Reply-To: <445ac00d-0f0c-4f6a-b85a-97209635c3f3@efficios.com> References: <20231212090057.41b28efe@gandalf.local.home> <445ac00d-0f0c-4f6a-b85a-97209635c3f3@efficios.com> X-Mailer: Claws Mail 3.19.1 (GTK+ 2.24.33; x86_64-pc-linux-gnu) MIME-Version: 1.0 Content-Type: text/plain; charset=US-ASCII Content-Transfer-Encoding: 7bit X-Spam-Status: No, score=-0.8 required=5.0 tests=HEADER_FROM_DIFFERENT_DOMAINS, MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS,T_SCC_BODY_TEXT_LINE autolearn=unavailable autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on fry.vger.email Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org X-Greylist: Sender passed SPF test, not delayed by milter-greylist-4.6.4 (fry.vger.email [0.0.0.0]); Tue, 12 Dec 2023 07:45:18 -0800 (PST) On Tue, 12 Dec 2023 09:33:11 -0500 Mathieu Desnoyers wrote: > On 2023-12-12 09:00, Steven Rostedt wrote: > [...] > > --- a/kernel/trace/trace.c > > +++ b/kernel/trace/trace.c > > @@ -7272,6 +7272,7 @@ tracing_mark_write(struct file *filp, const char __user *ubuf, > > enum event_trigger_type tt = ETT_NONE; > > struct trace_buffer *buffer; > > struct print_entry *entry; > > + int meta_size; > > ssize_t written; > > int size; > > int len; > > @@ -7286,12 +7287,9 @@ tracing_mark_write(struct file *filp, const char __user *ubuf, > > if (!(tr->trace_flags & TRACE_ITER_MARKERS)) > > return -EINVAL; > > > > - if (cnt > TRACE_BUF_SIZE) > > - cnt = TRACE_BUF_SIZE; > > You're removing an early bound check for a size_t userspace input... > > > - > > - BUILD_BUG_ON(TRACE_BUF_SIZE >= PAGE_SIZE); > > - > > - size = sizeof(*entry) + cnt + 2; /* add '\0' and possible '\n' */ > > + meta_size = sizeof(*entry) + 2; /* add '\0' and possible '\n' */ > > + again: > > + size = cnt + meta_size; > > ... and then implicitly casting it into a "int" size variable, which > can therefore become a negative value. > > Just for the sake of not having to rely on ring_buffer_lock_reserve > catching (length > BUF_MAX_DATA_SIZE), I would recommend to add an > early check for negative here. size_t is not signed, so nothing should be negative. But you are right, I need to have "size" be of size_t type too to prevent the overflow. And I could make cnt of ssize_t type and check for negative and fail early in such a case. Thanks! > > > > > /* If less than "", then make sure we can still add > > that */ if (cnt < FAULTED_SIZE) > > @@ -7300,9 +7298,25 @@ tracing_mark_write(struct file *filp, const char > > __user *ubuf, buffer = tr->array_buffer.buffer; > > event = __trace_buffer_lock_reserve(buffer, TRACE_PRINT, size, > > tracing_gen_ctx()); > > - if (unlikely(!event)) > > + if (unlikely(!event)) { > > + /* > > + * If the size was greated than what was allowed, then > > > > greater ? Nah, the size is "greated" like "greated cheese" ;-) Thanks for the review, I'll send out a v3. -- Steve