From patchwork Mon Sep 19 17:24:16 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Akinobu Mita X-Patchwork-Id: 12980830 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by smtp.lore.kernel.org (Postfix) with ESMTP id 83F9EECAAD3 for ; Mon, 19 Sep 2022 17:24:56 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id E0743940008; Mon, 19 Sep 2022 13:24:55 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id DB5AD6B0072; Mon, 19 Sep 2022 13:24:55 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id C57C6940008; Mon, 19 Sep 2022 13:24:55 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0015.hostedemail.com [216.40.44.15]) by kanga.kvack.org (Postfix) with ESMTP id B61EE6B0071 for ; Mon, 19 Sep 2022 13:24:55 -0400 (EDT) Received: from smtpin08.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay08.hostedemail.com (Postfix) with ESMTP id 8AC201401A1 for ; Mon, 19 Sep 2022 17:24:55 +0000 (UTC) X-FDA: 79929510150.08.2589A69 Received: from mail-pf1-f174.google.com (mail-pf1-f174.google.com [209.85.210.174]) by imf11.hostedemail.com (Postfix) with ESMTP id 40D7040019 for ; Mon, 19 Sep 2022 17:24:55 +0000 (UTC) Received: by mail-pf1-f174.google.com with SMTP id a80so270096pfa.4 for ; Mon, 19 Sep 2022 10:24:54 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20210112; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date; bh=dm/xj3UCM5GDvqsqEmDruuZjxjQYqmvO/RJqSynJbxs=; b=Gl7e0Yg8ZgFENkMxqlZEodWfUspPOUzXA6vlgpyAT3PfrxXQj5hHyjBXcOEztaOxX4 Cit0Qg+NsaiJdZzLZeDbyx+dco7v0P1bMKAkFi7i5QYrOPC60VSzMUSJ0blRa5Y7I333 BgCxp/EKma8OPzoa0oz/JFpLSbSggbELy21Kzyg8/PabTrvZ2SXGuWb8vpHEbZMSOswd DkmGSS+NjD9cVPrK/i2CnS1/MOoI8DigrnVgC6EFYnR1Yi8MTEsNZN7DqGmH5OibfzW+ EOIO7EPrnROJDtqPZvzmqKnXDdC18pi31j2HFmF499FCJTH/eEspslCg7QWyejU6JmZH gbkw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date; bh=dm/xj3UCM5GDvqsqEmDruuZjxjQYqmvO/RJqSynJbxs=; b=miRkQr4T8ckaxuABYfilOz23fieTe2mx6uuDYP5p7FiM0yvjopoLuNyzUcqc5wzukJ vsgkClRHLgsxcxSyXTVbphxmdDrkQPJt/86QYP5wfBlSAKrOpCBrkZT0/T+DHcYxM+Ii ll/yiweyYuzufzq5N0QfTgKqjTA079cdxUSSCMvHodvIk4/lFBx3hYW1fdPGPzRNC/nn eGCGg1DO8BpHm2rro1nKTavybFE7/5zM+BlwNV4O4JimwSyaaWspiv+NsL6WwITP9M3f hBIwOemvY5nUEZSBYaLInmxLB9Nu1OUdossbEB9bEBWrgR2ZkeHVF6xy9tiVgd0pJfHH akKA== X-Gm-Message-State: ACrzQf1P/+EQeE7ErNXqbOB97mJPUWLjZhrr+9K2oNpgqZLnTYzlhrTY HEyIQGTw0HO3LiKBAr7Ji/I= X-Google-Smtp-Source: AMsMyM77MWJIoSfL+bJOQIrJOo1UxqGAj8MBR0N1o9UjBpDSOUGMPeEtRSXnUeklW0hsy/M0CYwu2A== X-Received: by 2002:a63:c3:0:b0:439:72d7:7e1f with SMTP id 186-20020a6300c3000000b0043972d77e1fmr16248074pga.524.1663608294102; Mon, 19 Sep 2022 10:24:54 -0700 (PDT) Received: from localhost.localdomain (KD027092233113.ppp-bb.dion.ne.jp. [27.92.233.113]) by smtp.gmail.com with ESMTPSA id h7-20020aa796c7000000b0053f2505318asm21226480pfq.142.2022.09.19.10.24.50 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 19 Sep 2022 10:24:53 -0700 (PDT) From: Akinobu Mita To: linux-doc@vger.kernel.org, linux-kernel@vger.kernel.org, linux-mm@kvack.org, linux-kselftest@vger.kernel.org, linux-fsdevel@vger.kernel.org, corbet@lwn.net, david@redhat.com, osalvador@suse.de, shuah@kernel.org, Zhao Gongyi , Wei Yongjun , Yicong Yang , Greg Kroah-Hartman , "Rafael J. Wysocki" , Alexander Viro , akpm@linux-foundation.org Cc: Akinobu Mita Subject: [PATCH 1/3] libfs: add DEFINE_SIMPLE_ATTRIBUTE_SIGNED for signed value Date: Tue, 20 Sep 2022 02:24:16 +0900 Message-Id: <20220919172418.45257-2-akinobu.mita@gmail.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20220919172418.45257-1-akinobu.mita@gmail.com> References: <20220919172418.45257-1-akinobu.mita@gmail.com> MIME-Version: 1.0 ARC-Authentication-Results: i=1; imf11.hostedemail.com; dkim=pass header.d=gmail.com header.s=20210112 header.b=Gl7e0Yg8; spf=pass (imf11.hostedemail.com: domain of akinobu.mita@gmail.com designates 209.85.210.174 as permitted sender) smtp.mailfrom=akinobu.mita@gmail.com; dmarc=pass (policy=none) header.from=gmail.com ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1663608295; a=rsa-sha256; cv=none; b=JRzNsvQb+jSH21f1Qn577nEXW226fBxiK8xnRg/yxaMWQ6pPWJBTZVeurHcceC/0sX0fbs /XqkFrEGEt28QeTm15z4GReheCG2SYcvPm8KZKxQZuKrhqD+M5HcJ9UMB3VoyNcuK6NtWI eA7DDmGAcZRIpbKaOw9AevHaPVV3wHw= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1663608295; h=from:from:sender:reply-to:subject:subject:date:date: message-id:message-id:to:to:cc:cc:mime-version:mime-version: content-type:content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references:dkim-signature; bh=dm/xj3UCM5GDvqsqEmDruuZjxjQYqmvO/RJqSynJbxs=; b=0rPyGCwvqSGnawyUN3+6dsLPGjVhJ/KvV7dEW8mXzEkIAJVerpKM7eXcCTR+dKVdKSS7Jh 8KfwDfF1oy5leAUlx7NPfb/+zd98kaBHothFnZxo6IR+1qPobFiL6wWR38ZR9XFrwYep/m CYhttbZC0mqrFML/RcvKGazHE98xO58= Authentication-Results: imf11.hostedemail.com; dkim=pass header.d=gmail.com header.s=20210112 header.b=Gl7e0Yg8; spf=pass (imf11.hostedemail.com: domain of akinobu.mita@gmail.com designates 209.85.210.174 as permitted sender) smtp.mailfrom=akinobu.mita@gmail.com; dmarc=pass (policy=none) header.from=gmail.com X-Stat-Signature: uypybrj141kih4y1sbhcxikhim4uijhz X-Rspamd-Queue-Id: 40D7040019 X-Rspamd-Server: rspam03 X-Rspam-User: X-HE-Tag: 1663608295-786023 X-Bogosity: Ham, tests=bogofilter, spamicity=0.000000, version=1.2.4 Sender: owner-linux-mm@kvack.org Precedence: bulk X-Loop: owner-majordomo@kvack.org List-ID: The simple attribute files do not accept a negative value since the commit 488dac0c9237 ("libfs: fix error cast of negative value in simple_attr_write()"), so we have to use a 64-bit value to write a negative value. This adds DEFINE_SIMPLE_ATTRIBUTE_SIGNED for a signed value. Fixes: 488dac0c9237 ("libfs: fix error cast of negative value in simple_attr_write()") Reported-by: Zhao Gongyi Signed-off-by: Akinobu Mita Reviewed-by: David Hildenbrand --- fs/libfs.c | 22 +++++++++++++++++++--- include/linux/fs.h | 12 ++++++++++-- 2 files changed, 29 insertions(+), 5 deletions(-) diff --git a/fs/libfs.c b/fs/libfs.c index 31b0ddf01c31..76fb29a103a2 100644 --- a/fs/libfs.c +++ b/fs/libfs.c @@ -994,8 +994,8 @@ ssize_t simple_attr_read(struct file *file, char __user *buf, EXPORT_SYMBOL_GPL(simple_attr_read); /* interpret the buffer as a number to call the set function with */ -ssize_t simple_attr_write(struct file *file, const char __user *buf, - size_t len, loff_t *ppos) +static ssize_t simple_attr_write_xsigned(struct file *file, const char __user *buf, + size_t len, loff_t *ppos, bool is_signed) { struct simple_attr *attr; unsigned long long val; @@ -1016,7 +1016,10 @@ ssize_t simple_attr_write(struct file *file, const char __user *buf, goto out; attr->set_buf[size] = '\0'; - ret = kstrtoull(attr->set_buf, 0, &val); + if (is_signed) + ret = kstrtoll(attr->set_buf, 0, &val); + else + ret = kstrtoull(attr->set_buf, 0, &val); if (ret) goto out; ret = attr->set(attr->data, val); @@ -1026,8 +1029,21 @@ ssize_t simple_attr_write(struct file *file, const char __user *buf, mutex_unlock(&attr->mutex); return ret; } + +ssize_t simple_attr_write(struct file *file, const char __user *buf, + size_t len, loff_t *ppos) +{ + return simple_attr_write_xsigned(file, buf, len, ppos, false); +} EXPORT_SYMBOL_GPL(simple_attr_write); +ssize_t simple_attr_write_signed(struct file *file, const char __user *buf, + size_t len, loff_t *ppos) +{ + return simple_attr_write_xsigned(file, buf, len, ppos, true); +} +EXPORT_SYMBOL_GPL(simple_attr_write_signed); + /** * generic_fh_to_dentry - generic helper for the fh_to_dentry export operation * @sb: filesystem to do the file handle conversion on diff --git a/include/linux/fs.h b/include/linux/fs.h index 9eced4cc286e..c79138818922 100644 --- a/include/linux/fs.h +++ b/include/linux/fs.h @@ -3471,7 +3471,7 @@ void simple_transaction_set(struct file *file, size_t n); * All attributes contain a text representation of a numeric value * that are accessed with the get() and set() functions. */ -#define DEFINE_SIMPLE_ATTRIBUTE(__fops, __get, __set, __fmt) \ +#define DEFINE_SIMPLE_ATTRIBUTE_XSIGNED(__fops, __get, __set, __fmt, __is_signed) \ static int __fops ## _open(struct inode *inode, struct file *file) \ { \ __simple_attr_check_format(__fmt, 0ull); \ @@ -3482,10 +3482,16 @@ static const struct file_operations __fops = { \ .open = __fops ## _open, \ .release = simple_attr_release, \ .read = simple_attr_read, \ - .write = simple_attr_write, \ + .write = (__is_signed) ? simple_attr_write_signed : simple_attr_write, \ .llseek = generic_file_llseek, \ } +#define DEFINE_SIMPLE_ATTRIBUTE(__fops, __get, __set, __fmt) \ + DEFINE_SIMPLE_ATTRIBUTE_XSIGNED(__fops, __get, __set, __fmt, false) + +#define DEFINE_SIMPLE_ATTRIBUTE_SIGNED(__fops, __get, __set, __fmt) \ + DEFINE_SIMPLE_ATTRIBUTE_XSIGNED(__fops, __get, __set, __fmt, true) + static inline __printf(1, 2) void __simple_attr_check_format(const char *fmt, ...) { @@ -3500,6 +3506,8 @@ ssize_t simple_attr_read(struct file *file, char __user *buf, size_t len, loff_t *ppos); ssize_t simple_attr_write(struct file *file, const char __user *buf, size_t len, loff_t *ppos); +ssize_t simple_attr_write_signed(struct file *file, const char __user *buf, + size_t len, loff_t *ppos); struct ctl_table; int __init list_bdev_fs_names(char *buf, size_t size); From patchwork Mon Sep 19 17:24:17 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Akinobu Mita X-Patchwork-Id: 12980831 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by smtp.lore.kernel.org (Postfix) with ESMTP id 18FA3ECAAA1 for ; Mon, 19 Sep 2022 17:25:00 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 9E9D26B0071; Mon, 19 Sep 2022 13:24:59 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id 99783940009; Mon, 19 Sep 2022 13:24:59 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 8382C6B0073; Mon, 19 Sep 2022 13:24:59 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0010.hostedemail.com [216.40.44.10]) by kanga.kvack.org (Postfix) with ESMTP id 777326B0071 for ; Mon, 19 Sep 2022 13:24:59 -0400 (EDT) Received: from smtpin03.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay01.hostedemail.com (Postfix) with ESMTP id 498141C614C for ; Mon, 19 Sep 2022 17:24:59 +0000 (UTC) X-FDA: 79929510318.03.5F493AA Received: from mail-pj1-f41.google.com (mail-pj1-f41.google.com [209.85.216.41]) by imf30.hostedemail.com (Postfix) with ESMTP id F2DD280010 for ; Mon, 19 Sep 2022 17:24:58 +0000 (UTC) Received: by mail-pj1-f41.google.com with SMTP id j6-20020a17090a694600b00200bba67dadso6778065pjm.5 for ; Mon, 19 Sep 2022 10:24:58 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20210112; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date; bh=bbpyEIxy2q5E0Mu0eFfeDQBjUZV6iZmC2F5w0SRo/n0=; b=Co/4gbdqV3wYszCUQb+RGNGJu20t0HKKIu5oDP6hA8o9BdkU2FmW7i7IcL+7qo2PaC gM4RjQzS/YttfgyX5aTlw6dn83JpW5nnVlJPkKOC2VdS3K56xvI+AGNZfBtbF/h1rFER ScpZLXretyLf+Rt5TNkDJFqMg/kQ2Ipeq1lo7ytmLUhfwl5T7t+p5MOqXuiRfV4iyrJp Q8j82WniFh2z9s041bYtoTiYgUNtESbIF5HpSuNW1z0aCwe1479MPo92D2QSvDuadXob nNC7P8bvFcBWcvO0WucpeKiFL4sbIyYia87lUj0/OSbuGM0B/3hp4Okx1oAQO7TWN6UM a+5w== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date; bh=bbpyEIxy2q5E0Mu0eFfeDQBjUZV6iZmC2F5w0SRo/n0=; b=pM+E2hbMdoBE8YGl8ogGli55PE9xvfGCNim9Tz1bM/rm/q8LCzMH7U3W24YL8Mfe2q HcA3xLZR9msrm1eGgogOULJsOJtocsb8x9NRm0fVq+z6tKANovkjFi8A2njPXQbLXzei ZgZ+8a9LBIEGA5v3LUB2Tqoi/6V1WVPNIJ8nfbSvBWZs/uSIkrdHsp4Zdn9YOxY31CjC d/jGLRsn5wXdFz1xWCWS+qlPiXQu+zGxz0UnQ7OsaoqV/I+BpAJDMWg9ArgrWMXc6ZMF UfORPCX4k+M1T+N22FWvH3RYiUG/AzUoWW/8NivSHKCuMCIVFrrCYz+FUpBR7YQJQlho KPQg== X-Gm-Message-State: ACrzQf3ysJvtjcqrtfzQJvrLOaG5M6lPzBSyTUEEjm+tW10QA2fY2tHs JvOCNYT6A9ZyU8AiMWr/WvA= X-Google-Smtp-Source: AMsMyM6Qrw6HZuNf6rIjays5IloSGiOAoofUELKN7KLJpWX1ntXV4kAENP3WaVkLwjI5RbzGYGwmPw== X-Received: by 2002:a17:90a:ac10:b0:202:9880:4cae with SMTP id o16-20020a17090aac1000b0020298804caemr20626018pjq.173.1663608297969; Mon, 19 Sep 2022 10:24:57 -0700 (PDT) Received: from localhost.localdomain (KD027092233113.ppp-bb.dion.ne.jp. [27.92.233.113]) by smtp.gmail.com with ESMTPSA id h7-20020aa796c7000000b0053f2505318asm21226480pfq.142.2022.09.19.10.24.54 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 19 Sep 2022 10:24:57 -0700 (PDT) From: Akinobu Mita To: linux-doc@vger.kernel.org, linux-kernel@vger.kernel.org, linux-mm@kvack.org, linux-kselftest@vger.kernel.org, linux-fsdevel@vger.kernel.org, corbet@lwn.net, david@redhat.com, osalvador@suse.de, shuah@kernel.org, Zhao Gongyi , Wei Yongjun , Yicong Yang , Greg Kroah-Hartman , "Rafael J. Wysocki" , Alexander Viro , akpm@linux-foundation.org Cc: Akinobu Mita Subject: [PATCH 2/3] lib/notifier-error-inject: fix error when writing -errno to debugfs file Date: Tue, 20 Sep 2022 02:24:17 +0900 Message-Id: <20220919172418.45257-3-akinobu.mita@gmail.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20220919172418.45257-1-akinobu.mita@gmail.com> References: <20220919172418.45257-1-akinobu.mita@gmail.com> MIME-Version: 1.0 ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1663608298; h=from:from:sender:reply-to:subject:subject:date:date: message-id:message-id:to:to:cc:cc:mime-version:mime-version: content-type:content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references:dkim-signature; bh=bbpyEIxy2q5E0Mu0eFfeDQBjUZV6iZmC2F5w0SRo/n0=; b=rY8IqBuVdP27Vufc3CVKTrWSHyyjnRMpsyYNd/nJOyhLnCkcVklfp46YnVWxDY6r8d8aPd nT4ciW0/hyAd6tbHhCBiBNeYh18iMb/yDqAqgEFNqahR3AZK5TdNDgs1/mJScCfTPeWQCO 9UGBlcxasB+619riOcN3ylKrYzB9PIc= ARC-Authentication-Results: i=1; imf30.hostedemail.com; dkim=pass header.d=gmail.com header.s=20210112 header.b="Co/4gbdq"; dmarc=pass (policy=none) header.from=gmail.com; spf=pass (imf30.hostedemail.com: domain of akinobu.mita@gmail.com designates 209.85.216.41 as permitted sender) smtp.mailfrom=akinobu.mita@gmail.com ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1663608299; a=rsa-sha256; cv=none; b=C/+PKdFP4oBbH2kiTyVmAS+qYf+kiVfpzipFi/znTo5lOw4uHlGJlS5uS/Lf/TJZ2VTQM7 VAzU3WFF+hK+7aiGAfOPvvEBNWQ2TEIo7dd4S5OUJKXonUFuzB+Th/q1hBFK73gQ2LQ4hm uNmpDY1PzZB6ZkQaRCFH42MKwGFbq6c= X-Stat-Signature: p7w3s5p3m481c9m1ddcbfi8xgtm5emcw X-Rspamd-Queue-Id: F2DD280010 Authentication-Results: imf30.hostedemail.com; dkim=pass header.d=gmail.com header.s=20210112 header.b="Co/4gbdq"; dmarc=pass (policy=none) header.from=gmail.com; spf=pass (imf30.hostedemail.com: domain of akinobu.mita@gmail.com designates 209.85.216.41 as permitted sender) smtp.mailfrom=akinobu.mita@gmail.com X-Rspam-User: X-Rspamd-Server: rspam06 X-HE-Tag: 1663608298-553601 X-Bogosity: Ham, tests=bogofilter, spamicity=0.000000, version=1.2.4 Sender: owner-linux-mm@kvack.org Precedence: bulk X-Loop: owner-majordomo@kvack.org List-ID: The simple attribute files do not accept a negative value since the commit 488dac0c9237 ("libfs: fix error cast of negative value in simple_attr_write()"). This restores the previous behaviour by using newly introduced DEFINE_SIMPLE_ATTRIBUTE_SIGNED instead of DEFINE_SIMPLE_ATTRIBUTE. Fixes: 488dac0c9237 ("libfs: fix error cast of negative value in simple_attr_write()") Reported-by: Zhao Gongyi Signed-off-by: Akinobu Mita Reviewed-by: David Hildenbrand --- lib/notifier-error-inject.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/notifier-error-inject.c b/lib/notifier-error-inject.c index 21016b32d313..2b24ea6c9497 100644 --- a/lib/notifier-error-inject.c +++ b/lib/notifier-error-inject.c @@ -15,7 +15,7 @@ static int debugfs_errno_get(void *data, u64 *val) return 0; } -DEFINE_SIMPLE_ATTRIBUTE(fops_errno, debugfs_errno_get, debugfs_errno_set, +DEFINE_SIMPLE_ATTRIBUTE_SIGNED(fops_errno, debugfs_errno_get, debugfs_errno_set, "%lld\n"); static struct dentry *debugfs_create_errno(const char *name, umode_t mode, From patchwork Mon Sep 19 17:24:18 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Akinobu Mita X-Patchwork-Id: 12980832 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by smtp.lore.kernel.org (Postfix) with ESMTP id 3E305ECAAA1 for ; Mon, 19 Sep 2022 17:25:04 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id B958794000A; Mon, 19 Sep 2022 13:25:03 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id B44B5940009; Mon, 19 Sep 2022 13:25:03 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 9E61F94000A; Mon, 19 Sep 2022 13:25:03 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0010.hostedemail.com [216.40.44.10]) by kanga.kvack.org (Postfix) with ESMTP id 907C2940009 for ; Mon, 19 Sep 2022 13:25:03 -0400 (EDT) Received: from smtpin02.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay04.hostedemail.com (Postfix) with ESMTP id 6D7641A03BF for ; Mon, 19 Sep 2022 17:25:03 +0000 (UTC) X-FDA: 79929510486.02.F92A925 Received: from mail-pf1-f170.google.com (mail-pf1-f170.google.com [209.85.210.170]) by imf16.hostedemail.com (Postfix) with ESMTP id 10D51180006 for ; Mon, 19 Sep 2022 17:25:02 +0000 (UTC) Received: by mail-pf1-f170.google.com with SMTP id b75so256556pfb.7 for ; Mon, 19 Sep 2022 10:25:02 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20210112; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date; bh=euAaknLa+h5zIEMESHSd9vMo0x33lOPRlPldQOSO1tY=; b=ShNlkKcjQX74zNjF0cFpDDUgQjKD8DIkh4EVc7Mv0LXsJafE4SY2OEYjaXtaX6yg8Z 8PJonHc9SvScgzKL+dfAAtAzN5E0QOm7TMiGh2Ekv8ph4CTYvq458StXhFk/3SPwMm3F pBPxy2kCWa/AcGmxcGJKEWMGDaIOsTcrM8xaBFKZCvGgwW/IdONn/pVcY4Fow5+4aJSw 0cPtz24cRa12OPlbcMKQngJjGnF67wogF9OE5broq9HuQhZ3ydOxsJpbUfpIjX0ugOuw N27BvSJhGKXz03wnL1LZqtd0vyEKXZjs3SigU8Kfz8DrsmsoOySbz9GKYKX7CBuDtB/Q lnpg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date; bh=euAaknLa+h5zIEMESHSd9vMo0x33lOPRlPldQOSO1tY=; b=iyRYlx5LfVnWLouyOMPnJEtTWzSvTbes6d4TEd/xG5eQVLlmANQqWXS2DpS8q/l26r 2rsoxDIrNyUlrqJWtHVOfr7AArsbtoGm8hD+rc+WYUQj6aj6UMm+wP++h3bVi2Av6IzY ArluDapoy3tLr5bpZ0Q3eQTfE4wWApP3wy/SpMWi9RrjfpT/XvyO/iKhmyLXn+W2hFfY roS1+xePLrE4zmB5tIjsuHm6ZsV+hcX9id+gamCsLlbCv7ffQlXJ04pVmCWA8Pazw6RM DbMY+ELU3SPklPlSAT3me4ez4yu59tIausN8uqMfMF0rzVz9uHKq/tFwDw37D8uxOS/w SrMA== X-Gm-Message-State: ACrzQf1S0r4ogBnOszi6+Rvn0at0rItZnxqFZgPf3R9dvWMcmEudtgPv koWdhl7+bSnbSe6VjS/QEu0= X-Google-Smtp-Source: AMsMyM6OTf8JGt0/2O1PiJjtsm9iJk3G5nddptF65VkDZixrBOW+hXa9Ea4CpUGY12LhhkBrwX/ErA== X-Received: by 2002:a63:b64:0:b0:439:8143:c184 with SMTP id a36-20020a630b64000000b004398143c184mr16377617pgl.22.1663608301881; Mon, 19 Sep 2022 10:25:01 -0700 (PDT) Received: from localhost.localdomain (KD027092233113.ppp-bb.dion.ne.jp. [27.92.233.113]) by smtp.gmail.com with ESMTPSA id h7-20020aa796c7000000b0053f2505318asm21226480pfq.142.2022.09.19.10.24.58 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 19 Sep 2022 10:25:01 -0700 (PDT) From: Akinobu Mita To: linux-doc@vger.kernel.org, linux-kernel@vger.kernel.org, linux-mm@kvack.org, linux-kselftest@vger.kernel.org, linux-fsdevel@vger.kernel.org, corbet@lwn.net, david@redhat.com, osalvador@suse.de, shuah@kernel.org, Zhao Gongyi , Wei Yongjun , Yicong Yang , Greg Kroah-Hartman , "Rafael J. Wysocki" , Alexander Viro , akpm@linux-foundation.org Cc: Akinobu Mita Subject: [PATCH 3/3] debugfs: fix error when writing negative value to atomic_t debugfs file Date: Tue, 20 Sep 2022 02:24:18 +0900 Message-Id: <20220919172418.45257-4-akinobu.mita@gmail.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20220919172418.45257-1-akinobu.mita@gmail.com> References: <20220919172418.45257-1-akinobu.mita@gmail.com> MIME-Version: 1.0 ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1663608303; h=from:from:sender:reply-to:subject:subject:date:date: message-id:message-id:to:to:cc:cc:mime-version:mime-version: content-type:content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references:dkim-signature; bh=euAaknLa+h5zIEMESHSd9vMo0x33lOPRlPldQOSO1tY=; b=oUR0mUo/k6ipKsPgzviNu8E853SSE+oAnfVbLYdgF67QzrsSiX9QgEgM1dw9ZlDV6AV2F3 KSChRkxGW0oCsuOCusVZXSyz3COYvcj/x+wea1kJfk/1ybS+1BUCwar2qq8ZEaBTaqy6r2 FboseA+wFqGvO0KbLDXNCULStUZoK5I= ARC-Authentication-Results: i=1; imf16.hostedemail.com; dkim=pass header.d=gmail.com header.s=20210112 header.b=ShNlkKcj; dmarc=pass (policy=none) header.from=gmail.com; spf=pass (imf16.hostedemail.com: domain of akinobu.mita@gmail.com designates 209.85.210.170 as permitted sender) smtp.mailfrom=akinobu.mita@gmail.com ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1663608303; a=rsa-sha256; cv=none; b=gsF1wqsojOQzYUl1zUQU6dOQ04jIvnmKPpOtPyemQT4DQsG7SeuukBEmISiMFpw0rTHdee glLpChIicLmi3lO5spvN+LnJx8RlvTln0BltTD0Q+uaAS8yMtHnE9OZs1SaQ/rzQ2DStwg tBpC+KiS6FRJJnzHrdvESUvJ5wSCjBQ= X-Rspamd-Server: rspam12 X-Rspamd-Queue-Id: 10D51180006 X-Rspam-User: Authentication-Results: imf16.hostedemail.com; dkim=pass header.d=gmail.com header.s=20210112 header.b=ShNlkKcj; dmarc=pass (policy=none) header.from=gmail.com; spf=pass (imf16.hostedemail.com: domain of akinobu.mita@gmail.com designates 209.85.210.170 as permitted sender) smtp.mailfrom=akinobu.mita@gmail.com X-Stat-Signature: jismrcsykmtxj593a4kmberbba8sikpi X-HE-Tag: 1663608302-414361 X-Bogosity: Ham, tests=bogofilter, spamicity=0.000000, version=1.2.4 Sender: owner-linux-mm@kvack.org Precedence: bulk X-Loop: owner-majordomo@kvack.org List-ID: The simple attribute files do not accept a negative value since the commit 488dac0c9237 ("libfs: fix error cast of negative value in simple_attr_write()"), so we have to use a 64-bit value to write a negative value for a debugfs file created by debugfs_create_atomic_t(). This restores the previous behaviour by introducing DEFINE_DEBUGFS_ATTRIBUTE_SIGNED for a signed value. Fixes: 488dac0c9237 ("libfs: fix error cast of negative value in simple_attr_write()") Reported-by: Zhao Gongyi Signed-off-by: Akinobu Mita Reviewed-by: David Hildenbrand --- .../fault-injection/fault-injection.rst | 10 +++---- fs/debugfs/file.c | 28 +++++++++++++++---- include/linux/debugfs.h | 19 +++++++++++-- 3 files changed, 43 insertions(+), 14 deletions(-) diff --git a/Documentation/fault-injection/fault-injection.rst b/Documentation/fault-injection/fault-injection.rst index 17779a2772e5..5f6454b9dbd4 100644 --- a/Documentation/fault-injection/fault-injection.rst +++ b/Documentation/fault-injection/fault-injection.rst @@ -83,9 +83,7 @@ configuration of fault-injection capabilities. - /sys/kernel/debug/fail*/times: specifies how many times failures may happen at most. A value of -1 - means "no limit". Note, though, that this file only accepts unsigned - values. So, if you want to specify -1, you better use 'printf' instead - of 'echo', e.g.: $ printf %#x -1 > times + means "no limit". - /sys/kernel/debug/fail*/space: @@ -284,7 +282,7 @@ Application Examples echo Y > /sys/kernel/debug/$FAILTYPE/task-filter echo 10 > /sys/kernel/debug/$FAILTYPE/probability echo 100 > /sys/kernel/debug/$FAILTYPE/interval - printf %#x -1 > /sys/kernel/debug/$FAILTYPE/times + echo -1 > /sys/kernel/debug/$FAILTYPE/times echo 0 > /sys/kernel/debug/$FAILTYPE/space echo 2 > /sys/kernel/debug/$FAILTYPE/verbose echo Y > /sys/kernel/debug/$FAILTYPE/ignore-gfp-wait @@ -338,7 +336,7 @@ Application Examples echo N > /sys/kernel/debug/$FAILTYPE/task-filter echo 10 > /sys/kernel/debug/$FAILTYPE/probability echo 100 > /sys/kernel/debug/$FAILTYPE/interval - printf %#x -1 > /sys/kernel/debug/$FAILTYPE/times + echo -1 > /sys/kernel/debug/$FAILTYPE/times echo 0 > /sys/kernel/debug/$FAILTYPE/space echo 2 > /sys/kernel/debug/$FAILTYPE/verbose echo Y > /sys/kernel/debug/$FAILTYPE/ignore-gfp-wait @@ -369,7 +367,7 @@ Application Examples echo N > /sys/kernel/debug/$FAILTYPE/task-filter echo 100 > /sys/kernel/debug/$FAILTYPE/probability echo 0 > /sys/kernel/debug/$FAILTYPE/interval - printf %#x -1 > /sys/kernel/debug/$FAILTYPE/times + echo -1 > /sys/kernel/debug/$FAILTYPE/times echo 0 > /sys/kernel/debug/$FAILTYPE/space echo 1 > /sys/kernel/debug/$FAILTYPE/verbose diff --git a/fs/debugfs/file.c b/fs/debugfs/file.c index 950c63fa4d0b..38930d9b0bb7 100644 --- a/fs/debugfs/file.c +++ b/fs/debugfs/file.c @@ -378,8 +378,8 @@ ssize_t debugfs_attr_read(struct file *file, char __user *buf, } EXPORT_SYMBOL_GPL(debugfs_attr_read); -ssize_t debugfs_attr_write(struct file *file, const char __user *buf, - size_t len, loff_t *ppos) +static ssize_t debugfs_attr_write_xsigned(struct file *file, const char __user *buf, + size_t len, loff_t *ppos, bool is_signed) { struct dentry *dentry = F_DENTRY(file); ssize_t ret; @@ -387,12 +387,28 @@ ssize_t debugfs_attr_write(struct file *file, const char __user *buf, ret = debugfs_file_get(dentry); if (unlikely(ret)) return ret; - ret = simple_attr_write(file, buf, len, ppos); + if (is_signed) + ret = simple_attr_write_signed(file, buf, len, ppos); + else + ret = simple_attr_write(file, buf, len, ppos); debugfs_file_put(dentry); return ret; } + +ssize_t debugfs_attr_write(struct file *file, const char __user *buf, + size_t len, loff_t *ppos) +{ + return debugfs_attr_write_xsigned(file, buf, len, ppos, false); +} EXPORT_SYMBOL_GPL(debugfs_attr_write); +ssize_t debugfs_attr_write_signed(struct file *file, const char __user *buf, + size_t len, loff_t *ppos) +{ + return debugfs_attr_write_xsigned(file, buf, len, ppos, true); +} +EXPORT_SYMBOL_GPL(debugfs_attr_write_signed); + static struct dentry *debugfs_create_mode_unsafe(const char *name, umode_t mode, struct dentry *parent, void *value, const struct file_operations *fops, @@ -738,11 +754,11 @@ static int debugfs_atomic_t_get(void *data, u64 *val) *val = atomic_read((atomic_t *)data); return 0; } -DEFINE_DEBUGFS_ATTRIBUTE(fops_atomic_t, debugfs_atomic_t_get, +DEFINE_DEBUGFS_ATTRIBUTE_SIGNED(fops_atomic_t, debugfs_atomic_t_get, debugfs_atomic_t_set, "%lld\n"); -DEFINE_DEBUGFS_ATTRIBUTE(fops_atomic_t_ro, debugfs_atomic_t_get, NULL, +DEFINE_DEBUGFS_ATTRIBUTE_SIGNED(fops_atomic_t_ro, debugfs_atomic_t_get, NULL, "%lld\n"); -DEFINE_DEBUGFS_ATTRIBUTE(fops_atomic_t_wo, NULL, debugfs_atomic_t_set, +DEFINE_DEBUGFS_ATTRIBUTE_SIGNED(fops_atomic_t_wo, NULL, debugfs_atomic_t_set, "%lld\n"); /** diff --git a/include/linux/debugfs.h b/include/linux/debugfs.h index f60674692d36..ea2d919fd9c7 100644 --- a/include/linux/debugfs.h +++ b/include/linux/debugfs.h @@ -45,7 +45,7 @@ struct debugfs_u32_array { extern struct dentry *arch_debugfs_dir; -#define DEFINE_DEBUGFS_ATTRIBUTE(__fops, __get, __set, __fmt) \ +#define DEFINE_DEBUGFS_ATTRIBUTE_XSIGNED(__fops, __get, __set, __fmt, __is_signed) \ static int __fops ## _open(struct inode *inode, struct file *file) \ { \ __simple_attr_check_format(__fmt, 0ull); \ @@ -56,10 +56,16 @@ static const struct file_operations __fops = { \ .open = __fops ## _open, \ .release = simple_attr_release, \ .read = debugfs_attr_read, \ - .write = debugfs_attr_write, \ + .write = (__is_signed) ? debugfs_attr_write_signed : debugfs_attr_write, \ .llseek = no_llseek, \ } +#define DEFINE_DEBUGFS_ATTRIBUTE(__fops, __get, __set, __fmt) \ + DEFINE_DEBUGFS_ATTRIBUTE_XSIGNED(__fops, __get, __set, __fmt, false) + +#define DEFINE_DEBUGFS_ATTRIBUTE_SIGNED(__fops, __get, __set, __fmt) \ + DEFINE_DEBUGFS_ATTRIBUTE_XSIGNED(__fops, __get, __set, __fmt, true) + typedef struct vfsmount *(*debugfs_automount_t)(struct dentry *, void *); #if defined(CONFIG_DEBUG_FS) @@ -102,6 +108,8 @@ ssize_t debugfs_attr_read(struct file *file, char __user *buf, size_t len, loff_t *ppos); ssize_t debugfs_attr_write(struct file *file, const char __user *buf, size_t len, loff_t *ppos); +ssize_t debugfs_attr_write_signed(struct file *file, const char __user *buf, + size_t len, loff_t *ppos); struct dentry *debugfs_rename(struct dentry *old_dir, struct dentry *old_dentry, struct dentry *new_dir, const char *new_name); @@ -254,6 +262,13 @@ static inline ssize_t debugfs_attr_write(struct file *file, return -ENODEV; } +static inline ssize_t debugfs_attr_write_signed(struct file *file, + const char __user *buf, + size_t len, loff_t *ppos) +{ + return -ENODEV; +} + static inline struct dentry *debugfs_rename(struct dentry *old_dir, struct dentry *old_dentry, struct dentry *new_dir, char *new_name) {