Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit e71456ae authored by Steven Rostedt (Red Hat)'s avatar Steven Rostedt (Red Hat) Committed by Steven Rostedt
Browse files

netfilter: Remove checks of seq_printf() return values

The return value of seq_printf() is soon to be removed. Remove the
checks from seq_printf() in favor of seq_has_overflowed().

Link: http://lkml.kernel.org/r/20141104142236.GA10239@salvia


Acked-by: default avatarPablo Neira Ayuso <pablo@netfilter.org>
Cc: Patrick McHardy <kaber@trash.net>
Cc: Jozsef Kadlecsik <kadlec@blackhole.kfki.hu>
Cc: netfilter-devel@vger.kernel.org
Cc: coreteam@netfilter.org
Signed-off-by: default avatarSteven Rostedt <rostedt@goodmis.org>
parent 824f1fbe
Loading
Loading
Loading
Loading
+16 −20
Original line number Original line Diff line number Diff line
@@ -94,7 +94,7 @@ static void ct_seq_stop(struct seq_file *s, void *v)
}
}


#ifdef CONFIG_NF_CONNTRACK_SECMARK
#ifdef CONFIG_NF_CONNTRACK_SECMARK
static int ct_show_secctx(struct seq_file *s, const struct nf_conn *ct)
static void ct_show_secctx(struct seq_file *s, const struct nf_conn *ct)
{
{
	int ret;
	int ret;
	u32 len;
	u32 len;
@@ -102,17 +102,15 @@ static int ct_show_secctx(struct seq_file *s, const struct nf_conn *ct)


	ret = security_secid_to_secctx(ct->secmark, &secctx, &len);
	ret = security_secid_to_secctx(ct->secmark, &secctx, &len);
	if (ret)
	if (ret)
		return 0;
		return;


	ret = seq_printf(s, "secctx=%s ", secctx);
	seq_printf(s, "secctx=%s ", secctx);


	security_release_secctx(secctx, len);
	security_release_secctx(secctx, len);
	return ret;
}
}
#else
#else
static inline int ct_show_secctx(struct seq_file *s, const struct nf_conn *ct)
static inline void ct_show_secctx(struct seq_file *s, const struct nf_conn *ct)
{
{
	return 0;
}
}
#endif
#endif


@@ -141,11 +139,10 @@ static int ct_seq_show(struct seq_file *s, void *v)
	NF_CT_ASSERT(l4proto);
	NF_CT_ASSERT(l4proto);


	ret = -ENOSPC;
	ret = -ENOSPC;
	if (seq_printf(s, "%-8s %u %ld ",
	seq_printf(s, "%-8s %u %ld ",
		   l4proto->name, nf_ct_protonum(ct),
		   l4proto->name, nf_ct_protonum(ct),
		   timer_pending(&ct->timeout)
		   timer_pending(&ct->timeout)
		      ? (long)(ct->timeout.expires - jiffies)/HZ : 0) != 0)
		   ? (long)(ct->timeout.expires - jiffies)/HZ : 0);
		goto release;


	if (l4proto->print_conntrack)
	if (l4proto->print_conntrack)
		l4proto->print_conntrack(s, ct);
		l4proto->print_conntrack(s, ct);
@@ -163,8 +160,7 @@ static int ct_seq_show(struct seq_file *s, void *v)
		goto release;
		goto release;


	if (!(test_bit(IPS_SEEN_REPLY_BIT, &ct->status)))
	if (!(test_bit(IPS_SEEN_REPLY_BIT, &ct->status)))
		if (seq_printf(s, "[UNREPLIED] "))
		seq_printf(s, "[UNREPLIED] ");
			goto release;


	print_tuple(s, &ct->tuplehash[IP_CT_DIR_REPLY].tuple,
	print_tuple(s, &ct->tuplehash[IP_CT_DIR_REPLY].tuple,
		    l3proto, l4proto);
		    l3proto, l4proto);
@@ -176,19 +172,19 @@ static int ct_seq_show(struct seq_file *s, void *v)
		goto release;
		goto release;


	if (test_bit(IPS_ASSURED_BIT, &ct->status))
	if (test_bit(IPS_ASSURED_BIT, &ct->status))
		if (seq_printf(s, "[ASSURED] "))
		seq_printf(s, "[ASSURED] ");
			goto release;


