From patchwork Thu May 4 07:31:25 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Omar Sandoval X-Patchwork-Id: 9710903 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork.web.codeaurora.org (Postfix) with ESMTP id DD27260362 for ; Thu, 4 May 2017 07:31:47 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id CFEDC28682 for ; Thu, 4 May 2017 07:31:47 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id C4DD328685; Thu, 4 May 2017 07:31:47 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-6.9 required=2.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,RCVD_IN_DNSWL_HI autolearn=ham version=3.3.1 Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 73FDF28682 for ; Thu, 4 May 2017 07:31:47 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1752512AbdEDHbq (ORCPT ); Thu, 4 May 2017 03:31:46 -0400 Received: from mail-pf0-f171.google.com ([209.85.192.171]:35579 "EHLO mail-pf0-f171.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1752498AbdEDHbq (ORCPT ); Thu, 4 May 2017 03:31:46 -0400 Received: by mail-pf0-f171.google.com with SMTP id v14so3724436pfd.2 for ; Thu, 04 May 2017 00:31:46 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=osandov-com.20150623.gappssmtp.com; s=20150623; h=from:to:cc:subject:date:message-id:in-reply-to:references :in-reply-to:references; bh=hE+P0iLFGsleZZfLTnrCVEmPeYdVuQ3srvUkVu7MGYQ=; b=GYf6QxY0/aU6eLO1Ne4O1cjrlqjNMkIB1g/jBRcJqduKtriFEb/UupLR+MLpVnC6v2 wsKyqv179HJLO0kBmu/XRddaPjoQf7EpwLevoRU0O2mdkL9T4sKyob0ZX+Pmix0NKL2P F6QAEBVzSmTgFd5raRmhFKIpxtXewui0VJLvommEsf1fvW1GQi5hKEyLE5R7He4tX499 ZsZUdPAK/Dol+tQUOxYq0CpWFpCBwzl5tm7ZFTtyaiZKnex0GnRgk2GC5GxoUR6X9ZNe Iynco8duugAaEYVJ+3yX81TCmdV8NUbMbgMuvyzxWYDim0/lVrmibMbOaoBDzo1ur6Nf WLvg== 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:in-reply-to:references; bh=hE+P0iLFGsleZZfLTnrCVEmPeYdVuQ3srvUkVu7MGYQ=; b=npxKVuUuzylS9LSSGtt7FMUtlRHCONQYVku8BSv7u8Nxi2D3aBMp28YJhQnPWiYhJU y5ra/OpAqR7dWS9Ia00NNN6kCJx2A8cyjfAREZ1oIKAggTxyUeJZe7VNRKCjcALs5dYW 3Q7Zh+l/oOajmZ+uPmQGBNGwuJSBLDJXz9YGUEekNnx68nYE43YomRR3mvvCHenWHKlX CA8H8KbkBC27Jqe9/Zk7DGRSJCBlE2KAQWdxg4u3MH8SjC6TdTZ711tf1qvyEa7bdR+g p6cAxThgrhlPXOux0mlPH93oNyOQ6K+wpoxoweZr5mPhDNIg/26Ch1BR7QFBH8plgoUJ ItPQ== X-Gm-Message-State: AN3rC/5tLyJIp4rCGdRMCY0agWeJcTT2GBq/dK6tb7+DaWMwIYqoiby/ gSOTdDexauKHC2Pm X-Received: by 10.98.67.140 with SMTP id l12mr9386550pfi.110.1493883105553; Thu, 04 May 2017 00:31:45 -0700 (PDT) Received: from vader.thefacebook.com ([2620:10d:c090:180::1:1d23]) by smtp.gmail.com with ESMTPSA id q6sm2272168pfq.18.2017.05.04.00.31.44 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Thu, 04 May 2017 00:31:45 -0700 (PDT) From: Omar Sandoval To: Jens Axboe , linux-block@vger.kernel.org Cc: Bart Van Assche , kernel-team@fb.com Subject: [PATCH v2 03/12] blk-mq-debugfs: error on long write to queue "state" file Date: Thu, 4 May 2017 00:31:25 -0700 Message-Id: <859ef1939e07171f902b4fbb5bebbb274d68df18.1493882751.git.osandov@fb.com> X-Mailer: git-send-email 2.12.2 In-Reply-To: References: In-Reply-To: References: Sender: linux-block-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-block@vger.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP From: Omar Sandoval blk_queue_flags_store() currently truncates and returns a short write if the operation being written is too long. This can give us weird results, like here: $ echo "run bar" echo: write error: invalid argument $ dmesg [ 1103.075435] blk_queue_flags_store: unsupported operation bar. Use either 'run' or 'start' Instead, return an error if the user does this. While we're here, make the argument names consistent with everywhere else in this file. Signed-off-by: Omar Sandoval Reviewed-by: Hannes Reinecke Reviewed-by: Bart Van Assche --- block/blk-mq-debugfs.c | 19 ++++++++++++------- 1 file changed, 12 insertions(+), 7 deletions(-) diff --git a/block/blk-mq-debugfs.c b/block/blk-mq-debugfs.c index f58a116d6cca..2a19237455d4 100644 --- a/block/blk-mq-debugfs.c +++ b/block/blk-mq-debugfs.c @@ -107,14 +107,18 @@ static int blk_queue_flags_show(struct seq_file *m, void *v) return 0; } -static ssize_t blk_queue_flags_store(struct file *file, const char __user *ubuf, - size_t len, loff_t *offp) +static ssize_t blk_queue_flags_store(struct file *file, const char __user *buf, + size_t count, loff_t *ppos) { struct request_queue *q = file_inode(file)->i_private; char op[16] = { }, *s; - len = min(len, sizeof(op) - 1); - if (copy_from_user(op, ubuf, len)) + if (count >= sizeof(op)) { + pr_err("%s: operation too long\n", __func__); + goto inval; + } + + if (copy_from_user(op, buf, count)) return -EFAULT; s = op; strsep(&s, " \t\n"); /* strip trailing whitespace */ @@ -123,11 +127,12 @@ static ssize_t blk_queue_flags_store(struct file *file, const char __user *ubuf, } else if (strcmp(op, "start") == 0) { blk_mq_start_stopped_hw_queues(q, true); } else { - pr_err("%s: unsupported operation %s. Use either 'run' or 'start'\n", - __func__, op); + pr_err("%s: unsupported operation '%s'\n", __func__, op); +inval: + pr_err("%s: use either 'run' or 'start'\n", __func__); return -EINVAL; } - return len; + return count; } static int blk_queue_flags_open(struct inode *inode, struct file *file)