Received: by 2002:ab2:6203:0:b0:1f5:f2ab:c469 with SMTP id o3csp2122745lqt; Mon, 22 Apr 2024 02:00:09 -0700 (PDT) X-Forwarded-Encrypted: i=3; AJvYcCWJhk2K/+lMr8A5fQbinzaNuTdh58gDWZXWqNlG7JMpUKK2F7wLVjXmXZsAGnSyq/QUeTJwVsidf6Z26u7BKZvjJxYjksanY/MzJzdWTA== X-Google-Smtp-Source: AGHT+IEGAniDfzmX3G7d4jiGu8uI71DQXwqYPlCLfl9Oa7PxNokY6EEBUS9nhjAzB7rUN1i7Yfmh X-Received: by 2002:a17:902:f68b:b0:1e5:9da5:a799 with SMTP id l11-20020a170902f68b00b001e59da5a799mr11022608plg.6.1713776409240; Mon, 22 Apr 2024 02:00:09 -0700 (PDT) ARC-Seal: i=2; a=rsa-sha256; t=1713776409; cv=pass; d=google.com; s=arc-20160816; b=ZLemLlsTGZq7MQuuK47CVpvhmg83LeGnVpyUq9+1kIkt6QCojFe1Y3P0PYPptQVqzm 89S2mkq0oC+m2vTWgTNbpibNPFUqjBTjvHhy7Sey6I6PIdqosCLwi1Yo5cBwEogmHHLa YJ0KTVQuTdir7ZXjdzJx6BYpgVuVhEchtCjqxMuXHlYPbw5MsYZM0uID3ie//nZ7HtFD 8AXcarhl2FdoWVoKzOGyA2383F5h3ESdHN0gSIVQxgDd0cCGdg9KGp5LV1Q/NcPUrtxd Dq2bFP8rhz0KOGS7r1juCL7XY0LRY73H3P8zGcm1IbrRL6epkVKNvTsLDP/Wr6LbBGbs ysuw== ARC-Message-Signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=content-transfer-encoding:cc:to:subject:message-id:date:from :in-reply-to:references:mime-version:list-unsubscribe:list-subscribe :list-id:precedence:dkim-signature; bh=lN1tQRzEerHdmzjmn4cRyuYt4HVRT1txxhBtvZ2kMiw=; fh=HGhra0aTzZB2ND+Vipwid1j6UHvVUGhhVvwbeHnfYZg=; b=JHwi8zNKzsxoyNdJuR8BSfK0KQyas62dUlwx+ySiGsqVJrcsII0Y3p4OGzOAYuY6po wT4BSZQd3j5hH6aXgaYo2aXGXGVZchOi+igIcMxGHnIqRpoLJpak57ApDKXsO4TwMAoO NjidbrxtCPspR3YZE9Wk6gLbb9hQC8UWuu6T6Na9WNW1Z7GGOozxnTZ3SJrspXZbMfSK IFaDT8tHvAM0zyDOFqoFJLRyG4odUiGRgTC3lnJVi1oeadDQOltypSIxSKViRBJncdL4 Nc5VEMPA55v2MglUCXIGDBz+LNDc8R2jWw6RPgLnSgmFEy7bQjTBW3pLIOqdsIRpdrwX +VCw==; dara=google.com ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@google.com header.s=20230601 header.b=wWCDV8Jc; arc=pass (i=1 spf=pass spfdomain=google.com dkim=pass dkdomain=google.com dmarc=pass fromdomain=google.com); spf=pass (google.com: domain of linux-kernel+bounces-153033-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:40f1:3f00::1 as permitted sender) smtp.mailfrom="linux-kernel+bounces-153033-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=pass (p=REJECT sp=REJECT dis=NONE) header.from=google.com Return-Path: Received: from sy.mirrors.kernel.org (sy.mirrors.kernel.org. [2604:1380:40f1:3f00::1]) by mx.google.com with ESMTPS id n10-20020a170902f60a00b001e47f894beesi7829424plg.251.2024.04.22.02.00.08 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 22 Apr 2024 02:00:09 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel+bounces-153033-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:40f1:3f00::1 as permitted sender) client-ip=2604:1380:40f1:3f00::1; Authentication-Results: mx.google.com; dkim=pass header.i=@google.com header.s=20230601 header.b=wWCDV8Jc; arc=pass (i=1 spf=pass spfdomain=google.com dkim=pass dkdomain=google.com dmarc=pass fromdomain=google.com); spf=pass (google.com: domain of linux-kernel+bounces-153033-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:40f1:3f00::1 as permitted sender) smtp.mailfrom="linux-kernel+bounces-153033-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=pass (p=REJECT sp=REJECT dis=NONE) header.from=google.com Received: from smtp.subspace.kernel.org (wormhole.subspace.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by sy.mirrors.kernel.org (Postfix) with ESMTPS id 0C284B21784 for ; Mon, 22 Apr 2024 08:56:17 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 3D08954BE7; Mon, 22 Apr 2024 08:53:12 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=google.com header.i=@google.com header.b="wWCDV8Jc" Received: from mail-yb1-f181.google.com (mail-yb1-f181.google.com [209.85.219.181]) (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 E115453380 for ; Mon, 22 Apr 2024 08:53:09 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.219.181 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1713775991; cv=none; b=Su1jt8+cHUsxqqAVvKBKf1XZ7WEnWbPcgO955tdxwRySAZDqfkHnlZZ57w/ZcWZrM/D7nvYhKjZy1PgSx6Emo+N6EZxNyrfDxawxm+Gj/opRbrJn+SU5OZdXXm/hP6Nby5pBf7LOuL+garMvUoOxdxnrLX0G58pBEno4KLaVKx0= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1713775991; c=relaxed/simple; bh=tc1YFCLIzw0cQqXheGK0vA+hR2mqFn4ZzGTZtzlGTrA=; h=MIME-Version:References:In-Reply-To:From:Date:Message-ID:Subject: To:Cc:Content-Type; b=IrN1MDDkVp5hmg45YYWIEbCABEXm2Yg7lZS2Jd8E9RZMQbSTdeRjkfs0wDRDn7Bu5xsEbIxcUXtVZNxR9eC/SJ3CDe4zroOu6gVEJx7azJ07naEWtFLZnUYLgtjRnMjv1EjIjGLsAL+BWex/rxFsvEyHcO/xOoSr85QLk6opvHU= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=google.com; spf=pass smtp.mailfrom=google.com; dkim=pass (2048-bit key) header.d=google.com header.i=@google.com header.b=wWCDV8Jc; arc=none smtp.client-ip=209.85.219.181 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=google.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=google.com Received: by mail-yb1-f181.google.com with SMTP id 3f1490d57ef6-de45e596a05so4484386276.1 for ; Mon, 22 Apr 2024 01:53:09 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20230601; t=1713775989; x=1714380789; darn=vger.kernel.org; h=content-transfer-encoding:cc:to:subject:message-id:date:from :in-reply-to:references:mime-version:from:to:cc:subject:date :message-id:reply-to; bh=lN1tQRzEerHdmzjmn4cRyuYt4HVRT1txxhBtvZ2kMiw=; b=wWCDV8JcRqRQXy58ydxUZI5DGVuxK2hrwAh0UYWX9rNOTiEHR/MtDupsJEhNs7lwMt v/CUUWqcB3E24L7sj/d+tnuQWmAw67Wi8HzMtnuussxaScpcrg0er041ylHzkrNW6RcM VCcw/tJwrWncslc1r380a+1280uhDCoo0i1g9NiOqy69qkbxRckGLJCqskt2S8mwYJy3 CW+gVVkrprtJcHYEzHqk2e41EIxBTfBnlnLT8KSLM2ZbnF9fYH1d12lA057GgicIL2lS c6P3cLOs8GxuF0SFMRMIFelzw/wJnneeb2Dms1pUiZwJxyOYWs5VtvqGt8xn/f7I6uoI P8Xg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1713775989; x=1714380789; h=content-transfer-encoding:cc:to:subject:message-id:date:from :in-reply-to:references:mime-version:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=lN1tQRzEerHdmzjmn4cRyuYt4HVRT1txxhBtvZ2kMiw=; b=plNjc/P4+Wg/0XgycX/StgUU6RBwSfxBlj9XBKY2qfgoImXM4FKaPg6WQgrOz+lsCG s75vlKZInEzcTn2LYiGpvw0IpqDKD9yBVdZeW3CmLHILHszT5+JjsnbPA5ebX3RUGil8 FMQJETaZLywAvj6MTm+otKI9Ea2muqYkBtoR9DbmNYHbG+JSTKPafIliMYlgxphJnjxY eMfD436RBzhI7MHokshwHfpaKinJ5lGIEC5TL7I0pqyIBPbJ4+ioS60AirNDrvNMAl7d 8qRSxoLMIOR96mn/LQmcx0/Z6533odnIAlqz5GjMQ3s9LszNJSFJNdyluNviaoQiCrM8 NHiw== X-Forwarded-Encrypted: i=1; AJvYcCV3RHcod5LkGsoAE/IBfZ8AnXLcPIr/7GP/sWcCMZEEUIt0ShdYM9zpIUMPsJsc3PeLOVmN9E7LmzdgP4mfeUoqylB1RGgzBexSiO69 X-Gm-Message-State: AOJu0YypJwHCJ+0xBJCTAVkywYa3YiHXPpNura7emeRtHEXVucvlKqV1 Uq/yUv2xDVQka7431hsGS5oCTCMR589IqZnKT542iQDofSs+sP8Fb+sTMbPbodYH8KuGRmrmcJd x3/gbaaXTw06ss1xXdSfAQyUHHgCdUdQMJMZJ X-Received: by 2002:a25:c789:0:b0:dc7:32ea:c89f with SMTP id w131-20020a25c789000000b00dc732eac89fmr8266839ybe.15.1713775988625; Mon, 22 Apr 2024 01:53:08 -0700 (PDT) Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 References: <20240417191418.1341988-3-cmllamas@google.com> <20240418081222.3871629-1-aliceryhl@google.com> In-Reply-To: From: Alice Ryhl Date: Mon, 22 Apr 2024 10:52:57 +0200 Message-ID: Subject: Re: [PATCH 2/4] binder: migrate ioctl to new PF_SPAM_DETECTION To: Carlos Llamas Cc: arve@android.com, brauner@kernel.org, gregkh@linuxfoundation.org, joel@joelfernandes.org, kernel-team@android.com, linux-kernel@vger.kernel.org, maco@android.com, surenb@google.com, tkjos@android.com Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: quoted-printable On Sun, Apr 21, 2024 at 1:49=E2=80=AFAM Carlos Llamas = wrote: > > On Thu, Apr 18, 2024 at 08:12:22AM +0000, Alice Ryhl wrote: > > Carlos Llamas writes: > > > @@ -5553,7 +5553,8 @@ static long binder_ioctl(struct file *filp, uns= igned int cmd, unsigned long arg) > > > goto err; > > > } > > > binder_inner_proc_lock(proc); > > > - proc->oneway_spam_detection_enabled =3D (bool)enable; > > > + proc->flags &=3D ~PF_SPAM_DETECTION; > > > + proc->flags |=3D enable & PF_SPAM_DETECTION; > > > > The bitwise and in `enable & PF_SPAM_DETECTION` only works because > > PF_SPAM_DETECTION happens to be equal to 1. This seems pretty fragile t= o > > me. Would you be willing to do this instead? > > > > proc->flags &=3D ~PF_SPAM_DETECTION; > > if (enable) > > proc->flags |=3D PF_SPAM_DETECTION; > > > > I don't think it is fragile since PF_SPAM_DETECTION is fixed. However, > I agree the code is missing context about the flag being bit 0 and your > version addresses this problem. So I'll take it for v2, thanks! Thanks! By fragile I mean that it could result in future mistakes, e.g. somebody could copy this code and use it elsewhere with a different bit flag that might not be bit 0. > > Carlos Llamas writes: > > > - if (proc->oneway_spam_detection_enabled && > > > - w->type =3D=3D BINDER_WORK_TRANSACTION= _ONEWAY_SPAM_SUSPECT) > > > + if (proc->flags & PF_SPAM_DETECTION && > > > + w->type =3D=3D BINDER_WORK_TRANSACTION_ONEWAY= _SPAM_SUSPECT) > > > > Maybe I am just not sufficiently familiar with C, but I had to look up > > the operator precedence rules for this one. Could we add parenthesises > > around `proc->flags & PF_SPAM_DETECTION`? Or even define a macro for it= ? > > I think this is fairly common in C but I can definitly add the extra > paranthesis if it helps. Yeah, makes sense. Thanks! With the mentioned changes, you may add: Reviewed-by: Alice Ryhl Alice