Received: by 2002:a05:7412:8521:b0:e2:908c:2ebd with SMTP id t33csp1517rdf; Thu, 2 Nov 2023 12:01:54 -0700 (PDT) X-Google-Smtp-Source: AGHT+IG5Mh0m67aHh+0eHxW9HGysiwrMRcaKAHKZaZIFkIvlIeEnsMPtZ/R/S2D+4JSGQcK7IvUN X-Received: by 2002:a17:907:2087:b0:9c4:b8c9:1bf2 with SMTP id pv7-20020a170907208700b009c4b8c91bf2mr4075313ejb.60.1698951706908; Thu, 02 Nov 2023 12:01:46 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1698951706; cv=none; d=google.com; s=arc-20160816; b=XizwZ/sUgE1XtDvQqyo4Dl2CHrOyaAHFHd+Y5su3dQ7x0LcqkaZkxM23xiOwk40lcZ HvzqPp7UCGwcJ+QSwYU5z9XvyuXm3WkGM+/c4lg/AoDZZDAMRUFdByj6fPmuYoDkNgnl aNJQMvjnqlr5kIzisonh8MG5d4T6WEi70G+ztwxYwfpKt4TQwwkgnN7tHdzF9Cv07ugb 4sKrmyiBoACM8U4ubaIWlL/ewKzABxcP4Ca3GkwzQxRPKh8tm1/lsuOKNxsYK5DdW1ly vUfv+dEjbjDZXSeZXUrpR6UAwg1SZ1o4d+N20+kt+ZS6q3Hes9AEa6f0+PbBCCcpocAL gYbQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:cc:to:from:subject:message-id:references :mime-version:in-reply-to:date:dkim-signature; bh=Q+nc9zCe0F3smKTRXfJvQjpnEMs/1g7BVYJ89L/nFoU=; fh=cN2bmBXDRAWX5wJ872Ibj2Bs5H0l15+iIrkHtCmQ7Ak=; b=YnqM2XkTVMgcXp9pA6hhN27NSlLFMRDgy6W5n60rxL8KoIOhHD3GkN0fpt8fXmjr8u F7VMWMEtkBR/aWEQJGhd3wg+w+dSgetPi2CnjHcWRcjVhpTnvp7dY2nACPv1XW0M9s5d ewmh8NJOMOtBOYKS0NMhWPmOTqnveRhnmVJZaLPo1YraMHFRq2rKQXzMJuRwuc0ID/wt QtbVJBJtvwpi+NVzLb0V6JdiGZN4PaGbpOI2bWxKMqJH0pWESQhwnaZ+Z4mVINbNbTlG gepuVzpG2twuriKay6sU876eecDvDpCwSws3/8JREZ2FVzzFDMgSnmVqKjUUijUBkHEg PKsQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@google.com header.s=20230601 header.b=0kbwSHA0; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.33 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=REJECT sp=REJECT dis=NONE) header.from=google.com Return-Path: Received: from lipwig.vger.email (lipwig.vger.email. [23.128.96.33]) by mx.google.com with ESMTPS id qb16-20020a1709077e9000b009b3eb00c658si49361ejc.59.2023.11.02.12.01.38 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 02 Nov 2023 12:01:46 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.33 as permitted sender) client-ip=23.128.96.33; Authentication-Results: mx.google.com; dkim=pass header.i=@google.com header.s=20230601 header.b=0kbwSHA0; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.33 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=REJECT sp=REJECT dis=NONE) header.from=google.com Received: from out1.vger.email (depot.vger.email [IPv6:2620:137:e000::3:0]) by lipwig.vger.email (Postfix) with ESMTP id AAB6D80EB846; Thu, 2 Nov 2023 12:01:26 -0700 (PDT) X-Virus-Status: Clean X-Virus-Scanned: clamav-milter 0.103.10 at lipwig.vger.email Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1377382AbjKBTAt (ORCPT + 99 others); Thu, 2 Nov 2023 15:00:49 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:34862 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1377315AbjKBTAl (ORCPT ); Thu, 2 Nov 2023 15:00:41 -0400 Received: from mail-pg1-x549.google.com (mail-pg1-x549.google.com [IPv6:2607:f8b0:4864:20::549]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id BD231186 for ; Thu, 2 Nov 2023 12:00:38 -0700 (PDT) Received: by mail-pg1-x549.google.com with SMTP id 41be03b00d2f7-5b9a1494e65so954548a12.2 for ; Thu, 02 Nov 2023 12:00:38 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20230601; t=1698951638; x=1699556438; darn=vger.kernel.org; h=cc:to:from:subject:message-id:references:mime-version:in-reply-to :date:from:to:cc:subject:date:message-id:reply-to; bh=Q+nc9zCe0F3smKTRXfJvQjpnEMs/1g7BVYJ89L/nFoU=; b=0kbwSHA0om1a8qCaJjkGhTMng+QGCErUehmbNaeutCwchAWBW9/dl1WToHmmopUX3o PnDa1plyLwS5/qZSQoce3lbkVITkMNMacJ6AQLVmG9nJzyhhwqhO+yiHnh0MJiyo3Bi6 X4lmA753VcAaYVv/3Uq7NwT9xqL6MaOKtuvLIZbUveg7nn2WxNvWxhvQAQoP6ZAya2A4 hM71dJPUW0O3JzT0zZ/7lw1JB5gwYKdAkV+kEJFD2H4KrD+YI11NC3ZAKmVCa6n7193V y/tH/Yvd4Ncz5A1pEMLXZPHvSsAtz12V/RznmU1cciPLo0ZYibjUunH+sqoLWZzjM5iL QdvA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1698951638; x=1699556438; h=cc:to:from:subject:message-id:references:mime-version:in-reply-to :date:x-gm-message-state:from:to:cc:subject:date:message-id:reply-to; bh=Q+nc9zCe0F3smKTRXfJvQjpnEMs/1g7BVYJ89L/nFoU=; b=jI2W0+kcD73GU21f3Q++UEMPpX7IOe1vmdi89whjMl7ViY7HMw2KJqTPdJ0lho/vd+ XntyhHU6rCO8Am3FdqrPGjNCPspf1zmR1vFRTuzO2zEulhRbXEtF0GpDQKIXAel/SsF7 EROaV6we9dMps0PqMCJIn1gVvEENqCeXQldKnVcQGdW0iy1+nZ0sI7yRp1fLkjVJ6jiJ djiF4ppGbgc5kBKJeM4JWyrGAYAyZWhIeBzjYX1cIaz76SGe/btKSUlOI1GBMhvD2RH5 WbBia1r233Y4PIwH4WMkJ7uXpMQz8ASGNqBTophzlz/+hCnUncxfCBH0xVCLYgx42Aat qZDg== X-Gm-Message-State: AOJu0Yy/8Q+OMAtTu4XLRtE+Tr10F6q55eZASilXhDzI8B+WXWI9JLU+ MrXuK2cocpfITjhThO0w4TMp5CO5geMt/A== X-Received: from xllamas.c.googlers.com ([fda3:e722:ac3:cc00:7f:e700:c0a8:5070]) (user=cmllamas job=sendgmr) by 2002:a17:902:efc9:b0:1cc:20dd:8811 with SMTP id ja9-20020a170902efc900b001cc20dd8811mr317499plb.5.1698951638156; Thu, 02 Nov 2023 12:00:38 -0700 (PDT) Date: Thu, 2 Nov 2023 18:59:05 +0000 In-Reply-To: <20231102185934.773885-1-cmllamas@google.com> Mime-Version: 1.0 References: <20231102185934.773885-1-cmllamas@google.com> X-Mailer: git-send-email 2.42.0.869.gea05f2083d-goog Message-ID: <20231102185934.773885-5-cmllamas@google.com> Subject: [PATCH 04/21] binder: fix async space check for 0-sized buffers From: Carlos Llamas To: Greg Kroah-Hartman , "=?UTF-8?q?Arve=20Hj=C3=B8nnev=C3=A5g?=" , Todd Kjos , Martijn Coenen , Joel Fernandes , Christian Brauner , Carlos Llamas , Suren Baghdasaryan , Sherry Yang Cc: linux-kernel@vger.kernel.org, kernel-team@android.com Content-Type: text/plain; charset="UTF-8" X-Spam-Status: No, score=-8.4 required=5.0 tests=DKIMWL_WL_MED,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,HEADER_FROM_DIFFERENT_DOMAINS, MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS,T_SCC_BODY_TEXT_LINE, USER_IN_DEF_DKIM_WL autolearn=unavailable autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lipwig.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 (lipwig.vger.email [0.0.0.0]); Thu, 02 Nov 2023 12:01:26 -0700 (PDT) Move the padding of 0-sized buffers to an earlier stage to account for this round up during the alloc->free_async_space check. Fixes: 74310e06be4d ("android: binder: Move buffer out of area shared with user space") Signed-off-by: Carlos Llamas --- drivers/android/binder_alloc.c | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/drivers/android/binder_alloc.c b/drivers/android/binder_alloc.c index 046c3ae9eb8f..9b28d0f9666d 100644 --- a/drivers/android/binder_alloc.c +++ b/drivers/android/binder_alloc.c @@ -407,6 +407,10 @@ static struct binder_buffer *binder_alloc_new_buf_locked( alloc->pid, extra_buffers_size); return ERR_PTR(-EINVAL); } + + /* Pad 0-size buffers so they get assigned unique addresses */ + size = max(size, sizeof(void *)); + if (is_async && alloc->free_async_space < size + sizeof(struct binder_buffer)) { binder_alloc_debug(BINDER_DEBUG_BUFFER_ALLOC, @@ -415,9 +419,6 @@ static struct binder_buffer *binder_alloc_new_buf_locked( return ERR_PTR(-ENOSPC); } - /* Pad 0-size buffers so they get assigned unique addresses */ - size = max(size, sizeof(void *)); - while (n) { buffer = rb_entry(n, struct binder_buffer, rb_node); BUG_ON(!buffer->free); -- 2.42.0.869.gea05f2083d-goog