Received: by 2002:a05:6a10:206:0:0:0:0 with SMTP id 6csp5153070pxj; Wed, 9 Jun 2021 10:18:46 -0700 (PDT) X-Google-Smtp-Source: ABdhPJx7hZ9+IsLzVVB2z+2FiZk0c99nD5VT5PDvJNiX78VbAmgy+A+TlBo3dJYuUKhteWslEqeJ X-Received: by 2002:a50:ce0b:: with SMTP id y11mr515925edi.356.1623259126251; Wed, 09 Jun 2021 10:18:46 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1623259126; cv=none; d=google.com; s=arc-20160816; b=ybsXimMyIKCRu3Bp+wBPMqJipAwhHgsPwYwWYMOR7tqx/bPwBt1AHmc97Yf/0W9+PW kx41CKPaxr1BKiaU33e3vUBUWBS9YqezFNeNKYwnAmj7YR40cppsou2qYqAf4C+Af3TN BWZ3TpVG22oS9wLwtOIuUMGL6DEPd2H4Rp9fQTSUkgPRtBjoc07LncSChaV7QCZJk91J qwoDYILgRVwXKhZEyjB2UdS/d8FUPYn6k78TjZ0hKx3cgcc/fwHGHpTB9xvihORTQ/3V az0ZcKgs4uYLS/Rs9/amDfMtHlJLZUG2jiG7ETj9S4jUC+Giup0Wr24IfZygudzTOWrY DdnA== 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:date:subject:cc:to:from :dkim-signature; bh=8rEuxJKsCrgKYAMD0f1XbwF4Fy6H4vsWs0ouH8e/xgA=; b=iwmiuLWwwS2VcRTFeYt6YhsjQ5NfFePQVsgsH6qxLOGX99SNR2j/QXsr8WtrYR/mcP DIxuUkzLrU5+lB/0+1zdcW7kTwhShXZIDRvoyJEF5Lz1m/k0Pr/Djv5cuIarDJcxbWq1 kXwWpJz9ws6XH6koLaxpWBVy0DIB9vnO7XScD+SA38Xb2EPikuoRBltvAzKENSdSbUOO /S8fpO0zvEK7RhLmvT7jGT1qhNP7HaGMwp7Zlf6ZSyFpXcnEsVbFlnaqxXbtIi/enrWF weCXd3cUbZwEwdUOBCBMnbn0Qv2xUy2kvchmz6qoOIuKC3tJ/tctWNbihVIMc/O4jHrl b4/w== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@gmail.com header.s=20161025 header.b=HkY1kXqu; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=gmail.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id d26si195141edr.567.2021.06.09.10.18.22; Wed, 09 Jun 2021 10:18:46 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) client-ip=23.128.96.18; Authentication-Results: mx.google.com; dkim=pass header.i=@gmail.com header.s=20161025 header.b=HkY1kXqu; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=gmail.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S237277AbhFIKyI (ORCPT + 99 others); Wed, 9 Jun 2021 06:54:08 -0400 Received: from mail-pj1-f52.google.com ([209.85.216.52]:39918 "EHLO mail-pj1-f52.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S238233AbhFIKxw (ORCPT ); Wed, 9 Jun 2021 06:53:52 -0400 Received: by mail-pj1-f52.google.com with SMTP id o17-20020a17090a9f91b029015cef5b3c50so1148378pjp.4; Wed, 09 Jun 2021 03:51:58 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=8rEuxJKsCrgKYAMD0f1XbwF4Fy6H4vsWs0ouH8e/xgA=; b=HkY1kXquqImBORfXGpjC0WNRTiCM2scB9nvKCdzIr8BQOiwvpUdfuVhYVMQBCghN1q SAaNnhhE3U0ukmjR98uS4Gp+Y6ow6SGGqS0MLiGKP+HM0eG437Kf3esm8AeqB2Edybif m7dI2ijBnphAQoHPt1xFK5jxMalJN4SGe9rdD46nUoqLo1eu40gLoDSDkDMS0Br9I9bn buvW7QT2OaLYgFmy9vR2XqgAqVQGBh1pF2MV1DFJDHPrXt5JuGnCXLLV+WsWipUEn3FO 84JXAzNy3VNzTGRXF84JJR0ngBXNsQz6i5A5c35AqFORQNPfyXQdo1tTR+XXsmI2GR5m 9vbQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=8rEuxJKsCrgKYAMD0f1XbwF4Fy6H4vsWs0ouH8e/xgA=; b=Z2XypeJVVbZbsZt0nAjZCCDaxSiFGmaYUuzEiip8XBwIFJDSDv866pIRJBNOzmx5xm ID8DQNR5HYazGgnvEcszqgSG8kh5/b9Yc6U7SPf/4qE/EuT9hP5KCyXd/P6m4bqJqGZn wvkFDrfOaP4LLwYpV70cI6xd5Wq/7HJvtxNphj31FzceaqwxaFvDSyMY9tkcfCbMco8E e+j14EnYblkVKAuBjW42tcpDcWhh//OzYiyCGn/nVtXxGtLCg1YwsSOGi0rkbaSXvRRm K6Ghl2S09VKQzPXZffqWRZVmDU7oaC3q81BdUYRVS+YqUIrbauJw67p93fjq67fKrZ26 NhyA== X-Gm-Message-State: AOAM53315DqRc1ipkcPUxrO699WyhoYG4eIjo8Obi/SI5HKqJxsnB6or /3uUaM19XJWQkBf9StWLq6DmocZecLpSgw== X-Received: by 2002:a17:90b:1d89:: with SMTP id pf9mr9835001pjb.26.1623235858107; Wed, 09 Jun 2021 03:50:58 -0700 (PDT) Received: from localhost (122x211x248x161.ap122.ftth.ucom.ne.jp. [122.211.248.161]) by smtp.gmail.com with ESMTPSA id z185sm14125372pgb.4.2021.06.09.03.50.57 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 09 Jun 2021 03:50:57 -0700 (PDT) From: Punit Agrawal To: mhiramat@kernel.org, naveen.n.rao@linux.ibm.com, anil.s.keshavamurthy@intel.com, davem@davemloft.net Cc: Punit Agrawal , linux-kernel@vger.kernel.org, guoren@kernel.org, linux-csky@vger.kernel.org Subject: [RFC PATCH 2/5] kprobes: Use helper to parse boolean input from userspace Date: Wed, 9 Jun 2021 19:50:16 +0900 Message-Id: <20210609105019.3626677-3-punitagrawal@gmail.com> X-Mailer: git-send-email 2.30.2 In-Reply-To: <20210609105019.3626677-1-punitagrawal@gmail.com> References: <20210609105019.3626677-1-punitagrawal@gmail.com> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org The "enabled" file provides a debugfs interface to arm / disarm kprobes in the kernel. In order to parse the buffer containing the values written from userspace, the callback manually parses the user input to convert it to a boolean value. As taking a string value from userspace and converting it to boolean is a common operation, a helper kstrtobool_from_user() is already available in the kernel. Update the callback to use the common helper to parse the write buffer from userspace. Signed-off-by: Punit Agrawal --- kernel/kprobes.c | 28 ++++++---------------------- 1 file changed, 6 insertions(+), 22 deletions(-) diff --git a/kernel/kprobes.c b/kernel/kprobes.c index fdb1ea2e963b..1a11d3c411bf 100644 --- a/kernel/kprobes.c +++ b/kernel/kprobes.c @@ -2777,30 +2777,14 @@ static ssize_t read_enabled_file_bool(struct file *file, static ssize_t write_enabled_file_bool(struct file *file, const char __user *user_buf, size_t count, loff_t *ppos) { - char buf[32]; - size_t buf_size; - int ret = 0; - - buf_size = min(count, (sizeof(buf)-1)); - if (copy_from_user(buf, user_buf, buf_size)) - return -EFAULT; + bool enable; + int ret; - buf[buf_size] = '\0'; - switch (buf[0]) { - case 'y': - case 'Y': - case '1': - ret = arm_all_kprobes(); - break; - case 'n': - case 'N': - case '0': - ret = disarm_all_kprobes(); - break; - default: - return -EINVAL; - } + ret = kstrtobool_from_user(user_buf, count, &enable); + if (ret) + return ret; + ret = enable ? arm_all_kprobes() : disarm_all_kprobes(); if (ret) return ret; -- 2.30.2