From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Google-Smtp-Source: AH8x224tge9MRJHte4KAdG6Hu6kLDGhtci3Si9n8NAWMN5pw6TG+9yt8OkE58hNxWFGAgFvHLqQ+ ARC-Seal: i=1; a=rsa-sha256; t=1517256276; cv=none; d=google.com; s=arc-20160816; b=C5Hx8XAZPQzlmZAgOB24u8XyOUylaXToP0uOLN6QgdAAhnQJotAf2whadAv684Uozr gLoeBmPkYpfRvr576F/Sf1zb5BDJY6orqvWcdperHyF9SPePpvbjNSrodqDhq3WQxn1p 4084L4Ko9tWQLMEWtlmxCnVnY9bHdTX9E6B1Z30HJnohCGWnZthKnzPC0HdrygFtR370 tqMgLUEOtKlFIVw+DORZyV6/7MC7Xt+qumzUsmE9rqWMvLufsTyYiQSFbx7eHw3WGYWv R5vRpNzzzHiODuKW/Nini1GmQMDzS9I3sgS9gdqwLUwsbZQL8ceg6MV+UNfONIxJx9dm 74+A== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=mime-version:user-agent:references:in-reply-to:message-id:date :subject:cc:to:from:arc-authentication-results; bh=TBbpY5Sc8thZRuUM2Ruc1srF9WUUHLESVfMcneuBWKM=; b=yjpsJ1tSo6PgRr726jzO1VVhkBHQOX1wlU96ZJurzsOA9iAy9zotiur5P0ONTUwWzM OetLmvv+so0SYwpCypUQjB7sV22uVxOpVmyxWirwEU86b+ixCsvDYRcMqXw8h+/MGchw PVrE82POXbz6rsYcqpMGgTL9eU/O+l4ywbzGX0lEOTmxys5VdxRf0n/T+2JePrbnen+r Ff/ewc/TworfgyOotDbepMW2stYNiON+th7/Rmik3DpGcEBw/NMV57fcF0IqSURuKV56 dGkbPDbyGdR5gSaXpwO5dtoWA6MLKzJi+PxkONgtZRpay300ARPTyHEuJkUHGklKA22f hzOA== ARC-Authentication-Results: i=1; mx.google.com; spf=softfail (google.com: domain of transitioning gregkh@linuxfoundation.org does not designate 90.92.71.90 as permitted sender) smtp.mailfrom=gregkh@linuxfoundation.org Authentication-Results: mx.google.com; spf=softfail (google.com: domain of transitioning gregkh@linuxfoundation.org does not designate 90.92.71.90 as permitted sender) smtp.mailfrom=gregkh@linuxfoundation.org From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , stable@vger.kernel.org, Jiri Slaby , Davidlohr Bueso , Manfred Spraul , Andrew Morton , Linus Torvalds Subject: [PATCH 4.4 25/74] ipc: msg, make msgrcv work with LONG_MIN Date: Mon, 29 Jan 2018 13:56:30 +0100 Message-Id: <20180129123848.758999307@linuxfoundation.org> X-Mailer: git-send-email 2.16.1 In-Reply-To: <20180129123847.507563674@linuxfoundation.org> References: <20180129123847.507563674@linuxfoundation.org> User-Agent: quilt/0.65 MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 X-getmail-retrieved-from-mailbox: INBOX X-GMAIL-LABELS: =?utf-8?b?IlxcU2VudCI=?= X-GMAIL-THRID: =?utf-8?q?1590958517461058476?= X-GMAIL-MSGID: =?utf-8?q?1590958517461058476?= X-Mailing-List: linux-kernel@vger.kernel.org List-ID: 4.4-stable review patch. If anyone has any objections, please let me know. ------------------ From: Jiri Slaby commit 999898355e08ae3b92dfd0a08db706e0c6703d30 upstream. When LONG_MIN is passed to msgrcv, one would expect to recieve any message. But convert_mode does *msgtyp = -*msgtyp and -LONG_MIN is undefined. In particular, with my gcc -LONG_MIN produces -LONG_MIN again. So handle this case properly by assigning LONG_MAX to *msgtyp if LONG_MIN was specified as msgtyp to msgrcv. This code: long msg[] = { 100, 200 }; int m = msgget(IPC_PRIVATE, IPC_CREAT | 0644); msgsnd(m, &msg, sizeof(msg), 0); msgrcv(m, &msg, sizeof(msg), LONG_MIN, 0); produces currently nothing: msgget(IPC_PRIVATE, IPC_CREAT|0644) = 65538 msgsnd(65538, {100, "\310\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0"}, 16, 0) = 0 msgrcv(65538, ... Except a UBSAN warning: UBSAN: Undefined behaviour in ipc/msg.c:745:13 negation of -9223372036854775808 cannot be represented in type 'long int': With the patch, I see what I expect: msgget(IPC_PRIVATE, IPC_CREAT|0644) = 0 msgsnd(0, {100, "\310\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0"}, 16, 0) = 0 msgrcv(0, {100, "\310\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0"}, 16, -9223372036854775808, 0) = 16 Link: http://lkml.kernel.org/r/20161024082633.10148-1-jslaby@suse.cz Signed-off-by: Jiri Slaby Cc: Davidlohr Bueso Cc: Manfred Spraul Signed-off-by: Andrew Morton Signed-off-by: Linus Torvalds Signed-off-by: Greg Kroah-Hartman --- ipc/msg.c | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) --- a/ipc/msg.c +++ b/ipc/msg.c @@ -742,7 +742,10 @@ static inline int convert_mode(long *msg if (*msgtyp == 0) return SEARCH_ANY; if (*msgtyp < 0) { - *msgtyp = -*msgtyp; + if (*msgtyp == LONG_MIN) /* -LONG_MIN is undefined */ + *msgtyp = LONG_MAX; + else + *msgtyp = -*msgtyp; return SEARCH_LESSEQUAL; } if (msgflg & MSG_EXCEPT)