Received: by 2002:a05:6a10:2785:0:0:0:0 with SMTP id ia5csp2970764pxb; Tue, 12 Jan 2021 03:12:54 -0800 (PST) X-Google-Smtp-Source: ABdhPJxySaQOtXQwZRrbkZauSIiXw0hIUXv7Vi1VwsmpHNseSrLA2pw8WVwhq9QGV1U6+vJBpWtt X-Received: by 2002:a50:8b02:: with SMTP id l2mr2889691edl.322.1610449973915; Tue, 12 Jan 2021 03:12:53 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1610449973; cv=none; d=google.com; s=arc-20160816; b=I352Lmy6tScbgIwZeB66WIssnKd0SBztiKa23dGmOCFBy+G/oNeqFeMG7+eRsPS0X5 LNPdt3ioGq87Dal5wkBoHLTyCiotyTy/VqkuOhFsz1ibngoSwBGgU1MuCi2F9+NSJ3sI gHGY4JaQjLJSF9P4DmXfCo1Hij3JJOq8yAOXQ5PmcAtekxdFuKYcanuqikRb3uQfxTNk GppHr3H1QhN5t0TyyKRlVAOyvgB6uHAt11Gdp+nxLRuBZ8If089gaa5dkWbn2LdRx5Sl DAahiBMoPdzDN6w4fEbDXMTzDDZKcVqXDQXZLpcYUJcPoO+Cj9zJqXKZKTfKOsLVeVk1 dfeg== 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 :message-id:date:subject:cc:to:from; bh=dvxOO3p7hVNUVYnzC4jLdTZ6BTIzJNO3CFmU3Ok2T5E=; b=EUuCY2Qdl7FI+Ah69wVLuGMmc2Ep/TLF300P6tuNioAY9oLIiHsPd97GMyWuMReCie Gwpg0q9bxp+CAxcVupt4Z5whTVZ1XB0tMVHvrfbW+T2RFHaE8XtXBVm2cD5NjiD8HZ2a mtg9YgFr9fxr9uHtrATyOCTX2wtNxHJ3Vg73x+CieKp2cSg88KDaLpE5gzdpq+ok8qqD mSMbe7zOYgoGhh4h76MpIrZ078MMrECRKErpmMpjMULcTzRS3xz90evdRSjL0q45mKi5 AvvhPTwJHepFIX+P6p8pmUyKy/3nNphLWh7w3BXv6YkSNm6cuBrNkjfFXZCSLbkc8+Fu BcFg== ARC-Authentication-Results: i=1; mx.google.com; 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 Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id k10si1197460eds.206.2021.01.12.03.12.30; Tue, 12 Jan 2021 03:12:53 -0800 (PST) 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; 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 Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1727368AbhALDcw (ORCPT + 99 others); Mon, 11 Jan 2021 22:32:52 -0500 Received: from szxga05-in.huawei.com ([45.249.212.191]:11093 "EHLO szxga05-in.huawei.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726992AbhALDcw (ORCPT ); Mon, 11 Jan 2021 22:32:52 -0500 Received: from DGGEMS405-HUB.china.huawei.com (unknown [172.30.72.59]) by szxga05-in.huawei.com (SkyGuard) with ESMTP id 4DFGLh4HYdzMJ0q; Tue, 12 Jan 2021 11:30:52 +0800 (CST) Received: from use12-sp2.huawei.com (10.67.189.174) by DGGEMS405-HUB.china.huawei.com (10.3.19.205) with Microsoft SMTP Server id 14.3.498.0; Tue, 12 Jan 2021 11:31:58 +0800 From: Xiaoming Ni To: , , , , , , , , , CC: , Subject: [PATCH v3] proc_sysctl: fix oops caused by incorrect command parameters. Date: Tue, 12 Jan 2021 11:31:55 +0800 Message-ID: <20210112033155.91502-1-nixiaoming@huawei.com> X-Mailer: git-send-email 2.27.0 MIME-Version: 1.0 Content-Transfer-Encoding: 7BIT Content-Type: text/plain; charset=US-ASCII X-Originating-IP: [10.67.189.174] X-CFilter-Loop: Reflected Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org The process_sysctl_arg() does not check whether val is empty before invoking strlen(val). If the command line parameter () is incorrectly configured and val is empty, oops is triggered. For example: "hung_task_panic=1" is incorrectly written as "hung_task_panic", oops is triggered. The call stack is as follows: Kernel command line: .... hung_task_panic ...... Call trace: __pi_strlen+0x10/0x98 parse_args+0x278/0x344 do_sysctl_args+0x8c/0xfc kernel_init+0x5c/0xf4 ret_from_fork+0x10/0x30 To fix it, check whether "val" is empty when "phram" is a sysctl field. Error codes are returned in the failure branch, and error logs are generated by parse_args(). Fixes: 3db978d480e2843 ("kernel/sysctl: support setting sysctl parameters from kernel command line") Signed-off-by: Xiaoming Ni --------- v3: Return -EINVAL, When phram is the sysctl field and val is empty. v2: https://lore.kernel.org/lkml/20210108023339.55917-1-nixiaoming@huawei.com/ Added log output of the failure branch based on the review comments of Kees Cook. v1: https://lore.kernel.org/lkml/20201224074256.117413-1-nixiaoming@huawei.com/ --------- --- fs/proc/proc_sysctl.c | 3 +++ 1 file changed, 3 insertions(+) diff --git a/fs/proc/proc_sysctl.c b/fs/proc/proc_sysctl.c index 317899222d7f..d493a50058a5 100644 --- a/fs/proc/proc_sysctl.c +++ b/fs/proc/proc_sysctl.c @@ -1770,6 +1770,9 @@ static int process_sysctl_arg(char *param, char *val, return 0; } + if (!val) + return -EINVAL; + /* * To set sysctl options, we use a temporary mount of proc, look up the * respective sys/ file and write to it. To avoid mounting it when no -- 2.27.0