#ifdef CONFIG_NF_CONNTRACK_MARK
#ifdef CONFIG_NF_CONNTRACK_MARK
	if (seq_printf(s, "mark=%u ", ct->mark))
	seq_printf(s, "mark=%u ", ct->mark);
		goto release;
#endif
#endif


	if (ct_show_secctx(s, ct))
	ct_show_secctx(s, ct);
		goto release;

	seq_printf(s, "use=%u\n", atomic_read(&ct->ct_general.use));


	if (seq_printf(s, "use=%u\n", atomic_read(&ct->ct_general.use)))
	if (seq_has_overflowed(s))
		goto release;
		goto release;

	ret = 0;
	ret = 0;
release:
release:
	nf_ct_put(ct);
	nf_ct_put(ct);
+29 −31
Original line number Original line Diff line number Diff line
@@ -120,7 +120,7 @@ static void ct_seq_stop(struct seq_file *s, void *v)
}
}


#ifdef CONFIG_NF_CONNTRACK_SECMARK
#ifdef CONFIG_NF_CONNTRACK_SECMARK
static int ct_show_secctx(struct seq_file *s, const struct nf_conn *ct)
static void ct_show_secctx(struct seq_file *s, const struct nf_conn *ct)
{
{
	int ret;
	int ret;
	u32 len;
	u32 len;
@@ -128,22 +128,20 @@ static int ct_show_secctx(struct seq_file *s, const struct nf_conn *ct)


	ret = security_secid_to_secctx(ct->secmark, &secctx, &len);
	ret = security_secid_to_secctx(ct->secmark, &secctx, &len);
	if (ret)
	if (ret)
		return 0;
		return;


	ret = seq_printf(s, "secctx=%s ", secctx);
	seq_printf(s, "secctx=%s ", secctx);


	security_release_secctx(secctx, len);
	security_release_secctx(secctx, len);
	return ret;
}
}
#else
#else
static inline int ct_show_secctx(struct seq_file *s, const struct nf_conn *ct)
static inline void ct_show_secctx(struct seq_file *s, const struct nf_conn *ct)
{
{
	return 0;
}
}
#endif
#endif


#ifdef CONFIG_NF_CONNTRACK_TIMESTAMP
#ifdef CONFIG_NF_CONNTRACK_TIMESTAMP
static int ct_show_delta_time(struct seq_file *s, const struct nf_conn *ct)
static void ct_show_delta_time(struct seq_file *s, const struct nf_conn *ct)
{
{
	struct ct_iter_state *st = s->private;
	struct ct_iter_state *st = s->private;
	struct nf_conn_tstamp *tstamp;
	struct nf_conn_tstamp *tstamp;
@@ -157,16 +155,15 @@ static int ct_show_delta_time(struct seq_file *s, const struct nf_conn *ct)
		else
		else
			delta_time = 0;
			delta_time = 0;


		return seq_printf(s, "delta-time=%llu ",
		seq_printf(s, "delta-time=%llu ",
			   (unsigned long long)delta_time);
			   (unsigned long long)delta_time);
	}
	}
	return 0;
	return;
}
}
#else
#else
static inline int
static inline void
ct_show_delta_time(struct seq_file *s, const struct nf_conn *ct)
ct_show_delta_time(struct seq_file *s, const struct nf_conn *ct)
{
{
	return 0;
}
}
#endif
#endif


@@ -193,12 +190,11 @@ static int ct_seq_show(struct seq_file *s, void *v)
	NF_CT_ASSERT(l4proto);
	NF_CT_ASSERT(l4proto);


	ret = -ENOSPC;
	ret = -ENOSPC;
	if (seq_printf(s, "%-8s %u %-8s %u %ld ",
	seq_printf(s, "%-8s %u %-8s %u %ld ",
		   l3proto->name, nf_ct_l3num(ct),
		   l3proto->name, nf_ct_l3num(ct),
		   l4proto->name, nf_ct_protonum(ct),
		   l4proto->name, nf_ct_protonum(ct),
		   timer_pending(&ct->timeout)
		   timer_pending(&ct->timeout)
		       ? (long)(ct->timeout.expires - jiffies)/HZ : 0) != 0)
		   ? (long)(ct->timeout.expires - jiffies)/HZ : 0);
		goto release;


	if (l4proto->print_conntrack)
	if (l4proto->print_conntrack)
		l4proto->print_conntrack(s, ct);
		l4proto->print_conntrack(s, ct);
