Received: from mail-yw1-f182.google.com (mail-yw1-f182.google.com [209.85.128.182]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 1CA2B3DD51B for ; Wed, 24 Jun 2026 17:44:55 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.128.182 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1782323097; cv=none; b=cqTB47Mf+x77Wk5Jnxo9dt5BHO7uFFr+GOHs3lgDj/giN13C7e/ss+P0DioFm6A33uMbu4s5EqN6VNu5Ha4dzgXAIqFG1c+r7SWpAoeeLJ3hUpJ4NebXeo+HwGwIOdqZOkQxmsnmyI7DNLmkQiW6q1IT4aNTJfzZNVktpPirlN0= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1782323097; c=relaxed/simple; bh=Dgt7deH7Bjy85P0w1kCtTG+pu+9PBuXg2ium+G7Z+i0=; h=From:To:Cc:Subject:Date:Message-ID:MIME-Version; b=LE2hERPjB8Ep+bSl7dmDk+shGAKjcvUXu566TConfx21Y9X4eWadUeTCgJfc7ZBI4wbwvNlkFDLiUuY8H6irUWvV3wvVzeS1hdhdkysRTxH0TkviPGWm9GfGevgqw9DiUgD3ypQUQJKYtI46CiAPcdY6iOxLMfSPvI6CZFCfuF8= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com; spf=pass smtp.mailfrom=gmail.com; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b=Nb4K40yZ; arc=none smtp.client-ip=209.85.128.182 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=gmail.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b="Nb4K40yZ" Received: by mail-yw1-f182.google.com with SMTP id 00721157ae682-80a1fb0c683so1005347b3.1 for ; Wed, 24 Jun 2026 10:44:55 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20251104; t=1782323095; x=1782927895; darn=vger.kernel.org; h=content-transfer-encoding:mime-version:message-id:date:subject:cc :to:from:from:to:cc:subject:date:message-id:reply-to; bh=Hvdk8auvGr6gBDxJclEr8sSbwpLlIJ8Bx4YIOUeaALw=; b=Nb4K40yZMWcsC9PJtqCq6eDrqvmEqqTbgXBmzIk6XxVhoK0dXYRAH3YkP5bnZWItkG fwkoaAgJI3myxsVm82pKCX5lP9G1W2fRt+R7pP5y9+WcDQQwF36xryicbiOmf0TtS3JP mcSaETfELyU4sh3WoFOZpQxYKEXp7OAQ4ECs9VtBL+E1+Kk1iLL8Z6+Duce3z4p3e5ym +sB4+aeLYuxawVg/IsGVlIYmteSYKJ8a4vLTukooHNkvnDiJ6lrzNyolktWrWlJEXhWq D9VeOA1JvrePPvMJ+TRE2SL+LGpjpMCdR6bEPHmPIoWRK9eHC0ddhOU/NTKW/VA8lJ4x H+6Q== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20251104; t=1782323095; x=1782927895; h=content-transfer-encoding:mime-version:message-id:date:subject:cc :to:from:x-gm-gg:x-gm-message-state:from:to:cc:subject:date :message-id:reply-to; bh=Hvdk8auvGr6gBDxJclEr8sSbwpLlIJ8Bx4YIOUeaALw=; b=EnnXOhTEiy7U2sAA2NnDF3YvvxMSOTvmeuljYa7VRYTGFQQL1OTvfKHgLluk9acH7x Aj1iAieG1QQpoSdX7amuRZO+MmcQ61teAMluDv8NjIUlVbXfHblJc/RyLgzK5zdBEqpo mHSheh1upNzMx4gs4WvV7w691uJHWphZ+bckhKLjERkqh/umjtoBZDRDS7gRNfCaqPDV 3nDFiH+wHiCNxpjLYIUMbdt3IESKjp9iPBMAMZcIriKUhRWe5mkjEio848zPt393VTpD Fr3WCt8DuwccBVzAYzGyp0382Oy+xGOPdv+DDkoxtlbs2BqST5c8FwWAhtBGFCp4ESMG iKdg== X-Forwarded-Encrypted: i=1; AHgh+RrwCWdd3u/M+fzV1N7lBQC9vQmyqUqcbXFYjWiOMy650WGZh1/+awHd4XkvWobgMaeilX2PTyO9CHvjZrcW@vger.kernel.org X-Gm-Message-State: AOJu0Yx6RrqkAMhLpBp7wCN317cotGRMSJSS31ea7lI5k+zBa4HCQelr afv3fnYMt39zWKjy2gz2ICBjUyul3KRUnJ3zWu5BOAEkMuXuEnbu2M0z X-Gm-Gg: AfdE7cnkoLqpottzoNd/AnUWubmIsgwAnXqVSdUO3mVgc5f0Ni9yIzyuOUq5rTC6uMa 62yt9tE3fYUo9JtvcIbmZIJbNRzMAP4ooKeJHrtX38Ay3wLS3j5EWOFX7Te4EcDnhVwMewEkwne CgHRETQZwW2tAWCW9OZwzsNx2kHUh6pxzqsLj+hFcFZEehFKVSJl8+jIIt+US0evDdFiAFqrZ1t WqzJUb4XbAwBZV4PPi7/3YrIWJQEgcbyk+XHraylUIfKB6xniO5beoVA6O6Ivy6fa7ScsoZ9IX/ w3Er8EgJosFCpqVY6UfnGZ4Jzg3zWbZTcyPYBQ/J3ENnA03vJ7oQdxqpdL8F/Pxg9ViXX80lt7e eaelvRp7n3Kn/qihW5z/aMJ64raF3vTZnioctoGJYpOcif0YyL2IwgRTj4AESlVtHxwCQEJuQyA ueaAA6lWoKA/srmwh38Z6EYHXL1A== X-Received: by 2002:a05:690c:6e0e:b0:7bd:7b2e:f079 with SMTP id 00721157ae682-80266c36fcbmr218316607b3.44.1782323095111; Wed, 24 Jun 2026 10:44:55 -0700 (PDT) Received: from Dev-Null-MSI ([2a0d:3344:52ac:a808:98a4:4381:be45:536f]) by smtp.gmail.com with ESMTPSA id 00721157ae682-80984a02906sm7053847b3.49.2026.06.24.10.44.52 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 24 Jun 2026 10:44:54 -0700 (PDT) From: Yousef Alhouseen To: Srinivas Kandagatla , Amol Maheshwari Cc: Arnd Bergmann , Greg Kroah-Hartman , linux-arm-msm@vger.kernel.org, dri-devel@lists.freedesktop.org, linux-kernel@vger.kernel.org, Yousef Alhouseen Subject: [PATCH] misc: fastrpc: reject overflowing invoke buffer ranges Date: Wed, 24 Jun 2026 19:44:10 +0200 Message-ID: <20260624174410.6074-1-alhouseenyousef@gmail.com> X-Mailer: git-send-email 2.54.0 Precedence: bulk X-Mailing-List: linux-arm-msm@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: 8bit fastrpc_get_buff_overlaps() builds end addresses from user ranges. A wrapped end can understate the payload size. It can also feed bad ranges into the invoke metadata. Reject invoke buffers whose pointer plus length overflows. Signed-off-by: Yousef Alhouseen --- drivers/misc/fastrpc.c | 18 +++++++++++++++--- 1 file changed, 15 insertions(+), 3 deletions(-) diff --git a/drivers/misc/fastrpc.c b/drivers/misc/fastrpc.c index f3a493845..ba4ade874 100644 --- a/drivers/misc/fastrpc.c +++ b/drivers/misc/fastrpc.c @@ -13,6 +13,7 @@ #include #include #include +#include #include #include #include @@ -607,14 +608,17 @@ static int olaps_cmp(const void *a, const void *b) return st == 0 ? ed : st; } -static void fastrpc_get_buff_overlaps(struct fastrpc_invoke_ctx *ctx) +static int fastrpc_get_buff_overlaps(struct fastrpc_invoke_ctx *ctx) { u64 max_end = 0; int i; for (i = 0; i < ctx->nbufs; ++i) { ctx->olaps[i].start = ctx->args[i].ptr; - ctx->olaps[i].end = ctx->olaps[i].start + ctx->args[i].length; + if (check_add_overflow(ctx->olaps[i].start, + ctx->args[i].length, + &ctx->olaps[i].end)) + return -EOVERFLOW; ctx->olaps[i].raix = i; } @@ -641,6 +645,8 @@ static void fastrpc_get_buff_overlaps(struct fastrpc_invoke_ctx *ctx) max_end = ctx->olaps[i].end; } } + + return 0; } static struct fastrpc_invoke_ctx *fastrpc_context_alloc( @@ -675,7 +681,13 @@ static struct fastrpc_invoke_ctx *fastrpc_context_alloc( return ERR_PTR(-ENOMEM); } ctx->args = args; - fastrpc_get_buff_overlaps(ctx); + ret = fastrpc_get_buff_overlaps(ctx); + if (ret) { + kfree(ctx->olaps); + kfree(ctx->maps); + kfree(ctx); + return ERR_PTR(ret); + } } /* Released in fastrpc_context_put() */ -- 2.54.0