Received: by 2002:a25:ad19:0:0:0:0:0 with SMTP id y25csp9052112ybi; Tue, 23 Jul 2019 20:50:59 -0700 (PDT) X-Google-Smtp-Source: APXvYqwx8BoHvnuIs80to25I0m9qnZ5S70L9jNXw+4G3vFRcnxhjudw+VMtf+AnK3xa4S6TlQvCc X-Received: by 2002:a62:e815:: with SMTP id c21mr9465596pfi.244.1563940259511; Tue, 23 Jul 2019 20:50:59 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1563940259; cv=none; d=google.com; s=arc-20160816; b=sr9ie6nRbxZelNes2hVaySXfsMZBUmNFOMF6pgk8JuILZWheuswrYYi6nXdKpwapfH oo/sup64r3fwO33+SSZLU/Q+a1KkyHkoO4YAr5PWcOseNX1k13M83pMVNEKg95ov54Jg 0Gg+dxBg3yNjxM52U0+WnNdhdlffjDBskcQbYAk0QO2xLsTUYKzY65fXpi1RclD89xKF svQHAF2pOOY2Is6q+77t+l7q1La0bvLwBqxXV8p24yFA6iAGjcR3Rr/dV74fidedI1zB qNlIYELLL0JjSKjluSmINsTK1h/ugbF0Frp70n0r6R9K21k3lmMGPrSU2FbX/mLEvE8H pLGw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:message-id:date:subject:cc:to:from :dkim-signature; bh=opj8lnCtN7uVcvkOiHNBMfsILzIZd7HuE+IB/qnbPFs=; b=jG6jROp6TSSfJGmM05WAqyWFu5YRYhYYwa1wE8GixWY2ZEpEfTYUlQRAkNwJ9zPQeQ odZAoevWYGU2MNIbgLOFxRQZFuaw+g+8XG74UnzcSjUrHpHxIBGaVhPEEV8qmgaIgNTT A/rYygVMgZxW4sEg0n3959uuyWjViog0owG32sT1ot9k1dRCq3qOvpebkLkZscDOOtPJ VQmlu8aAot0r3gd/hLqylj2jP0Rb2X1lPj+/zN7BFrEJq8E3PYN07WiimQdd1ioGsog6 iMGCF6+6vySYpEA8PB16DB2Sijxp56npNS7QRavBYu166Wj3fAqDcmDQKwq7KXRmiQAu rhxQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@gmail.com header.s=20161025 header.b=ltVI7vA+; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 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. [209.132.180.67]) by mx.google.com with ESMTP id y2si14224858pgh.524.2019.07.23.20.50.45; Tue, 23 Jul 2019 20:50:59 -0700 (PDT) Received-SPF: pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; dkim=pass header.i=@gmail.com header.s=20161025 header.b=ltVI7vA+; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 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 S1726589AbfGXDth (ORCPT + 99 others); Tue, 23 Jul 2019 23:49:37 -0400 Received: from mail-pg1-f194.google.com ([209.85.215.194]:38962 "EHLO mail-pg1-f194.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726400AbfGXDtg (ORCPT ); Tue, 23 Jul 2019 23:49:36 -0400 Received: by mail-pg1-f194.google.com with SMTP id u17so20462993pgi.6; Tue, 23 Jul 2019 20:49:36 -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; bh=opj8lnCtN7uVcvkOiHNBMfsILzIZd7HuE+IB/qnbPFs=; b=ltVI7vA+iq01wgiVxnieomCY9v/Tub804FD/gn9yiUjeQMRw2XKJofb5kolEda7nrV v3aQUuQuzvKVF3jveZuBXMoNL+KrzVgCeDLCc8nV9CpqFCUMe6jmzNjNLGf0Khh2pywL sUBhtVnBipvGnWDKC5Yj0crLE61C0zJiSYLjdQ0NaUHBjpCZjuhqnxFDAtLHM91JULXM wQpQxztA9L2D5PGuXsf18W+CJ1pmRMx7lFizLIgDBdmO1w0lUJww65iQgnxFp0cgoJOk K9/XZXQLUrUg/4/AEXqlc24YDF/UFQoFD7z6oxdRGgSqnLksMjaeBMoS6Qzvb3Fr0yiW n/Hw== 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; bh=opj8lnCtN7uVcvkOiHNBMfsILzIZd7HuE+IB/qnbPFs=; b=LgedTwpbgCJMGnuJAT/6zYcOQzy7dPGTn9zyYxYIQ8pdGqVZRdOEoAB4OPU7MvKkYb +obUgCQu7fIysX6YqX0gGA24XleiD/AkgtNJDSDDkKBRZ8FilRVx5S/iRbkRr59so+y9 HvTrd9J+WoEmVzgeSMDL/Tk5esjMzt4+IPo9r9yaPBGJl5HBYy6AfwVI3fIBI4fUm5go 5/JAGcXfovSRxFEuRFXRHxqhGrYGcQzHizZl2qT23PQLGmL9M9SqJmOaq5M6qFBGmJAw Q0rteVTpoXvk7XcmYmkyRnpLSSR4qieEvRui2yqv5JmTOm3wgTsEBNraUoOJqTk2HhpZ 8xAg== X-Gm-Message-State: APjAAAUDPTYmZ/qcecfCRn5OBiqzkD1tC6P499Fv2JqX23LsZM14xiWN wwlm5u5DG5iWTiDdCGfJWFg= X-Received: by 2002:a62:cdc8:: with SMTP id o191mr9130518pfg.74.1563940176347; Tue, 23 Jul 2019 20:49:36 -0700 (PDT) Received: from oslab.tsinghua.edu.cn ([2402:f000:4:72:808::3ca]) by smtp.gmail.com with ESMTPSA id t11sm51359610pgb.33.2019.07.23.20.49.34 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Tue, 23 Jul 2019 20:49:35 -0700 (PDT) From: Jia-Ju Bai To: philipp.reisner@linbit.com, lars.ellenberg@linbit.com, axboe@kernel.dk Cc: drbd-dev@lists.linbit.com, linux-block@vger.kernel.org, linux-kernel@vger.kernel.org, Jia-Ju Bai Subject: [PATCH 2/2] block: drbd: Fix a possible null-pointer dereference in is_valid_state() Date: Wed, 24 Jul 2019 11:49:26 +0800 Message-Id: <20190724034926.28755-1-baijiaju1990@gmail.com> X-Mailer: git-send-email 2.17.0 Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org In is_valid_state(), there is an if statement on line 839 to check whether nc is NULL: if (nc) When nc is NULL, it is used on line 880: (nc->verify_alg[0] == 0) Thus, a possible null-pointer dereference may occur. To fix this bug, nc is also checked on line 880. This bug is found by a static analysis tool STCheck written by us. Signed-off-by: Jia-Ju Bai --- drivers/block/drbd/drbd_state.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/drivers/block/drbd/drbd_state.c b/drivers/block/drbd/drbd_state.c index eeaa3b49b264..3cf477e9cf6a 100644 --- a/drivers/block/drbd/drbd_state.c +++ b/drivers/block/drbd/drbd_state.c @@ -877,7 +877,7 @@ is_valid_state(struct drbd_device *device, union drbd_state ns) rv = SS_CONNECTED_OUTDATES; else if ((ns.conn == C_VERIFY_S || ns.conn == C_VERIFY_T) && - (nc->verify_alg[0] == 0)) + (nc && nc->verify_alg[0] == 0)) rv = SS_NO_VERIFY_ALG; else if ((ns.conn == C_VERIFY_S || ns.conn == C_VERIFY_T) && -- 2.17.0