@@ -206,12 +202,14 @@ static int ct_seq_show(struct seq_file *s, void *v)
	print_tuple(s, &ct->tuplehash[IP_CT_DIR_ORIGINAL].tuple,
	print_tuple(s, &ct->tuplehash[IP_CT_DIR_ORIGINAL].tuple,
		    l3proto, l4proto);
		    l3proto, l4proto);


	if (seq_has_overflowed(s))
		goto release;

	if (seq_print_acct(s, ct, IP_CT_DIR_ORIGINAL))
	if (seq_print_acct(s, ct, IP_CT_DIR_ORIGINAL))
		goto release;
		goto release;


	if (!(test_bit(IPS_SEEN_REPLY_BIT, &ct->status)))
	if (!(test_bit(IPS_SEEN_REPLY_BIT, &ct->status)))
		if (seq_printf(s, "[UNREPLIED] "))
		seq_printf(s, "[UNREPLIED] ");
			goto release;


	print_tuple(s, &ct->tuplehash[IP_CT_DIR_REPLY].tuple,
	print_tuple(s, &ct->tuplehash[IP_CT_DIR_REPLY].tuple,
		    l3proto, l4proto);
		    l3proto, l4proto);
@@ -220,26 +218,26 @@ static int ct_seq_show(struct seq_file *s, void *v)
		goto release;
		goto release;


	if (test_bit(IPS_ASSURED_BIT, &ct->status))
	if (test_bit(IPS_ASSURED_BIT, &ct->status))
		if (seq_printf(s, "[ASSURED] "))
		seq_printf(s, "[ASSURED] ");

	if (seq_has_overflowed(s))
		goto release;
		goto release;


#if defined(CONFIG_NF_CONNTRACK_MARK)
#if defined(CONFIG_NF_CONNTRACK_MARK)
	if (seq_printf(s, "mark=%u ", ct->mark))
	seq_printf(s, "mark=%u ", ct->mark);
		goto release;
#endif
#endif


	if (ct_show_secctx(s, ct))
	ct_show_secctx(s, ct);
		goto release;


#ifdef CONFIG_NF_CONNTRACK_ZONES
#ifdef CONFIG_NF_CONNTRACK_ZONES
	if (seq_printf(s, "zone=%u ", nf_ct_zone(ct)))
	seq_printf(s, "zone=%u ", nf_ct_zone(ct));
		goto release;
#endif
#endif


	if (ct_show_delta_time(s, ct))
	ct_show_delta_time(s, ct);
		goto release;

	seq_printf(s, "use=%u\n", atomic_read(&ct->ct_general.use));


	if (seq_printf(s, "use=%u\n", atomic_read(&ct->ct_general.use)))
	if (seq_has_overflowed(s))
		goto release;
		goto release;


	ret = 0;
	ret = 0;
+16 −14
Original line number Original line Diff line number Diff line
@@ -294,19 +294,19 @@ static int seq_show(struct seq_file *s, void *v)
{
{
	loff_t *pos = v;
	loff_t *pos = v;
	const struct nf_logger *logger;
	const struct nf_logger *logger;
	int i, ret;
	int i;
	struct net *net = seq_file_net(s);
	struct net *net = seq_file_net(s);


	logger = rcu_dereference_protected(net->nf.nf_loggers[*pos],
	logger = rcu_dereference_protected(net->nf.nf_loggers[*pos],
					   lockdep_is_held(&nf_log_mutex));
					   lockdep_is_held(&nf_log_mutex));


	if (!logger)
	if (!logger)
		ret = seq_printf(s, "%2lld NONE (", *pos);
		seq_printf(s, "%2lld NONE (", *pos);
	else
	else
		ret = seq_printf(s, "%2lld %s (", *pos, logger->name);
		seq_printf(s, "%2lld %s (", *pos, logger->name);


	if (ret < 0)
	if (seq_has_overflowed(s))
		return ret;
		return -ENOSPC;


	for (i = 0; i < NF_LOG_TYPE_MAX; i++) {
	for (i = 0; i < NF_LOG_TYPE_MAX; i++) {
		if (loggers[*pos][i] == NULL)
		if (loggers[*pos][i] == NULL)
@@ -314,17 +314,19 @@ static int seq_show(struct seq_file *s, void *v)


		logger = rcu_dereference_protected(loggers[*pos][i],
		logger = rcu_dereference_protected(loggers[*pos][i],
					   lockdep_is_held(&nf_log_mutex));
					   lockdep_is_held(&nf_log_mutex));
		ret = seq_printf(s, "%s", logger->name);
		seq_printf(s, "%s", logger->name);
		if (ret < 0)
		if (i == 0 && loggers[*pos][i + 1] != NULL)
			return ret;
			seq_printf(s, ",");
		if (i == 0 && loggers[*pos][i + 1] != NULL) {

			ret = seq_printf(s, ",");
		if (seq_has_overflowed(s))
			if (ret < 0)
			return -ENOSPC;
				return ret;
		}
	}
	}


	return seq_printf(s, ")\n");
	seq_printf(s, ")\n");

	if (seq_has_overflowed(s))
		return -ENOSPC;
	return 0;
}
}


