From patchwork Fri Feb 19 12:56:57 2016 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: =?utf-8?q?Matias_Bj=C3=B8rling?= X-Patchwork-Id: 8360661 Return-Path: X-Original-To: patchwork-linux-block@patchwork.kernel.org Delivered-To: patchwork-parsemail@patchwork1.web.kernel.org Received: from mail.kernel.org (mail.kernel.org [198.145.29.136]) by patchwork1.web.kernel.org (Postfix) with ESMTP id BC34F9F2F0 for ; Fri, 19 Feb 2016 12:58:47 +0000 (UTC) Received: from mail.kernel.org (localhost [127.0.0.1]) by mail.kernel.org (Postfix) with ESMTP id DECA32049C for ; Fri, 19 Feb 2016 12:58:46 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id D2A4E20494 for ; Fri, 19 Feb 2016 12:58:45 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1757877AbcBSM6p (ORCPT ); Fri, 19 Feb 2016 07:58:45 -0500 Received: from mail-wm0-f41.google.com ([74.125.82.41]:37376 "EHLO mail-wm0-f41.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1757844AbcBSM5w (ORCPT ); Fri, 19 Feb 2016 07:57:52 -0500 Received: by mail-wm0-f41.google.com with SMTP id g62so69782389wme.0 for ; Fri, 19 Feb 2016 04:57:52 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=bjorling.me; s=google; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-type:content-transfer-encoding; bh=mahAZuRV7zsjZTeNqM0rWTGvFCSavZXmQTvpgrt89JY=; b=E97i5SKlaXxaX5QJekCHULl1TUsuNH1em81f11HTilmSS8AqRUid7vkq8T0kwxZg3e GskAlJdyxVOtqBkpxzybNWOgf51GyiSzoEQvRDZ2zNkT1KIygxP1xJF7ZTIQ0SLxMIs+ uclPYUgFNhH5m6ixDWvVhmVwbzubEPFJoO1X8= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20130820; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-type:content-transfer-encoding; bh=mahAZuRV7zsjZTeNqM0rWTGvFCSavZXmQTvpgrt89JY=; b=Qd7QSQcp6TH2ASB9EqHKahbBkcE0ONsEX7nr8ckPKmGgnhjcyz7p4lPKvQ9OKoq0xI 9DT3ZVvp0EBb8gzltF7nMB3r+jljAfzQeZR+9ss50mn8t6CqbU7appDjQu4TPTCcCo0X p4X/jommJ2wZjtWduYW5yx11lj9lucwTzc9Ztvz/TJ5BrwoVqa2LM7IJMDhybSzEqZ2T EqnkZa8omLzFb/CYxFmLBXb6g7cLLVK+Kzm9HxtRdIyJvtGJ9LRdBD9b+e+mFZ4tllVB e+8lRkKnW+rIcn1iaC24cpzQso1Doa/VO6pfbWAXC1W4bSi12gylHHO76ZCCfDD2r8r2 H0hQ== X-Gm-Message-State: AG10YOQ1m0VK1Sxy6isiq6xIWISGZ858EzCK5IUNm/sjMf4WWYau+FPANOdrqTvf0/wOnA== X-Received: by 10.28.158.198 with SMTP id h189mr8885712wme.74.1455886671641; Fri, 19 Feb 2016 04:57:51 -0800 (PST) Received: from localhost.localdomain (6164198-cl69.boa.fiberby.dk. [193.106.164.198]) by smtp.gmail.com with ESMTPSA id ks5sm11157902wjb.13.2016.02.19.04.57.50 (version=TLS1_2 cipher=ECDHE-RSA-AES128-SHA bits=128/128); Fri, 19 Feb 2016 04:57:50 -0800 (PST) From: =?UTF-8?q?Matias=20Bj=C3=B8rling?= To: linux-block@vger.kernel.org, linux-kernel@vger.kernel.org, axboe@fb.com Cc: Alan , Alan Cox , =?UTF-8?q?Matias=20Bj=C3=B8rling?= Subject: [PATCH 1/3] lightnvm: fix up nonsensical configure overrun checking Date: Fri, 19 Feb 2016 13:56:57 +0100 Message-Id: <1455886619-3007-2-git-send-email-m@bjorling.me> X-Mailer: git-send-email 2.1.4 In-Reply-To: <1455886619-3007-1-git-send-email-m@bjorling.me> References: <1455886619-3007-1-git-send-email-m@bjorling.me> MIME-Version: 1.0 Sender: linux-block-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-block@vger.kernel.org X-Spam-Status: No, score=-6.8 required=5.0 tests=BAYES_00,DKIM_SIGNED, RCVD_IN_DNSWL_HI,RP_MATCHES_RCVD,T_DKIM_INVALID,UNPARSEABLE_RELAY autolearn=ham version=3.3.1 X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on mail.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP From: Alan Instead of checking a constant 0 actually check the space available. Even better remember to allow for the header and also check the right amount of space is needed. Signed-off-by: Alan Cox Signed-off-by: Matias Bjørling --- drivers/lightnvm/core.c | 11 +++++------ 1 file changed, 5 insertions(+), 6 deletions(-) diff --git a/drivers/lightnvm/core.c b/drivers/lightnvm/core.c index c3d4b54..b53632d 100644 --- a/drivers/lightnvm/core.c +++ b/drivers/lightnvm/core.c @@ -868,20 +868,19 @@ static int nvm_configure_by_str_event(const char *val, static int nvm_configure_get(char *buf, const struct kernel_param *kp) { - int sz = 0; - char *buf_start = buf; + int sz; struct nvm_dev *dev; - buf += sprintf(buf, "available devices:\n"); + sz = sprintf(buf, "available devices:\n"); down_write(&nvm_lock); list_for_each_entry(dev, &nvm_devices, devices) { - if (sz > 4095 - DISK_NAME_LEN) + if (sz > 4095 - DISK_NAME_LEN - 2) break; - buf += sprintf(buf, " %32s\n", dev->name); + sz += sprintf(buf + sz, " %32s\n", dev->name); } up_write(&nvm_lock); - return buf - buf_start - 1; + return sz; } static const struct kernel_param_ops nvm_configure_by_str_event_param_ops = {