static const struct seq_operations nflog_seq_ops = {
static const struct seq_operations nflog_seq_ops = {
+7 −6
Original line number Original line Diff line number Diff line
@@ -1242,12 +1242,13 @@ static int seq_show(struct seq_file *s, void *v)
{
{
	const struct nfqnl_instance *inst = v;
	const struct nfqnl_instance *inst = v;


	return seq_printf(s, "%5d %6d %5d %1d %5d %5d %5d %8d %2d\n",
	seq_printf(s, "%5d %6d %5d %1d %5d %5d %5d %8d %2d\n",
		   inst->queue_num,
		   inst->queue_num,
		   inst->peer_portid, inst->queue_total,
		   inst->peer_portid, inst->queue_total,
		   inst->copy_mode, inst->copy_range,
		   inst->copy_mode, inst->copy_range,
		   inst->queue_dropped, inst->queue_user_dropped,
		   inst->queue_dropped, inst->queue_user_dropped,
		   inst->id_sequence, 1);
		   inst->id_sequence, 1);
	return seq_has_overflowed(s);
}
}


static const struct seq_operations nfqnl_seq_ops = {
static const struct seq_operations nfqnl_seq_ops = {
+12 −7
Original line number Original line Diff line number Diff line
@@ -947,9 +947,10 @@ static int xt_table_seq_show(struct seq_file *seq, void *v)
{
{
	struct xt_table *table = list_entry(v, struct xt_table, list);
	struct xt_table *table = list_entry(v, struct xt_table, list);


	if (strlen(table->name))
	if (strlen(table->name)) {
		return seq_printf(seq, "%s\n", table->name);
		seq_printf(seq, "%s\n", table->name);
	else
		return seq_has_overflowed(seq);
	} else
		return 0;
		return 0;
}
}


@@ -1086,8 +1087,10 @@ static int xt_match_seq_show(struct seq_file *seq, void *v)
		if (trav->curr == trav->head)
		if (trav->curr == trav->head)
			return 0;
			return 0;
		match = list_entry(trav->curr, struct xt_match, list);
		match = list_entry(trav->curr, struct xt_match, list);
		return (*match->name == '\0') ? 0 :
		if (*match->name == '\0')
			return 0;
		seq_printf(seq, "%s\n", match->name);
		seq_printf(seq, "%s\n", match->name);
		return seq_has_overflowed(seq);
	}
	}
	return 0;
	return 0;
}
}
@@ -1139,8 +1142,10 @@ static int xt_target_seq_show(struct seq_file *seq, void *v)
		if (trav->curr == trav->head)
		if (trav->curr == trav->head)
			return 0;
			return 0;
		target = list_entry(trav->curr, struct xt_target, list);
		target = list_entry(trav->curr, struct xt_target, list);
		return (*target->name == '\0') ? 0 :
		if (*target->name == '\0')
			return 0;
		seq_printf(seq, "%s\n", target->name);
		seq_printf(seq, "%s\n", target->name);
		return seq_has_overflowed(seq);
	}
	}
	return 0;
	return 0;
}
}
Loading